This commit is contained in:
boy0001 2015-03-24 16:27:56 +11:00
parent 548127dc1d
commit 98232107f9
2 changed files with 41 additions and 36 deletions

View File

@ -68,7 +68,6 @@ public class BukkitHybridUtils extends HybridUtils {
return ey; return ey;
} }
@Override
public void regenerateChunkChunk(final String worldname, final ChunkLoc loc) { public void regenerateChunkChunk(final String worldname, final ChunkLoc loc) {
final World world = BukkitUtil.getWorld(worldname); final World world = BukkitUtil.getWorld(worldname);
final int sx = loc.x << 5; final int sx = loc.x << 5;
@ -90,42 +89,57 @@ public class BukkitHybridUtils extends HybridUtils {
} }
} }
public final ArrayList<ChunkLoc> getChunks(ChunkLoc region) {
ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
final int sx = region.x << 5;
final int sz = region.z << 5;
for (int x = sx; x < (sx + 32); x++) {
for (int z = sz; z < (sz + 32); z++) {
chunks.add(new ChunkLoc(x, z));
}
}
return chunks;
}
private static boolean UPDATE = false; private static boolean UPDATE = false;
private int task; private int task;
private long LAST = 0;
private double AV = 1000;
@Override @Override
public boolean scheduleRoadUpdate(final String world) { public boolean scheduleRoadUpdate(final String world) {
if (BukkitHybridUtils.UPDATE) { if (BukkitHybridUtils.UPDATE) {
return false; return false;
} }
final List<ChunkLoc> chunks = ChunkManager.manager.getChunkChunks(world); final List<ChunkLoc> regions = ChunkManager.manager.getChunkChunks(world);
final List<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
final Plugin plugin = BukkitMain.THIS; final Plugin plugin = BukkitMain.THIS;
this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
if (chunks.size() == 0) { if (regions.size() == 0) {
BukkitHybridUtils.UPDATE = false; BukkitHybridUtils.UPDATE = false;
PlotSquared.log(C.PREFIX.s() + "Finished road conversion"); PlotSquared.log(C.PREFIX.s() + "Finished road conversion");
Bukkit.getScheduler().cancelTask(BukkitHybridUtils.this.task); Bukkit.getScheduler().cancelTask(BukkitHybridUtils.this.task);
return; return;
} else { } else {
if (LAST == 0) {
LAST = System.currentTimeMillis();
}
long current = System.currentTimeMillis() - LAST;
AV = Math.max(current, (current + AV * 5) / 6);
LAST = System.currentTimeMillis();
if (AV < 1500) {
try { try {
final ChunkLoc loc = chunks.get(0); if (chunks.size() < 1024) {
final ChunkLoc loc = regions.get(0);
PlotSquared.log("&3Updating .mcr: " + loc.x + ", " + loc.z + " (aprrox 1024 chunks)"); PlotSquared.log("&3Updating .mcr: " + loc.x + ", " + loc.z + " (aprrox 1024 chunks)");
PlotSquared.log(" - Remaining: " + chunks.size()); PlotSquared.log(" - Remaining: " + regions.size());
chunks.addAll(getChunks(regions.get(0)));
regions.remove(0);
}
if (chunks.size() > 0) {
long diff = System.currentTimeMillis() + 50;
while (System.currentTimeMillis() < diff) {
ChunkLoc chunk = chunks.get(0);
chunks.remove(0); chunks.remove(0);
regenerateChunkChunk(world, loc); regenerateRoad(world, chunk);
}
}
} catch (final Exception e) { } catch (final Exception e) {
final ChunkLoc loc = chunks.get(0); final ChunkLoc loc = regions.get(0);
PlotSquared.log("&c[ERROR]&7 Could not update '" + world + "/region/r." + loc.x + "." + loc.z + ".mca' (Corrupt chunk?)"); PlotSquared.log("&c[ERROR]&7 Could not update '" + world + "/region/r." + loc.x + "." + loc.z + ".mca' (Corrupt chunk?)");
final int sx = loc.x << 5; final int sx = loc.x << 5;
final int sz = loc.z << 5; final int sz = loc.z << 5;
@ -138,13 +152,6 @@ public class BukkitHybridUtils extends HybridUtils {
PlotSquared.log("&d - TODO: recommend chunkster if corrupt"); PlotSquared.log("&d - TODO: recommend chunkster if corrupt");
} }
} }
else {
double tps = (20000.0/Math.min(AV, current));
if (tps < 19) {
System.out.print("waiting for chunks to unload...");
}
}
}
} }
}, 20, 20); }, 20, 20);
return true; return true;

View File

@ -85,8 +85,6 @@ public abstract class HybridUtils {
public abstract int get_ey(final String world, final int sx, final int ex, final int sz, final int ez, final int sy); public abstract int get_ey(final String world, final int sx, final int ex, final int sz, final int ez, final int sy);
public abstract void regenerateChunkChunk(final String world, final ChunkLoc loc);
public abstract boolean scheduleRoadUpdate(final String world); public abstract boolean scheduleRoadUpdate(final String world);
public boolean regenerateRoad(final String world, final ChunkLoc chunk) { public boolean regenerateRoad(final String world, final ChunkLoc chunk) {