This commit is contained in:
boy0001 2015-02-16 02:22:00 +11:00
parent 37febd40b7
commit dd152ce28e
6 changed files with 121 additions and 86 deletions

View File

@ -68,8 +68,12 @@ public class Move extends SubCommand {
PlayerFunctions.sendMessage(plr, "DUPLICATE ID");
return false;
}
if (move(world, plot1, plot2, null)) {
PlayerFunctions.sendMessage(plr, "MOVE SUCCESS");
if (move(world, plot1, plot2, new Runnable() {
@Override
public void run() {
PlayerFunctions.sendMessage(plr, "MOVE SUCCESS");
}
})) {
return true;
}
else {

View File

@ -122,7 +122,7 @@ public class Trim extends SubCommand {
if (Trim.TASK) {
return false;
}
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
String directory = world.getName() + File.separator + "region";
@ -169,7 +169,7 @@ public class Trim extends SubCommand {
}
}
Trim.TASK = false;
TaskManager.runTask(whenDone);
TaskManager.runTaskAsync(whenDone);
}
});
Trim.TASK = true;
@ -197,7 +197,7 @@ public class Trim extends SubCommand {
empty.addAll(chunks);
System.out.print("DONE!");
Trim.TASK = false;
TaskManager.runTask(whenDone);
TaskManager.runTaskAsync(whenDone);
Bukkit.getScheduler().cancelTask(Trim.TASK_ID);
return;
}

View File

