more move stuff

This commit is contained in:
boy0001 2015-02-16 01:31:24 +11:00
parent 1e8ce84769
commit 37febd40b7
4 changed files with 53 additions and 26 deletions

View File

@ -53,22 +53,29 @@ public class Move extends SubCommand {
if (plr == null) { if (plr == null) {
PlayerFunctions.sendMessage(plr, "MUST BE EXECUTED BY PLAYER"); PlayerFunctions.sendMessage(plr, "MUST BE EXECUTED BY PLAYER");
} }
if (args.length != 2) {
PlayerFunctions.sendMessage(plr, "/plot move <pos1> <pos2>");
return false;
}
World world = plr.getWorld(); World world = plr.getWorld();
PlotId plot1 = PlotHelper.parseId(args[0]); PlotId plot1 = PlotHelper.parseId(args[0]);
PlotId plot2 = PlotHelper.parseId(args[1]); PlotId plot2 = PlotHelper.parseId(args[1]);
if (plot1 == null || plot2 == null) { if (plot1 == null || plot2 == null) {
PlayerFunctions.sendMessage(plr, "INVALID PLOT ID\n/plot move <pos1> <pos2>"); PlayerFunctions.sendMessage(plr, "INVALID PLOT ID\n/plot move <pos1> <pos2>");
return false;
} }
if (plot1 == plot2) { if (plot1 == plot2) {
PlayerFunctions.sendMessage(plr, "DUPLICATE ID"); PlayerFunctions.sendMessage(plr, "DUPLICATE ID");
return false;
} }
if (move(world, plot1, plot2, null)) { if (move(world, plot1, plot2, null)) {
PlayerFunctions.sendMessage(plr, "MOVE SUCCESS"); PlayerFunctions.sendMessage(plr, "MOVE SUCCESS");
return true;
} }
else { else {
PlayerFunctions.sendMessage(plr, "MOVE FAILED"); PlayerFunctions.sendMessage(plr, "MOVE FAILED");
return false;
} }
return true;
} }
public boolean move(final World world, final PlotId current, PlotId newPlot, final Runnable whenDone) { 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() { ChunkManager.copyRegion(bot1, top, bot2, new Runnable() {
@Override @Override
public void run() { 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); TaskManager.runTaskLater(whenDone, 1);
} }
}); });

View File

@ -131,7 +131,7 @@ public class AugmentedPopulator extends BlockPopulator {
@Override @Override
public void run() { public void run() {
populateBiome(world, x, z); populateBiome(world, x, z);
chunk.unload(true, false); chunk.unload(true, true);
AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk})); AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk}));
} }
}, 20); }, 20);
@ -148,7 +148,7 @@ public class AugmentedPopulator extends BlockPopulator {
public void run() { public void run() {
chunk.load(true); chunk.load(true);
populateBlocks(world, rand, X, Z, x, z, check); populateBlocks(world, rand, X, Z, x, z, check);
chunk.unload(true, false); chunk.unload(true, true);
AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk})); AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk}));
} }
}, 40 + rand.nextInt(40)); }, 40 + rand.nextInt(40));

View File

@ -134,8 +134,10 @@ public class ChunkManager {
* Copy a region to a new location (in the same world) * 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) { public static boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
int relX = newPos.getBlockX() - pos1.getBlockX(); index.increment();
int relZ = newPos.getBlockZ() - pos1.getBlockZ(); 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()); RegionWrapper region = new RegionWrapper(pos1.getBlockX(), pos2.getBlockX(), pos1.getBlockZ(), pos2.getBlockZ());
final World world = pos1.getWorld(); final World world = pos1.getWorld();
@ -161,7 +163,7 @@ public class ChunkManager {
final int c4z = c4.getZ(); final int c4z = c4.getZ();
// Copy entities // Copy entities
ArrayList<Chunk> chunks = new ArrayList<>(); final ArrayList<Chunk> chunks = new ArrayList<>();
initMaps(); initMaps();
for (int x = c3x; x <= c4x; x ++) { for (int x = c3x; x <= c4x; x ++) {
for (int z = c3z; z <= c4z; z ++) { for (int z = c3z; z <= c4z; z ++) {
@ -183,8 +185,17 @@ public class ChunkManager {
} }
// Copy blocks // Copy blocks
int maxY = world.getMaxHeight(); final MutableInt mx = new MutableInt(sx);
for (int x = sx; x <= ex; x++) { 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++) { for (int z = sz; z <= ez; z++) {
saveBlocks(world, maxY, x, z); saveBlocks(world, maxY, x, z);
for (int y = 1; y <= maxY; y++) { for (int y = 1; y <= maxY; y++) {
@ -194,13 +205,21 @@ public class ChunkManager {
AbstractSetBlock.setBlockManager.set(world, x + relX, y, z + relZ, id, data); AbstractSetBlock.setBlockManager.set(world, x + relX, y, z + relZ, id, data);
} }
} }
} mx.increment();
if (x + 1 == ex) { // done!
restoreBlocks(world, relX, relZ); restoreBlocks(world, relX, relZ);
TaskManager.runTaskLater(whenDone, 1);
AbstractSetBlock.setBlockManager.update(chunks); AbstractSetBlock.setBlockManager.update(chunks);
for (Chunk chunk : chunks) { for (Chunk chunk : chunks) {
chunk.unload(true, false); chunk.unload(true, true);
} }
TaskManager.runTaskLater(whenDone, 1);
Bukkit.getScheduler().cancelTask(tasks.get(currentIndex));
return;
}
}
};
}, 1, 1);
tasks.put(currentIndex, task);
return true; return true;
} }
@ -289,7 +308,7 @@ public class ChunkManager {
restoreBlocks(world, 0, 0); restoreBlocks(world, 0, 0);
restoreEntities(world, 0, 0); restoreEntities(world, 0, 0);
} }
chunk.unload(true, false); chunk.unload(true, true);
AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk})); AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk}));
} }
CURRENT_PLOT_CLEAR = null; CURRENT_PLOT_CLEAR = null;

View File

@ -290,7 +290,7 @@ public class ClusterManager {
if (populator == null || plotworld.TYPE == 0) { if (populator == null || plotworld.TYPE == 0) {
AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk})); AbstractSetBlock.setBlockManager.update(Arrays.asList( new Chunk[] {chunk}));
world.regenerateChunk(chunk.getX(), chunk.getZ()); world.regenerateChunk(chunk.getX(), chunk.getZ());
chunk.unload(true, false); chunk.unload(true, true);
} }
else { else {
populator.populate(world, rand, chunk); populator.populate(world, rand, chunk);