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,24 +185,41 @@ 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();
for (int z = sz; z <= ez; z++) { final Integer currentIndex = index.toInteger();
saveBlocks(world, maxY, x, z); final int maxY = world.getMaxHeight();
for (int y = 1; y <= maxY; y++) { final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
Block block = world.getBlockAt(x, y, z); @Override
int id = block.getTypeId(); public void run() {
byte data = block.getData(); long start = System.currentTimeMillis();
AbstractSetBlock.setBlockManager.set(world, x + relX, y, z + relZ, id, data); 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;
}
} }
} };
} }, 1, 1);
restoreBlocks(world, relX, relZ); tasks.put(currentIndex, task);
TaskManager.runTaskLater(whenDone, 1);
AbstractSetBlock.setBlockManager.update(chunks);
for (Chunk chunk : chunks) {
chunk.unload(true, false);
}
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);