package wtf.beatrice.limbomanager.objects; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.scheduler.BukkitTask; import wtf.beatrice.limbomanager.Cache; import wtf.beatrice.limbomanager.LimboManager; import java.util.ArrayList; import java.util.List; @Deprecated // this works, but it's too slow. (fast-async)worldedit's api has a far better way of handling it. public class AreaCleanerRunnable implements Runnable { public BukkitTask task; Location min, max; List blocksList = new ArrayList<>(); Location current; int blocksPerRun = 384; String playerName, cleanUpID; public AreaCleanerRunnable(Location min, Location max, String playerName, String cleanUpID) { this.playerName = playerName; this.cleanUpID = cleanUpID; this.min = min; this.max = max; current = new Location(min.getWorld(), min.getBlockX(), min.getBlockY(), min.getBlockZ()); LimboManager.getInstance().getLogger().info(min.getBlockX() + " " + min.getBlockY() + " " + min.getBlockZ()); LimboManager.getInstance().getLogger().info(max.getBlockX() + " " + max.getBlockY() + " " + max.getBlockZ()); } @Override public void run() { boolean cancelled = false; for(int i = 0; i < blocksPerRun; i++) { if(cancelled) break; Bukkit.getScheduler().runTask(LimboManager.getInstance(), () -> { current.getBlock().setType(Material.AIR); if(current.getBlockY() < max.getBlockY()) { current.setY(current.getBlockY() + 1 ); } else { current.setY(min.getBlockY()); if (current.getBlockX() < max.getBlockX()) { current.setX(current.getBlockX() + 1); } else { current.setX(min.getBlockX()); if (current.getBlockZ() < max.getBlockZ()) { current.setZ(current.getBlockZ() + 1); LimboManager.getInstance().getLogger().info("c: " + current.getBlockX() + " " + current.getBlockY() + " " + current.getBlockZ()); } else { // we finished, free the location and cancel the task. Cache.playerIslands.remove(cleanUpID); LimboManager.getInstance().getLogger().info("finished cleaning area for " + playerName); task.cancel(); return; } } } }); } } }