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,59 +89,67 @@ 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) { try {
LAST = System.currentTimeMillis(); if (chunks.size() < 1024) {
} final ChunkLoc loc = regions.get(0);
long current = System.currentTimeMillis() - LAST;
AV = Math.max(current, (current + AV * 5) / 6);
LAST = System.currentTimeMillis();
if (AV < 1500) {
try {
final ChunkLoc loc = chunks.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.remove(0); chunks.addAll(getChunks(regions.get(0)));
regenerateChunkChunk(world, loc); regions.remove(0);
} catch (final Exception e) { }
final ChunkLoc loc = chunks.get(0); if (chunks.size() > 0) {
PlotSquared.log("&c[ERROR]&7 Could not update '" + world + "/region/r." + loc.x + "." + loc.z + ".mca' (Corrupt chunk?)"); long diff = System.currentTimeMillis() + 50;
final int sx = loc.x << 5; while (System.currentTimeMillis() < diff) {
final int sz = loc.z << 5; ChunkLoc chunk = chunks.get(0);
for (int x = sx; x < (sx + 32); x++) { chunks.remove(0);
for (int z = sz; z < (sz + 32); z++) { regenerateRoad(world, chunk);
ChunkManager.manager.unloadChunk(world, new ChunkLoc(x, z));
} }
}
} catch (final Exception e) {
final ChunkLoc loc = regions.get(0);
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 sz = loc.z << 5;
for (int x = sx; x < (sx + 32); x++) {
for (int z = sz; z < (sz + 32); z++) {
ChunkManager.manager.unloadChunk(world, new ChunkLoc(x, z));
} }
PlotSquared.log("&d - Potentially skipping 1024 chunks");
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...");
} }
PlotSquared.log("&d - Potentially skipping 1024 chunks");
PlotSquared.log("&d - TODO: recommend chunkster if corrupt");
} }
} }
} }

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) {