From 37febd40b7a03e2e28b8c767682898c97362518a Mon Sep 17 00:00:00 2001 From: boy0001 Date: Mon, 16 Feb 2015 01:31:24 +1100 Subject: [PATCH] more move stuff --- .../plot/commands/Move.java | 12 +++- .../plot/generator/AugmentedPopulator.java | 4 +- .../plot/util/ChunkManager.java | 61 ++++++++++++------- .../plot/util/ClusterManager.java | 2 +- 4 files changed, 53 insertions(+), 26 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java index a2cc119bc..35759d089 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Move.java @@ -53,22 +53,29 @@ public class Move extends SubCommand { if (plr == null) { PlayerFunctions.sendMessage(plr, "MUST BE EXECUTED BY PLAYER"); } + if (args.length != 2) { + PlayerFunctions.sendMessage(plr, "/plot move "); + return false; + } World world = plr.getWorld(); PlotId plot1 = PlotHelper.parseId(args[0]); PlotId plot2 = PlotHelper.parseId(args[1]); if (plot1 == null || plot2 == null) { PlayerFunctions.sendMessage(plr, "INVALID PLOT ID\n/plot move "); + return false; } if (plot1 == plot2) { PlayerFunctions.sendMessage(plr, "DUPLICATE ID"); + return false; } if (move(world, plot1, plot2, null)) { PlayerFunctions.sendMessage(plr, "MOVE SUCCESS"); + return true; } else { PlayerFunctions.sendMessage(plr, "MOVE FAILED"); + return false; } - return true; } public boolean move(final World world, final PlotId current, PlotId newPlot, final Runnable whenDone) { @@ -101,7 +108,8 @@ public class Move extends SubCommand { ChunkManager.copyRegion(bot1, top, bot2, new Runnable() { @Override public void run() { - ChunkManager.regenerateRegion(bot1, top, null); + Location bot = bot1.clone().add(1, 0, 1); + ChunkManager.regenerateRegion(bot, top, null); TaskManager.runTaskLater(whenDone, 1); } }); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java index 993bfac95..c6a4627a6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java @@ -131,7 +131,7 @@ public class AugmentedPopulator extends BlockPopulator { @Override public void run() { populateBiome(world, x, z); - chunk.unload(true, false); + chunk.unload(true, true); AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk})); } }, 20); @@ -148,7 +148,7 @@ public class AugmentedPopulator extends BlockPopulator { public void run() { chunk.load(true); populateBlocks(world, rand, X, Z, x, z, check); - chunk.unload(true, false); + chunk.unload(true, true); AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk})); } }, 40 + rand.nextInt(40)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index 81c3c419c..4d65d0c1b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -134,8 +134,10 @@ public class ChunkManager { * Copy a region to a new location (in the same world) */ public static boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) { - int relX = newPos.getBlockX() - pos1.getBlockX(); - int relZ = newPos.getBlockZ() - pos1.getBlockZ(); + index.increment(); + final int relX = newPos.getBlockX() - pos1.getBlockX(); + final int relZ = newPos.getBlockZ() - pos1.getBlockZ(); + System.out.print(relX + "," + relZ); RegionWrapper region = new RegionWrapper(pos1.getBlockX(), pos2.getBlockX(), pos1.getBlockZ(), pos2.getBlockZ()); final World world = pos1.getWorld(); @@ -161,7 +163,7 @@ public class ChunkManager { final int c4z = c4.getZ(); // Copy entities - ArrayList chunks = new ArrayList<>(); + final ArrayList chunks = new ArrayList<>(); initMaps(); for (int x = c3x; x <= c4x; x ++) { for (int z = c3z; z <= c4z; z ++) { @@ -183,24 +185,41 @@ public class ChunkManager { } // Copy blocks - int maxY = world.getMaxHeight(); - for (int x = sx; x <= ex; x++) { - for (int z = sz; z <= ez; z++) { - saveBlocks(world, maxY, x, z); - for (int y = 1; y <= maxY; y++) { - Block block = world.getBlockAt(x, y, z); - int id = block.getTypeId(); - byte data = block.getData(); - AbstractSetBlock.setBlockManager.set(world, x + relX, y, z + relZ, id, data); + final MutableInt mx = new MutableInt(sx); + final Plugin plugin = (Plugin) PlotMain.getMain(); + final Integer currentIndex = index.toInteger(); + final int maxY = world.getMaxHeight(); + final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + @Override + public void run() { + long start = System.currentTimeMillis(); + while (System.currentTimeMillis() - start < 20) { + int x = mx.intValue(); + System.out.print(x); + for (int z = sz; z <= ez; z++) { + saveBlocks(world, maxY, x, z); + for (int y = 1; y <= maxY; y++) { + Block block = world.getBlockAt(x, y, z); + int id = block.getTypeId(); + byte data = block.getData(); + AbstractSetBlock.setBlockManager.set(world, x + relX, y, z + relZ, id, data); + } + } + mx.increment(); + if (x + 1 == ex) { // done! + restoreBlocks(world, relX, relZ); + AbstractSetBlock.setBlockManager.update(chunks); + for (Chunk chunk : chunks) { + chunk.unload(true, true); + } + TaskManager.runTaskLater(whenDone, 1); + Bukkit.getScheduler().cancelTask(tasks.get(currentIndex)); + return; + } } - } - } - restoreBlocks(world, relX, relZ); - TaskManager.runTaskLater(whenDone, 1); - AbstractSetBlock.setBlockManager.update(chunks); - for (Chunk chunk : chunks) { - chunk.unload(true, false); - } + }; + }, 1, 1); + tasks.put(currentIndex, task); return true; } @@ -289,7 +308,7 @@ public class ChunkManager { restoreBlocks(world, 0, 0); restoreEntities(world, 0, 0); } - chunk.unload(true, false); + chunk.unload(true, true); AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk})); } CURRENT_PLOT_CLEAR = null; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java index 96a1aaa31..374ea83ea 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -290,7 +290,7 @@ public class ClusterManager { if (populator == null || plotworld.TYPE == 0) { AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk})); world.regenerateChunk(chunk.getX(), chunk.getZ()); - chunk.unload(true, false); + chunk.unload(true, true); } else { populator.populate(world, rand, chunk);