mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-26 10:44:42 +02:00
optimizations + more sponge work
This commit is contained in:
@ -241,20 +241,12 @@ public class DebugExec extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
case "stop-rgar": {
|
||||
if (((BukkitHybridUtils)(HybridUtils.manager)).task == 0) {
|
||||
if (!HybridUtils.UPDATE) {
|
||||
MainUtil.sendMessage(player, "&cTASK NOT RUNNING!");
|
||||
return false;
|
||||
}
|
||||
((BukkitHybridUtils)(HybridUtils.manager)).task = 0;
|
||||
PS.get().TASK.cancelTask(((BukkitHybridUtils)(HybridUtils.manager)).task);
|
||||
MainUtil.sendMessage(player, "&cCancelling task...");
|
||||
while (BukkitHybridUtils.chunks.size() > 0) {
|
||||
ChunkLoc chunk = BukkitHybridUtils.chunks.get(0);
|
||||
BukkitHybridUtils.chunks.remove(0);
|
||||
HybridUtils.manager.regenerateRoad(BukkitHybridUtils.world, chunk, 0);
|
||||
ChunkManager.manager.unloadChunk(BukkitHybridUtils.world, chunk, true, true);
|
||||
}
|
||||
MainUtil.sendMessage(player, "&cCancelled!");
|
||||
HybridUtils.UPDATE = false;
|
||||
MainUtil.sendMessage(player, "&cCancelling task... (please wait)");
|
||||
return true;
|
||||
}
|
||||
case "start-expire": {
|
||||
|
@ -1,10 +1,14 @@
|
||||
package com.intellectualcrafters.plot.generator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
@ -13,22 +17,192 @@ import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.SetBlockQueue;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public abstract class HybridUtils {
|
||||
|
||||
public static HybridUtils manager;
|
||||
|
||||
public abstract void checkModified(final Plot plot, final RunnableVal<Integer> whenDone);
|
||||
|
||||
public abstract void analyzePlot(final Plot plot, final RunnableVal<PlotAnalysis> whenDone);
|
||||
|
||||
public abstract int checkModified(final String world, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks);
|
||||
|
||||
public static List<ChunkLoc> regions;
|
||||
public static List<ChunkLoc> chunks = new ArrayList<>();
|
||||
public static String world;
|
||||
public static boolean UPDATE = false;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void checkModified(final Plot plot, final RunnableVal<Integer> whenDone) {
|
||||
if (whenDone == null) {
|
||||
return;
|
||||
}
|
||||
final Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
final Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
||||
if (!(plotworld instanceof ClassicPlotWorld)) {
|
||||
whenDone.value = -1;
|
||||
TaskManager.runTask(whenDone);
|
||||
return;
|
||||
}
|
||||
whenDone.value = 0;
|
||||
final ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld;
|
||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChunkLoc loc = new ChunkLoc(value[0], value[1]);
|
||||
ChunkManager.manager.loadChunk(plot.world, loc, false);
|
||||
int bx = value[2];
|
||||
int bz = value[3];
|
||||
int ex = value[4];
|
||||
int ez = value[5];
|
||||
whenDone.value += checkModified(plot.world, bx, ex, 1, cpw.PLOT_HEIGHT - 1, bz, ez, cpw.MAIN_BLOCK);
|
||||
whenDone.value += checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT, cpw.PLOT_HEIGHT, bz, ez, cpw.TOP_BLOCK);
|
||||
whenDone.value += checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT + 1, 255, bz, ez, new PlotBlock[] { new PlotBlock((short) 0, (byte) 0) });
|
||||
}
|
||||
}, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TaskManager.runTask(whenDone);
|
||||
}
|
||||
}, 5);
|
||||
}
|
||||
|
||||
public boolean scheduleRoadUpdate(final String world, int extend) {
|
||||
if (HybridUtils.UPDATE) {
|
||||
return false;
|
||||
}
|
||||
HybridUtils.UPDATE = true;
|
||||
final List<ChunkLoc> regions = ChunkManager.manager.getChunkChunks(world);
|
||||
return scheduleRoadUpdate(world, regions, extend);
|
||||
}
|
||||
|
||||
public boolean scheduleRoadUpdate(final String world, final List<ChunkLoc> rgs, final int extend) {
|
||||
HybridUtils.regions = rgs;
|
||||
HybridUtils.world = world;
|
||||
chunks = new ArrayList<ChunkLoc>();
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
final long baseTime = System.currentTimeMillis();
|
||||
final AtomicInteger last = new AtomicInteger();
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (UPDATE == false) {
|
||||
last.set(0);
|
||||
while (chunks.size() > 0) {
|
||||
ChunkLoc chunk = chunks.get(0);
|
||||
chunks.remove(0);
|
||||
regenerateRoad(world, chunk, extend);
|
||||
ChunkManager.manager.unloadChunk(world, chunk, true, true);
|
||||
}
|
||||
PS.debug("&cCancelled road task");
|
||||
return;
|
||||
}
|
||||
count.incrementAndGet();
|
||||
if (count.intValue() % 20 == 0) {
|
||||
PS.debug("PROGRESS: " + ((100 * (2048 - chunks.size())) / 2048) + "%");
|
||||
}
|
||||
if (regions.size() == 0 && chunks.size() == 0) {
|
||||
HybridUtils.UPDATE = false;
|
||||
PS.debug(C.PREFIX.s() + "Finished road conversion");
|
||||
// CANCEL TASK
|
||||
return;
|
||||
} else {
|
||||
final Runnable task = this;
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (last.get() == 0) {
|
||||
last.set((int) (System.currentTimeMillis() - baseTime));
|
||||
}
|
||||
if (chunks.size() < 1024) {
|
||||
if (regions.size() > 0) {
|
||||
final ChunkLoc loc = regions.get(0);
|
||||
PS.debug("&3Updating .mcr: " + loc.x + ", " + loc.z + " (aprrox 1024 chunks)");
|
||||
PS.debug(" - Remaining: " + regions.size());
|
||||
chunks.addAll(getChunks(loc));
|
||||
regions.remove(0);
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
if (chunks.size() > 0) {
|
||||
long diff = System.currentTimeMillis() + 1;
|
||||
if (System.currentTimeMillis() - baseTime - last.get() > 2000 && last.get() != 0) {
|
||||
last.set(0);
|
||||
PS.debug(C.PREFIX.s() + "Detected low TPS. Rescheduling in 30s");
|
||||
final ChunkLoc chunk = chunks.get(0);
|
||||
chunks.remove(0);
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
regenerateRoad(world, chunk, extend);
|
||||
}
|
||||
});
|
||||
// DELAY TASK
|
||||
TaskManager.runTaskLater(task, 600);
|
||||
return;
|
||||
}
|
||||
if ((System.currentTimeMillis() - baseTime) - last.get() < 1500 && last.get() != 0) {
|
||||
while (System.currentTimeMillis() < diff && chunks.size() > 0) {
|
||||
final ChunkLoc chunk = chunks.get(0);
|
||||
chunks.remove(0);
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
regenerateRoad(world, chunk, extend);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
last.set((int) (System.currentTimeMillis() - baseTime));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
final ChunkLoc loc = regions.get(0);
|
||||
PS.debug("&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), true, true);
|
||||
}
|
||||
}
|
||||
PS.debug("&d - Potentially skipping 1024 chunks");
|
||||
PS.debug("&d - TODO: recommend chunkster if corrupt");
|
||||
}
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TaskManager.runTaskLater(task, 20);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setupRoadSchematic(final Plot plot) {
|
||||
final String world = plot.world;
|
||||
final Location bot = MainUtil.getPlotBottomLoc(world, plot.id);
|
||||
@ -70,8 +244,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 boolean scheduleRoadUpdate(final String world, int extend);
|
||||
|
||||
public boolean regenerateRoad(final String world, final ChunkLoc chunk, int extend) {
|
||||
final int x = chunk.x << 4;
|
||||
final int z = chunk.z << 4;
|
||||
@ -138,13 +310,13 @@ public abstract class HybridUtils {
|
||||
final PlotLoc loc = new PlotLoc(absX, absZ);
|
||||
final HashMap<Short, Short> blocks = plotworld.G_SCH.get(loc);
|
||||
for (short y = (short) (plotworld.ROAD_HEIGHT); y <= (plotworld.ROAD_HEIGHT + plotworld.SCHEMATIC_HEIGHT + extend); y++) {
|
||||
BlockManager.manager.functionSetBlock(world, x + X, y, z + Z, 0, (byte) 0);
|
||||
SetBlockQueue.setBlock(world, x + X, y, z + Z, 0);
|
||||
}
|
||||
if (blocks != null) {
|
||||
final HashMap<Short, Byte> datas = plotworld.G_SCH_DATA.get(loc);
|
||||
if (datas == null) {
|
||||
for (final Short y : blocks.keySet()) {
|
||||
BlockManager.manager.functionSetBlock(world, x + X, sy + y, z + Z, blocks.get(y), (byte) 0);
|
||||
SetBlockQueue.setBlock(world, x + X, sy + y, z + Z, blocks.get(y));
|
||||
}
|
||||
} else {
|
||||
for (final Short y : blocks.keySet()) {
|
||||
@ -152,13 +324,19 @@ public abstract class HybridUtils {
|
||||
if (data == null) {
|
||||
data = 0;
|
||||
}
|
||||
BlockManager.manager.functionSetBlock(world, x + X, sy + y, z + Z, blocks.get(y), data);
|
||||
SetBlockQueue.setBlock(world, x + X, sy + y, z + Z, new PlotBlock(blocks.get(y), data));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChunkManager.manager.unloadChunk(world, chunk, true, true);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,13 @@ public abstract class TaskManager {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int runTaskRepeatAsync(final Runnable r, final int interval) {
|
||||
if (r != null) {
|
||||
return PS.get().TASK.taskRepeat(r, interval);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void runTaskAsync(final Runnable r) {
|
||||
if (r != null) {
|
||||
@ -49,6 +56,8 @@ public abstract class TaskManager {
|
||||
}
|
||||
|
||||
public abstract int taskRepeat(final Runnable r, int interval);
|
||||
|
||||
public abstract int taskRepeatAsync(final Runnable r, int interval);
|
||||
|
||||
public abstract void taskAsync(final Runnable r);
|
||||
|
||||
|
Reference in New Issue
Block a user