diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index 8da4241d0..7ce171e06 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -6,7 +6,7 @@ com.intellectualcrafters PlotSquared - 2.3.3 + 2.3.4 PlotSquared jar diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java index 561d22729..de5795a73 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java @@ -48,7 +48,6 @@ public class Schematic extends SubCommand { public Schematic() { super("schematic", "plots.schematic", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false); - // TODO command to fetch schematic from worldedit directory } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 7c75e32f9..afe65a1d0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -281,7 +281,7 @@ public enum C { /* * Clearing */ - CLEARING_PLOT("&cClearing plot."), + CLEARING_PLOT("&cClearing plot async."), CLEARING_DONE("&6Done, took &a%time%&6 ms!"), CLEARING_DONE_PACKETS("&6(&a%time% &6ms for packets)"), /* diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotManager.java index 6d6769a61..613004b99 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/DefaultPlotManager.java @@ -25,11 +25,13 @@ import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.Block; +import org.bukkit.plugin.Plugin; import java.util.ArrayList; @@ -222,19 +224,8 @@ public class DefaultPlotManager extends PlotManager { return new Location(Bukkit.getWorld(plotworld.worldname), x, 256, z); } - /** - * Clearing the plot needs to only consider removing the blocks - This - * implementation has used the SetCuboid function, as it is fast, and uses - * NMS code - It also makes use of the fact that deleting chunks is a lot - * faster than block updates This code is very messy, but you don't need to - * do something quite as complex unless you happen to have 512x512 sized - * plots - */ - @Override - public boolean clearPlot(final World world, final Plot plot) { - - // TODO LOAD CHUNKS TO CLEAR IT PROPERLY - + public void clearPlotAsync(final World world, final Plot plot) { + PlotHelper.runners.put(plot, 1); final DefaultPlotWorld dpw = ((DefaultPlotWorld) PlotMain.getWorldSettings(world)); final Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1); @@ -257,118 +248,268 @@ public class DefaultPlotManager extends PlotManager { if ((block.getTypeId() != wall.id) || (block.getData() != wall.data)) { setWall(world, dpw, plot.id, wall); } + int count = 10000; + + int s_x = pos1.getBlockX(); + int s_y = 0; + int s_z = pos1.getBlockZ(); + + int e_x = pos2.getBlockX(); + int e_y = world.getMaxHeight(); + int e_z = pos2.getBlockZ(); + + Plugin plugin = (Plugin) PlotMain.getMain(); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + // TODO Auto-generated method stub + } + }, 1L); + + PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT, pos2.getBlockZ() + 1), filling); + PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getBlockZ() + 1), plotfloor); + + } + + /** + * Clearing the plot needs to only consider removing the blocks - This + * implementation has used the SetCuboid function, as it is fast, and uses + * NMS code - It also makes use of the fact that deleting chunks is a lot + * faster than block updates This code is very messy, but you don't need to + * do something quite as complex unless you happen to have 512x512 sized + * plots + */ + @Override + public boolean clearPlot(final World world, final Plot plot) { + PlotHelper.runners.put(plot, 1); + final Plugin plugin = (Plugin) PlotMain.getMain(); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.runners.remove(plot); + } }, 90L); - if ((pos2.getBlockX() - pos1.getBlockX()) < 48) { - PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT, pos2.getBlockZ() + 1), filling); - PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getBlockZ() + 1), plotfloor); - return true; + final DefaultPlotWorld dpw = ((DefaultPlotWorld) PlotMain.getWorldSettings(world)); + + final Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1); + final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id); + + final PlotBlock[] plotfloor = dpw.TOP_BLOCK; + final PlotBlock[] filling = dpw.MAIN_BLOCK; + + // PlotBlock wall = dpw.WALL_BLOCK; + final PlotBlock wall = dpw.WALL_BLOCK; + + final PlotBlock wall_filling = dpw.WALL_FILLING; + + Block block = world.getBlockAt(new Location(world, pos1.getBlockX() - 1, 1, pos1.getBlockZ())); + if ((block.getTypeId() != wall_filling.id) || (block.getData() != wall_filling.data)) { + setWallFilling(world, dpw, plot.id, wall_filling); } - final int startX = (pos1.getBlockX() / 16) * 16; - final int startZ = (pos1.getBlockZ() / 16) * 16; - final int chunkX = 16 + pos2.getBlockX(); - final int chunkZ = 16 + pos2.getBlockZ(); - final Location l1 = PlotHelper.getPlotBottomLoc(world, plot.id); - final Location l2 = PlotHelper.getPlotTopLoc(world, plot.id); - final int plotMinX = l1.getBlockX() + 1; - final int plotMinZ = l1.getBlockZ() + 1; - final int plotMaxX = l2.getBlockX(); - final int plotMaxZ = l2.getBlockZ(); - Location min = null; - Location max = null; - for (int i = startX; i < chunkX; i += 16) { - for (int j = startZ; j < chunkZ; j += 16) { - final Plot plot1 = PlotHelper.getCurrentPlot(new Location(world, i, 0, j)); - if ((plot1 != null) && (plot1.getId() != plot.getId())) { - break; + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + + Block block = world.getBlockAt(new Location(world, pos1.getBlockX() - 1, dpw.WALL_HEIGHT + 1, pos1.getBlockZ())); + if ((block.getTypeId() != wall.id) || (block.getData() != wall.data)) { + setWall(world, dpw, plot.id, wall); + } + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + if ((pos2.getBlockX() - pos1.getBlockX()) < 48) { + PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT, pos2.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getBlockZ() + 1), plotfloor); + } }, 5L); + } }, 5L); + } }, 5L); + return; } - final Plot plot2 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j)); - if ((plot2 != null) && (plot2.getId() != plot.getId())) { - break; - } - final Plot plot3 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j + 15)); - if ((plot3 != null) && (plot3.getId() != plot.getId())) { - break; - } - final Plot plot4 = PlotHelper.getCurrentPlot(new Location(world, i, 0, j + 15)); - if ((plot4 != null) && (plot4.getId() != plot.getId())) { - break; - } - final Plot plot5 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j + 15)); - if ((plot5 != null) && (plot5.getId() != plot.getId())) { - break; + + final int startX = (pos1.getBlockX() / 16) * 16; + final int startZ = (pos1.getBlockZ() / 16) * 16; + final int chunkX = 16 + pos2.getBlockX(); + final int chunkZ = 16 + pos2.getBlockZ(); + final Location l1 = PlotHelper.getPlotBottomLoc(world, plot.id); + final Location l2 = PlotHelper.getPlotTopLoc(world, plot.id); + final int plotMinX = l1.getBlockX() + 1; + final int plotMinZ = l1.getBlockZ() + 1; + final int plotMaxX = l2.getBlockX(); + final int plotMaxZ = l2.getBlockZ(); + Location mn = null; + Location mx = null; + for (int i = startX; i < chunkX; i += 16) { + for (int j = startZ; j < chunkZ; j += 16) { + final Plot plot1 = PlotHelper.getCurrentPlot(new Location(world, i, 0, j)); + if ((plot1 != null) && (!plot1.getId().equals(plot.getId()))) { + break; + } + final Plot plot2 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j)); + if ((plot2 != null) && (!plot2.getId().equals(plot.getId()))) { + break; + } + final Plot plot3 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j + 15)); + if ((plot3 != null) && (!plot3.getId().equals(plot.getId()))) { + break; + } + final Plot plot4 = PlotHelper.getCurrentPlot(new Location(world, i, 0, j + 15)); + if ((plot4 != null) && (!plot4.getId().equals(plot.getId()))) { + break; + } + final Plot plot5 = PlotHelper.getCurrentPlot(new Location(world, i + 15, 0, j + 15)); + if ((plot5 != null) && (!plot5.getId().equals(plot.getId()))) { + break; + } + if (mn == null) { + mn = new Location(world, Math.max(i - 1, plotMinX), 0, Math.max(j - 1, plotMinZ)); + mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); + } else if ((mx.getBlockZ() < (j + 15)) || (mx.getBlockX() < (i + 15))) { + mx = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); + } + world.regenerateChunk(i / 16, j / 16); + } } + + final Location max = mx; + final Location min = mn; + if (min == null) { - min = new Location(world, Math.max(i - 1, plotMinX), 0, Math.max(j - 1, plotMinZ)); - max = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); - } else if ((max.getBlockZ() < (j + 15)) || (max.getBlockX() < (i + 15))) { - max = new Location(world, Math.min(i + 16, plotMaxX), 0, Math.min(j + 16, plotMaxZ)); + PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT, pos2.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getBlockZ() + 1), plotfloor); + } }, 5L); + } }, 5L); + } }, 5L); + return; + } else { + + if (min.getBlockX() < plotMinX) { + min.setX(plotMinX); + } + if (min.getBlockZ() < plotMinZ) { + min.setZ(plotMinZ); + } + if (max.getBlockX() > plotMaxX) { + max.setX(plotMaxX); + } + if (max.getBlockZ() > plotMaxZ) { + max.setZ(plotMaxZ); + } + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, plotMinZ), new Location(world, min.getBlockX() + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, plotMinZ), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, plotMinZ), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); + } }, 1L); + } }, 1L); + } }, 1L); + } }, 21L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, plotMinZ), new Location(world, max.getBlockX() + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), 1, plotMinZ), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT, min.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); + } }, 1L); + } }, 1L); + } }, 1L); + } }, 25L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, plotMinZ), new Location(world, plotMaxX + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, min.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); + } }, 1L); + } }, 1L); + } }, 1L); + } }, 29L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, min.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, max.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT, max.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, min.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloor); + } }, 1L); + } }, 1L); + } }, 1L); + } }, 33L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, max.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); + } }, 1L); + } }, 1L); + } }, 1L); + } }, 37L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, max.getBlockZ()), new Location(world, max.getBlockX() + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); + } }, 1L); + } }, 1L); + } }, 1L); + } }, 41L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, min.getBlockZ()), new Location(world, plotMaxX + 1, 1, max.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, min.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, max.getBlockZ() + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, min.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloor); + } }, 1L); + } }, 1L); + } }, 1L); + } }, 45L); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, max.getBlockZ()), new Location(world, plotMaxX + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, max.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); + } }, 1L); + } }, 1L); + } }, 1L); + } }, 49L); } - world.regenerateChunk(i / 16, j / 16); - } - } - - if (min == null) { - PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), 0, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, 1, pos2.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - PlotHelper.setSimpleCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT + 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, world.getMaxHeight() + 1, pos2.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), 1, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT, pos2.getBlockZ() + 1), filling); - PlotHelper.setCuboid(world, new Location(world, pos1.getBlockX(), dpw.PLOT_HEIGHT, pos1.getBlockZ()), new Location(world, pos2.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, pos2.getBlockZ() + 1), plotfloor); - } else { - - if (min.getBlockX() < plotMinX) { - min.setX(plotMinX); - } - if (min.getBlockZ() < plotMinZ) { - min.setZ(plotMinZ); - } - if (max.getBlockX() > plotMaxX) { - max.setX(plotMaxX); - } - if (max.getBlockZ() > plotMaxZ) { - max.setZ(plotMaxZ); - } - - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, plotMinZ), new Location(world, min.getBlockX() + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, plotMinZ), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), filling); - PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, plotMinZ), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); - - PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, plotMinZ), new Location(world, max.getBlockX() + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), 1, plotMinZ), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT, min.getBlockZ() + 1), filling); - PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); - - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, plotMinZ), new Location(world, plotMaxX + 1, 1, min.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, plotMinZ), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, min.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, min.getBlockZ() + 1), filling); - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, plotMinZ), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, min.getBlockZ() + 1), plotfloor); - - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, min.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, max.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, min.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT, max.getBlockZ() + 1), filling); - PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, min.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloor); - - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, 0, max.getBlockZ()), new Location(world, min.getBlockX() + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); - PlotHelper.setSimpleCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); - PlotHelper.setCuboid(world, new Location(world, plotMinX, 1, max.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); - PlotHelper.setCuboid(world, new Location(world, plotMinX, dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, min.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); - - PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), 0, max.getBlockZ()), new Location(world, max.getBlockX() + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); - PlotHelper.setSimpleCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); - PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), 1, max.getBlockZ()), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); - PlotHelper.setCuboid(world, new Location(world, min.getBlockX(), dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, max.getBlockX() + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); - - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, min.getBlockZ()), new Location(world, plotMaxX + 1, 1, max.getBlockZ() + 1), new PlotBlock((short) 7, (byte) 0)); - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, min.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, max.getBlockZ() + 1), new PlotBlock((short) 0, (byte) 0)); - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, min.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, max.getBlockZ() + 1), filling); - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, min.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, max.getBlockZ() + 1), plotfloor); - - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), 0, max.getBlockZ()), new Location(world, plotMaxX + 1, 1, plotMaxZ + 1), new PlotBlock((short) 7, (byte) 0)); - PlotHelper.setSimpleCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT + 1, max.getBlockZ()), new Location(world, plotMaxX + 1, world.getMaxHeight() + 1, plotMaxZ + 1), new PlotBlock((short) 0, (byte) 0)); - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), 1, max.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT, plotMaxZ + 1), filling); - PlotHelper.setCuboid(world, new Location(world, max.getBlockX(), dpw.PLOT_HEIGHT, max.getBlockZ()), new Location(world, plotMaxX + 1, dpw.PLOT_HEIGHT + 1, plotMaxZ + 1), plotfloor); - } + } }, 20L); + } }, 20L); return true; } @@ -482,15 +623,23 @@ public class DefaultPlotManager extends PlotManager { final int bottomZ = PlotHelper.getPlotBottomLoc(world, plot.id).getBlockZ() - 1; final int topZ = PlotHelper.getPlotTopLoc(world, plot.id).getBlockZ() + 1; + Block block = world.getBlockAt(PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 1, 1)); + Biome current = block.getBiome(); + if (biome.equals(current)) { + return false; + } + for (int x = bottomX; x <= topX; x++) { for (int z = bottomZ; z <= topZ; z++) { - world.getBlockAt(x, 0, z).setBiome(biome); + Block blk = world.getBlockAt(x, 0, z); + Biome c = blk.getBiome(); + if (c.equals(biome)) { + x += 15; + continue; + } + blk.setBiome(biome); } } - - PlotMain.updatePlot(plot); - PlotHelper.refreshPlotChunks(world, plot); - return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java index 9134c9797..76a838d0c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java @@ -26,7 +26,9 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.listeners.PlotListener; import com.intellectualcrafters.plot.object.*; + import net.milkbowl.vault.economy.Economy; + import org.bukkit.*; import org.bukkit.block.Biome; import org.bukkit.block.Block; @@ -34,10 +36,13 @@ import org.bukkit.block.BlockState; import org.bukkit.block.Sign; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import java.io.File; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; import java.util.UUID; /** @@ -655,33 +660,27 @@ public class PlotHelper { } public static void clearAllEntities(final World world, final Plot plot, final boolean tile) { - final Location pos1 = getPlotBottomLoc(world, plot.id).add(1, 0, 1); - final Location pos2 = getPlotTopLoc(world, plot.id); - for (int i = (pos1.getBlockX() / 16) * 16; i < (16 + ((pos2.getBlockX() / 16) * 16)); i += 16) { - for (int j = (pos1.getBlockZ() / 16) * 16; j < (16 + ((pos2.getBlockZ() / 16) * 16)); j += 16) { - final Chunk chunk = world.getChunkAt(i, j); - for (final Entity entity : chunk.getEntities()) { - final PlotId id = PlayerFunctions.getPlot(entity.getLocation()); - if ((id != null) && id.equals(plot.id)) { - if (entity instanceof Player) { - Player player = (Player) entity; - PlotMain.teleportPlayer(player, entity.getLocation(), plot); - PlotListener.plotExit(player, plot); - } else { - entity.remove(); - } - } - } - if (tile) { - for (final BlockState entity : chunk.getTileEntities()) { - entity.setRawData((byte) 0); - } + + List entities = world.getEntities(); + for (Entity entity : entities) { + PlotId id = PlayerFunctions.getPlot(entity.getLocation()); + if (plot.id.equals(id)) { + if (entity instanceof Player) { + Player player = (Player) entity; + PlotMain.teleportPlayer(player, entity.getLocation(), plot); + PlotListener.plotExit(player, plot); + } else { + entity.remove(); } } } } public static void clear(final World world, final Plot plot) { + if (runners.containsKey(plot)) { + PlayerFunctions.sendMessage(null, C.WAIT_FOR_TIMER); + return; + } final PlotManager manager = PlotMain.getPlotManager(world); final Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1); @@ -692,12 +691,14 @@ public class PlotHelper { h = (prime * h) + pos1.getBlockZ(); state = h; - PlotHelper.setBiome(world, plot, Biome.FOREST); - manager.clearPlot(world, plot); if (canSetFast) { - refreshPlotChunks(world, plot); + final Plugin plugin = (Plugin) PlotMain.getMain(); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlotHelper.setBiome(world, plot, Biome.FOREST); + refreshPlotChunks(world, plot); + } }, 90L); } } @@ -721,18 +722,18 @@ public class PlotHelper { PlayerFunctions.sendMessage(requester, C.CLEARING_PLOT); - final long start = System.nanoTime(); + final long start = System.currentTimeMillis(); final World world; world = requester.getWorld(); - /* - * keep - */ clearAllEntities(world, plot, false); clear(world, plot); removeSign(world, plot); - PlayerFunctions.sendMessage(requester, C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.nanoTime() - start) / 1000000.0))); + final Plugin plugin = (Plugin) PlotMain.getMain(); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { + PlayerFunctions.sendMessage(requester, C.CLEARING_DONE.s().replaceAll("%time%", "" + ((System.currentTimeMillis() - start) / 1000.0))); + } }, 90L); } @@ -801,19 +802,29 @@ public class PlotHelper { } public static void setBiome(final World world, final Plot plot, final Biome b) { - final int bottomX = getPlotBottomLoc(world, plot.id).getBlockX() - 1; + final int bottomX = getPlotBottomLoc(world, plot.id).getBlockX(); final int topX = getPlotTopLoc(world, plot.id).getBlockX() + 1; - final int bottomZ = getPlotBottomLoc(world, plot.id).getBlockZ() - 1; + final int bottomZ = getPlotBottomLoc(world, plot.id).getBlockZ(); final int topZ = getPlotTopLoc(world, plot.id).getBlockZ() + 1; - + + Block block = world.getBlockAt(getPlotBottomLoc(world, plot.id).add(1, 1, 1)); + Biome biome = block.getBiome(); + + if (biome.equals(b)) { + return; + } + for (int x = bottomX; x <= topX; x++) { for (int z = bottomZ; z <= topZ; z++) { - world.getBlockAt(x, 0, z).setBiome(b); + Block blk = world.getBlockAt(x, 0, z); + Biome c = blk.getBiome(); + if (c.equals(b)) { + x += 15; + continue; + } + blk.setBiome(b); } } - - PlotMain.updatePlot(plot); - refreshPlotChunks(world, plot); } public static int getHeighestBlock(final World world, final int x, final int z) {