Minor changes to the block queue classes to match FAWE more closely.

This commit is contained in:
MattBDev 2019-09-09 15:15:44 -04:00
parent ecfb71b08f
commit 07b88e3147
9 changed files with 29 additions and 26 deletions

View File

@ -228,7 +228,7 @@ public class BukkitChunkManager extends ChunkManager {
}
}
queue.enqueue();
GlobalBlockQueue.IMP.addTask(() -> {
GlobalBlockQueue.IMP.addEmptyTask(() -> {
//map.restoreBlocks(newWorld, 0, 0);
map.restoreEntities(newWorld, relX, relZ);
TaskManager.runTask(whenDone);
@ -444,7 +444,7 @@ public class BukkitChunkManager extends ChunkManager {
maps.add(swapChunk(world1, world2, chunk1, chunk2, region1, region2));
}
}
GlobalBlockQueue.IMP.addTask(() -> {
GlobalBlockQueue.IMP.addEmptyTask(() -> {
for (ContentMap map : maps) {
map.restoreEntities(world1, 0, 0);
TaskManager.runTaskLater(whenDone, 1);

View File

@ -42,7 +42,7 @@ import java.util.concurrent.CompletableFuture;
final long start = System.currentTimeMillis();
boolean result = plot.clear(true, false, () -> {
plot.unlink();
GlobalBlockQueue.IMP.addTask(() -> {
GlobalBlockQueue.IMP.addEmptyTask(() -> {
plot.removeRunning();
// If the state changes, then mark it as no longer done
if (plot.getFlag(Flags.DONE).isPresent()) {

View File

@ -107,7 +107,7 @@ import java.util.stream.IntStream;
current.setComponent(component, bucket);
}
MainUtil.sendMessage(player, Captions.GENERATING_COMPONENT);
GlobalBlockQueue.IMP.addTask(plot::removeRunning);
GlobalBlockQueue.IMP.addEmptyTask(plot::removeRunning);
return true;
}
}

View File

@ -158,7 +158,7 @@ import java.util.zip.ZipOutputStream;
setup.step = new ConfigurationNode[0];
setup.world = world;
SetupUtils.manager.setupWorld(setup);
GlobalBlockQueue.IMP.addTask(() -> {
GlobalBlockQueue.IMP.addEmptyTask(() -> {
MainUtil.sendMessage(player, "Done!");
player.teleport(WorldUtil.IMP.getSpawn(world));
});

View File

@ -46,7 +46,7 @@ public class ClassicPlotManager extends SquarePlotManager {
@Override public boolean unClaimPlot(Plot plot, Runnable whenDone) {
setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING);
setWall(plot.getId(), classicPlotWorld.WALL_BLOCK);
return GlobalBlockQueue.IMP.addTask(whenDone);
return GlobalBlockQueue.IMP.addEmptyTask(whenDone);
}
public boolean setFloor(PlotId plotId, BlockBucket blocks) {

View File

@ -207,7 +207,7 @@ public class HybridPlotManager extends ClassicPlotManager {
}, () -> {
queue.enqueue();
// And notify whatever called this when plot clearing is done
GlobalBlockQueue.IMP.addTask(whenDone);
GlobalBlockQueue.IMP.addEmptyTask(whenDone);
}, 10);
return true;
}

View File

@ -223,7 +223,7 @@ public abstract class HybridUtils {
PlotSquared.debug("&d - Potentially skipping 1024 chunks");
PlotSquared.debug("&d - TODO: recommend chunkster if corrupt");
}
GlobalBlockQueue.IMP.addTask(() -> TaskManager.runTaskLater(task, 20));
GlobalBlockQueue.IMP.addEmptyTask(() -> TaskManager.runTaskLater(task, 20));
});
}
}

View File

@ -869,7 +869,7 @@ public class Plot {
manager.claimPlot(current);
}
}
GlobalBlockQueue.IMP.addTask(run);
GlobalBlockQueue.IMP.addEmptyTask(run);
return;
}
Plot current = queue.poll();
@ -982,7 +982,7 @@ public class Plot {
current.setMerged(merged);
}
if (createSign) {
GlobalBlockQueue.IMP.addTask(() -> {
GlobalBlockQueue.IMP.addEmptyTask(() -> {
for (Plot current : plots) {
current.setSign(MainUtil.getName(current.owner));
}

View File

@ -8,7 +8,6 @@ import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.atomic.AtomicBoolean;
@ -21,8 +20,10 @@ public class GlobalBlockQueue {
private final ConcurrentLinkedDeque<Runnable> runnables;
private final AtomicBoolean running;
private QueueProvider provider;
/**
* Used to calculate elapsed time in milliseconds and ensure block placement doesn't lag the server
* Used to calculate elapsed time in milliseconds and ensure block placement doesn't lag the
* server
*/
private long last;
private long secondLast;
@ -35,11 +36,12 @@ public class GlobalBlockQueue {
if (!more) {
lastSuccess = last;
if (inactiveQueues.size() == 0 && activeQueues.size() == 0) {
tasks();
runEmptyTasks();
}
return;
}
} while (((GlobalBlockQueue.this.secondLast = System.currentTimeMillis())- GlobalBlockQueue.this.last) < free);
} while (((GlobalBlockQueue.this.secondLast = System.currentTimeMillis())
- GlobalBlockQueue.this.last) < free);
}
};
@ -85,10 +87,12 @@ public class GlobalBlockQueue {
@Override public void run() {
if (inactiveQueues.isEmpty() && activeQueues.isEmpty()) {
lastSuccess = System.currentTimeMillis();
GlobalBlockQueue.this.tasks();
GlobalBlockQueue.this.runEmptyTasks();
return;
}
SET_TASK.value1 = 50 + Math.min((50 + GlobalBlockQueue.this.last) - (GlobalBlockQueue.this.last = System.currentTimeMillis()),
SET_TASK.value1 = 50 + Math.min(
(50 + GlobalBlockQueue.this.last) - (GlobalBlockQueue.this.last =
System.currentTimeMillis()),
GlobalBlockQueue.this.secondLast - System.currentTimeMillis());
SET_TASK.value2 = GlobalBlockQueue.this.getNextQueue();
if (SET_TASK.value2 == null) {
@ -231,7 +235,7 @@ public class GlobalBlockQueue {
public LocalBlockQueue getNextQueue() {
long now = System.currentTimeMillis();
while (activeQueues.size() > 0) {
while (!activeQueues.isEmpty()) {
LocalBlockQueue queue = activeQueues.peek();
if (queue != null && queue.size() > 0) {
queue.setModified(now);
@ -251,7 +255,7 @@ public class GlobalBlockQueue {
long age = now - queue.getModified();
total += queue.size();
if (queue.size() == 0) {
if (age > 1000) {
if (age > 60000) {
iter.remove();
}
continue;
@ -263,7 +267,7 @@ public class GlobalBlockQueue {
firstNonEmpty.setModified(now);
return firstNonEmpty;
}
if (age > 60000) {
if (age > 1000) {
queue.setModified(now);
return queue;
}
@ -279,10 +283,10 @@ public class GlobalBlockQueue {
return activeQueues.size() == 0 && inactiveQueues.size() == 0;
}
public boolean addTask(final Runnable whenDone) {
public boolean addEmptyTask(final Runnable whenDone) {
if (this.isDone()) {
// Run
this.tasks();
this.runEmptyTasks();
if (whenDone != null) {
whenDone.run();
}
@ -294,19 +298,18 @@ public class GlobalBlockQueue {
return false;
}
public synchronized boolean tasks() {
private synchronized void runEmptyTasks() {
if (this.runnables.isEmpty()) {
return false;
return;
}
final ArrayList<Runnable> tmp = new ArrayList<>(this.runnables);
final ConcurrentLinkedDeque<Runnable> tmp = new ConcurrentLinkedDeque<>(this.runnables);
this.runnables.clear();
for (final Runnable runnable : tmp) {
runnable.run();
}
return true;
}
public enum QueueStage {
INACTIVE, ACTIVE, NONE;
INACTIVE, ACTIVE, NONE
}
}