From 830e85f2df45efb1dda8f8ffbd024de3988962d7 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Mon, 18 May 2015 02:20:53 +1000 Subject: [PATCH] Component setting limit --- .../plot/commands/Set.java | 13 +- .../plot/generator/ClassicPlotManager.java | 121 ++++++------------ 2 files changed, 48 insertions(+), 86 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java index 3f1bb0b4a..de9b86ada 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -45,6 +45,7 @@ import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; /** @@ -58,7 +59,6 @@ public class Set extends SubCommand { super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS, true); } - @SuppressWarnings("deprecation") @Override public boolean execute(final PlotPlayer plr, final String... args) { final Location loc = plr.getLocation(); @@ -249,8 +249,19 @@ public class Set extends SubCommand { return false; } } + if (MainUtil.runners.containsKey(plot)) { + MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); + return false; + } + MainUtil.runners.put(plot, 1); manager.setComponent(plotworld, plot.id, component, blocks); MainUtil.sendMessage(plr, C.GENERATING_COMPONENT); + SetBlockQueue.addNotify(new Runnable() { + @Override + public void run() { + MainUtil.runners.remove(plot); + } + }); return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java index 95a2039ab..8a08566ad 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java @@ -10,6 +10,7 @@ import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.SetBlockQueue; /** * A plot manager with square plots which tesselate on a square grid with the following sections: ROAD, WALL, BORDER (wall), PLOT, FLOOR (plot) @@ -40,7 +41,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final Location pos2 = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1); pos1.setY(dpw.PLOT_HEIGHT); pos2.setY(dpw.PLOT_HEIGHT + 1); - MainUtil.setCuboid(plotworld.worldname, pos1, pos2, blocks); + MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks); return true; } @@ -53,55 +54,30 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1); int x, z; z = bottom.getZ(); - final int length1 = top.getX() - bottom.getX(); - final int length2 = top.getZ() - bottom.getZ(); - final int size = (length1 * 2 + length2 * 2) * (dpw.WALL_HEIGHT); - final int[] xl = new int[size]; - final int[] yl = new int[size]; - final int[] zl = new int[size]; - final PlotBlock[] bl = new PlotBlock[size]; - int i = 0; PseudoRandom random = new PseudoRandom(); for (x = bottom.getX(); x <= (top.getX() - 1); x++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { - xl[i] = x; - zl[i] = z; - yl[i] = y; - bl[i] = blocks[random.random(blocks.length)]; - i++; + SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); } } x = top.getX(); for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { - xl[i] = x; - zl[i] = z; - yl[i] = y; - bl[i] = blocks[random.random(blocks.length)]; - i++; + SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); } } z = top.getZ(); for (x = top.getX(); x >= (bottom.getX() + 1); x--) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { - xl[i] = x; - zl[i] = z; - yl[i] = y; - bl[i] = blocks[random.random(blocks.length)]; - i++; + SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); } } x = bottom.getX(); for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { - xl[i] = x; - zl[i] = z; - yl[i] = y; - bl[i] = blocks[random.random(blocks.length)]; - i++; + SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); } } - BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, bl); return true; } @@ -112,50 +88,25 @@ public abstract class ClassicPlotManager extends SquarePlotManager { } final Location bottom = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid); final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1); - final int length1 = top.getX() - bottom.getX(); - final int length2 = top.getZ() - bottom.getZ(); - final int size = length1 * 2 + length2 * 2; - final int[] xl = new int[size]; - final int[] yl = new int[size]; - final int[] zl = new int[size]; - final PlotBlock[] bl = new PlotBlock[size]; int x, z; z = bottom.getZ(); - int i = 0; PseudoRandom random = new PseudoRandom(); final int y = dpw.WALL_HEIGHT + 1; for (x = bottom.getX(); x <= (top.getX() - 1); x++) { - xl[i] = x; - zl[i] = z; - yl[i] = y; - bl[i] = blocks[random.random(blocks.length)]; - i++; + SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); } x = top.getX(); for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) { - xl[i] = x; - zl[i] = z; - yl[i] = y; - bl[i] = blocks[random.random(blocks.length)]; - i++; + SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); } z = top.getZ(); for (x = top.getX(); x >= (bottom.getX() + 1); x--) { - xl[i] = x; - zl[i] = z; - yl[i] = y; - bl[i] = blocks[random.random(blocks.length)]; - i++; + SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); } x = bottom.getX(); for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) { - xl[i] = x; - zl[i] = z; - yl[i] = y; - bl[i] = blocks[random.random(blocks.length)]; - i++; + SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]); } - BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, bl); return true; } @@ -171,13 +122,13 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final int ex = (sx + dpw.ROAD_WIDTH) - 1; final int sz = pos1.getZ() - 1; final int ez = pos2.getZ() + 2; - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1), new Location(plotworld.worldname, ex + 1, 257, ez), new PlotBlock((short) 0, (byte) 0)); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT, ez), new PlotBlock((short) 7, (byte) 0)); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, ez), dpw.WALL_FILLING); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 2, ez), dpw.WALL_BLOCK); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, ex, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.WALL_HEIGHT + 1, ez), dpw.WALL_FILLING); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.WALL_HEIGHT + 2, ez), dpw.WALL_BLOCK); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1), new Location(plotworld.worldname, ex + 1, 257, ez), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT, ez), new PlotBlock((short) 7, (byte) 0)); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, ez), dpw.WALL_FILLING); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 2, ez), dpw.WALL_BLOCK); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.WALL_HEIGHT + 1, ez), dpw.WALL_FILLING); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.WALL_HEIGHT + 2, ez), dpw.WALL_BLOCK); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK); return true; } @@ -190,13 +141,13 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final int ez = (sz + dpw.ROAD_WIDTH) - 1; final int sx = pos1.getX() - 1; final int ex = pos2.getX() + 2; - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex, 257, ez + 1), new PlotBlock((short) 0, (byte) 0)); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 0, sz), new Location(plotworld.worldname, ex, 1, ez + 1), new PlotBlock((short) 7, (byte) 0)); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), dpw.WALL_FILLING); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, sz), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 2, sz + 1), dpw.WALL_BLOCK); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, ez), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, ez + 1), dpw.WALL_FILLING); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, ez), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 2, ez + 1), dpw.WALL_BLOCK); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex, 257, ez + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 0, sz), new Location(plotworld.worldname, ex, 1, ez + 1), new PlotBlock((short) 7, (byte) 0)); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), dpw.WALL_FILLING); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, sz), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 2, sz + 1), dpw.WALL_BLOCK); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, ez), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, ez + 1), dpw.WALL_FILLING); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, ez), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 2, ez + 1), dpw.WALL_BLOCK); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK); return true; } @@ -208,9 +159,9 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final int ex = (sx + dpw.ROAD_WIDTH) - 1; final int sz = pos2.getZ() + 1; final int ez = (sz + dpw.ROAD_WIDTH) - 1; - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.ROAD_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex, 257, ez), new PlotBlock((short) 0, (byte) 0)); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 0, sz + 1), new Location(plotworld.worldname, ex, 1, ez), new PlotBlock((short) 7, (byte) 0)); - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.ROAD_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex, 257, ez), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 0, sz + 1), new Location(plotworld.worldname, ex, 1, ez), new PlotBlock((short) 7, (byte) 0)); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK); return true; } @@ -223,9 +174,9 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final int ex = (sx + dpw.ROAD_WIDTH) - 1; final int sz = pos1.getZ(); final int ez = pos2.getZ() + 1; - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0)); - MainUtil.setCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT, ez), dpw.MAIN_BLOCK); - MainUtil.setCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.PLOT_HEIGHT, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT + 1, ez), dpw.TOP_BLOCK); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT, ez), dpw.MAIN_BLOCK); + MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.PLOT_HEIGHT, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT + 1, ez), dpw.TOP_BLOCK); return true; } @@ -238,9 +189,9 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final int ez = (sz + dpw.ROAD_WIDTH) - 1; final int sx = pos1.getX(); final int ex = pos2.getX() + 1; - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0)); - MainUtil.setCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz), new Location(plotworld.worldname, ex, dpw.PLOT_HEIGHT, ez + 1), dpw.MAIN_BLOCK); - MainUtil.setCuboid(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.PLOT_HEIGHT, sz), new Location(plotworld.worldname, ex, dpw.PLOT_HEIGHT + 1, ez + 1), dpw.TOP_BLOCK); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz), new Location(plotworld.worldname, ex, dpw.PLOT_HEIGHT, ez + 1), dpw.MAIN_BLOCK); + MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.PLOT_HEIGHT, sz), new Location(plotworld.worldname, ex, dpw.PLOT_HEIGHT + 1, ez + 1), dpw.TOP_BLOCK); return true; } @@ -252,9 +203,9 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final int ex = (sx + dpw.ROAD_WIDTH) - 1; final int sz = loc.getZ() + 1; final int ez = (sz + dpw.ROAD_WIDTH) - 1; - MainUtil.setSimpleCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.ROAD_HEIGHT + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0)); - MainUtil.setCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz), new Location(plotworld.worldname, ex + 1, dpw.ROAD_HEIGHT, ez + 1), dpw.MAIN_BLOCK); - MainUtil.setCuboid(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.ROAD_HEIGHT, sz), new Location(plotworld.worldname, ex + 1, dpw.ROAD_HEIGHT + 1, ez + 1), dpw.TOP_BLOCK); + MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.ROAD_HEIGHT + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock((short) 0, (byte) 0)); + MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz), new Location(plotworld.worldname, ex + 1, dpw.ROAD_HEIGHT, ez + 1), dpw.MAIN_BLOCK); + MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.ROAD_HEIGHT, sz), new Location(plotworld.worldname, ex + 1, dpw.ROAD_HEIGHT + 1, ez + 1), dpw.TOP_BLOCK); return true; }