1.17.1 Set Blocks in Area dosen't work!

Discussion in 'Spigot Plugin Development' started by Maxrisko, Nov 23, 2021.

  1. It only outputs debug 1 and 2 when starting and then debug 4 endlessly when stopping.



    Code (Java):
    public boolean startGameCountdown = false;
        public static boolean endGame = false;
        public int gameCountdown = main.getInstance().getMainConfig().getStatGameCountdown();
        public static Set<Location> sandstone = new HashSet<();

    Code (Java):
    public static void setLight() {
            Bukkit.broadcastMessage("Debug1");
            int random = getRandomInt(7)+1;
            int random2 = getRandomInt(5)+1;
            if(main.gameState == GameStates.LIGHTGAME) {
                Bukkit.broadcastMessage("Debug2");
                Bukkit.getScheduler().scheduleSyncDelayedTask(main.getInstance(), () -> {
                    Bukkit.broadcastMessage("Debug3");
                    Bukkit.getScheduler().runTaskAsynchronously(main.getInstance(), () -> {
                        boolean initSandstone = sandstone.size() == 0;
                        for(int x = 18 ; x <= 124 ; x++) {
                            for(int z = -55; z <= 57; z++) {
                                Location loc = new Location(Bukkit.getWorld(main.getInstance().getMainConfig().getGameWorld()), x, 64, z);
                                if(loc.getBlock().getType() == Material.SANDSTONE && initSandstone) {
                                    sandstone.add(loc);
                                   
                                }
                                Bukkit.broadcastMessage("Debug4");
                                Bukkit.getScheduler().runTask(main.getInstance(), () -> {
                                    loc.getBlock().setType(Material.RED_CONCRETE_POWDER);
                                });
                            }
                        }
                    });
                    Bukkit.broadcastMessage("Debug5");
                    Bukkit.getScheduler().scheduleSyncDelayedTask(main.getInstance(), () -> {
                        Bukkit.broadcastMessage("Debug6");
                        Bukkit.getScheduler().runTaskAsynchronously(main.getInstance(), () -> {
                            for(int x = 18 ; x <= 124 ; x++) {
                                for(int z = -55; z <= 57; z++) {
                                    Location loc = new Location(Bukkit.getWorld(main.getInstance().getMainConfig().getGameWorld()), x, 64, z);
                                    Bukkit.broadcastMessage("Debug7");
                                    Bukkit.getScheduler().runTask(main.getInstance(), () -> {
                                        loc.getBlock().setType(sandstone.contains(loc) ? Material.SANDSTONE : Material.SAND);
                                    });                                                // WENN ? TRUE DANN (:) FALSE
                                }
                            }
                        });                                  
                        if(!endGame) {
                            setLight();
                        }
                    },20*random2);
                },20*random); //set red count
            }
        }
     
  2. Some error in console?
     
  3. Why are you switching between the main thread and async threads so often? Just run everything in a sync task, if anything you're just hurting performance by creating literally ten thousand+ tasks like that.
     
  4. This, plus it makes the code alot harder to read the way you're doing it.

    Plus im 90% sure you cant get a block's type async (which is probabbly your issue), like 99% of spigot isnt thread safe, if you really wanted to do this async you would have to use ChunkSnapshots