@ -114,7 +114,7 @@ public class SQLManager implements AbstractDB {
*/
@Override
public void setOwner(final Plot plot, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -308,7 +308,7 @@ public class SQLManager implements AbstractDB {
*/
@Override
public void createPlot(final Plot plot) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
@ -330,7 +330,7 @@ public class SQLManager implements AbstractDB {
@Override
public void createPlotAndSettings(final Plot plot) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
@ -410,7 +410,7 @@ public class SQLManager implements AbstractDB {
@Override
public void delete(final String world, final Plot plot) {
PlotMain.removePlot(world, plot.id, false);
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
@ -451,7 +451,7 @@ public class SQLManager implements AbstractDB {
*/
@Override
public void createPlotSettings(final int id, final Plot plot) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
@ -730,7 +730,7 @@ public class SQLManager implements AbstractDB {
@Override
public void setMerged(final String world, final Plot plot, final boolean[] merged) {
plot.settings.setMerged(merged);
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -753,7 +753,7 @@ public class SQLManager implements AbstractDB {
@Override
public void swapPlots(final Plot p1, final Plot p2) {
TaskManager.runTask(
TaskManager.runTaskAsync(
new Runnable() {
@Override
public void run() {
@ -790,7 +790,7 @@ public class SQLManager implements AbstractDB {
@Override
public void movePlot(final String world, final PlotId originalPlot, final PlotId newPlot) {
TaskManager.runTask(
TaskManager.runTaskAsync(
new Runnable() {
@Override
public void run() {
@ -821,7 +821,7 @@ public class SQLManager implements AbstractDB {
flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4"));
i++;
}
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -846,7 +846,7 @@ public class SQLManager implements AbstractDB {
}
}
final String flag_string = StringUtils.join(newflags, ",");
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -870,7 +870,7 @@ public class SQLManager implements AbstractDB {
@Override
public void setAlias(final String world, final Plot plot, final String alias) {
plot.settings.setAlias(alias);
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
@ -962,7 +962,7 @@ public class SQLManager implements AbstractDB {
*/
@Override
public void setPosition(final String world, final Plot plot, final String position) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
@ -1034,7 +1034,7 @@ public class SQLManager implements AbstractDB {
@Override
public void removeComment(final String world, final Plot plot, final PlotComment comment) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1095,7 +1095,7 @@ public class SQLManager implements AbstractDB {
@Override
public void setComment(final String world, final Plot plot, final PlotComment comment) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1121,7 +1121,7 @@ public class SQLManager implements AbstractDB {
*/
@Override
public void removeHelper(final String world, final Plot plot, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1144,7 +1144,7 @@ public class SQLManager implements AbstractDB {
*/
@Override
public void removeTrusted(final String world, final Plot plot, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1167,7 +1167,7 @@ public class SQLManager implements AbstractDB {
*/
@Override
public void setHelper(final String world, final Plot plot, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1185,7 +1185,7 @@ public class SQLManager implements AbstractDB {
}
public void setHelper(final int id, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1208,7 +1208,7 @@ public class SQLManager implements AbstractDB {
*/
@Override
public void setTrusted(final String world, final Plot plot, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1231,7 +1231,7 @@ public class SQLManager implements AbstractDB {
*/
@Override
public void removeDenied(final String world, final Plot plot, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1254,7 +1254,7 @@ public class SQLManager implements AbstractDB {
*/
@Override
public void setDenied(final String world, final Plot plot, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1293,7 +1293,7 @@ public class SQLManager implements AbstractDB {
@Override
public void delete(final PlotCluster cluster) {
ClusterManager.removeCluster(cluster);
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
@ -1548,7 +1548,7 @@ public class SQLManager implements AbstractDB {
flag_string.append(flag.getKey() + ":" + flag.getValueString().replaceAll(":", "\u00AF").replaceAll(",", "\u00B4"));
i++;
}
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1569,7 +1569,7 @@ public class SQLManager implements AbstractDB {
@Override
public void setClusterName(final PlotCluster cluster, final String name) {
cluster.settings.setAlias(name);
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
@ -1590,7 +1590,7 @@ public class SQLManager implements AbstractDB {
@Override
public void removeHelper(final PlotCluster cluster, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1609,7 +1609,7 @@ public class SQLManager implements AbstractDB {
@Override
public void setHelper(final PlotCluster cluster, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1628,7 +1628,7 @@ public class SQLManager implements AbstractDB {
@Override
public void createCluster(final PlotCluster cluster) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
@ -1663,7 +1663,7 @@ public class SQLManager implements AbstractDB {
final PlotId pos2 = new PlotId(current.getP2().x, current.getP2().y);
current.setP1(resize.pos1);
current.setP2(resize.pos2);
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
@ -1686,7 +1686,7 @@ public class SQLManager implements AbstractDB {
@Override
public void setPosition(final PlotCluster cluster, final String position) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
PreparedStatement stmt = null;
@ -1753,7 +1753,7 @@ public class SQLManager implements AbstractDB {
@Override
public void removeInvited(final PlotCluster cluster, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
@ -1773,7 +1773,7 @@ public class SQLManager implements AbstractDB {
@Override
public void setInvited(String world, final PlotCluster cluster, final UUID uuid) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {

View File

@ -77,7 +77,7 @@ public class ChunkManager {
}
public static void deleteRegionFile(final String world, final ChunkLoc loc) {
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
String directory = world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca";
@ -138,14 +138,14 @@ public class ChunkManager {
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 RegionWrapper region = new RegionWrapper(pos1.getBlockX(), pos2.getBlockX(), pos1.getBlockZ(), pos2.getBlockZ());
final World world = pos1.getWorld();
Chunk c1 = world.getChunkAt(pos1);
Chunk c2 = world.getChunkAt(pos2);
Chunk c3 = world.getChunkAt(pos1.getBlockX() + relX, pos1.getBlockZ() + relZ);
Chunk c4 = world.getChunkAt(pos2.getBlockX() + relX, pos2.getBlockZ() + relZ);
Chunk c3 = world.getChunkAt((pos1.getBlockX() + relX) >> 4, (pos1.getBlockZ() + relZ) >> 4);
Chunk c4 = world.getChunkAt((pos2.getBlockX() + relX) >> 4, (pos2.getBlockZ() + relZ) >> 4);
final int sx = pos1.getBlockX();
final int sz = pos1.getBlockZ();
@ -162,64 +162,90 @@ public class ChunkManager {
final int c4x = c4.getX();
final int c4z = c4.getZ();
// Copy entities
final ArrayList<Chunk> chunks = new ArrayList<>();
initMaps();
for (int x = c3x; x <= c4x; x ++) {
for (int z = c3z; z <= c4z; z ++) {
Chunk chunk = world.getChunkAt(x, z);
chunks.add(chunk);
chunk.load(false);
saveEntitiesIn(chunk, region);
restoreEntities(world, relX, relZ);
}
}
final ArrayList<Chunk> toGenerate = new ArrayList<>();
// Load chunks
for (int x = c1x; x <= c2x; x ++) {
for (int z = c1z; z <= c2z; z ++) {
Chunk chunk = world.getChunkAt(x, z);
chunk.load(true);
chunks.add(chunk);
toGenerate.add(chunk);
}
}
// Copy blocks
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() {
final int loadTask = 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);
if (toGenerate.size() == 0) {
Bukkit.getScheduler().cancelTask(tasks.get(currentIndex));
tasks.remove(currentIndex);
TaskManager.runTask(new Runnable() {
@Override
public void run() {
System.out.print("================== SETTING BLOCKS ===================");
index.increment();
// Copy entities
initMaps();
for (int x = c3x; x <= c4x; x ++) {
for (int z = c3z; z <= c4z; z ++) {
Chunk chunk = world.getChunkAt(x, z);
System.out.print("SAVING ENTITIES: " + chunk);
chunks.add(chunk);
chunk.load(false);
saveEntitiesIn(chunk, region);
restoreEntities(world, relX, relZ);
}
}
// Copy blocks
final MutableInt mx = new MutableInt(sx);
final Integer currentIndex = index.toInteger();
final int maxY = world.getMaxHeight();
final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
System.out.print(" - " + mx.intValue());
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));
tasks.remove(currentIndex);
return;
}
}
};
}, 1, 1);
tasks.put(currentIndex, task);
}
}
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;
}
});
return;
}
};
}, 1, 1);
tasks.put(currentIndex, task);
Chunk chunk = toGenerate.get(0);
toGenerate.remove(0);
chunk.load(true);
chunks.add(chunk);
System.out.print("GENERATING CHUNK: " + chunk);
}
}, 1l, 1l);
tasks.put(currentIndex, loadTask);
return true;
}
@ -257,6 +283,7 @@ public class ChunkManager {
if (chunks.size() == 0) {
TaskManager.runTaskLater(whenDone, 1);
Bukkit.getScheduler().cancelTask(tasks.get(currentIndex));
tasks.remove(currentIndex);
return;
}
CURRENT_PLOT_CLEAR = new RegionWrapper(pos1.getBlockX(), pos2.getBlockX(), pos1.getBlockZ(), pos2.getBlockZ());

View File

@ -44,7 +44,7 @@ public class ExpireManager {
long now = System.currentTimeMillis();
if (now > getTimeStamp(world)) {
timestamp.put(world, now + 86400000l);
TaskManager.runTask(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
HashMap<Plot, Long> plots = getOldPlots(world);

View File

@ -8,10 +8,14 @@ public class TaskManager {
public static HashSet<String> TELEPORT_QUEUE = new HashSet<>();
public static void runTask(final Runnable r) {
public static void runTaskAsync(final Runnable r) {
PlotMain.getMain().getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), r);
}
public static void runTask(final Runnable r) {
PlotMain.getMain().getServer().getScheduler().runTask(PlotMain.getMain(), r);
}
public static void runTaskLater(final Runnable r, int delay) {
if (r == null) {
return;