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

View file

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

View file

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

View file

@ -158,7 +158,7 @@ import java.util.zip.ZipOutputStream;
setup.step = new ConfigurationNode[0]; setup.step = new ConfigurationNode[0];
setup.world = world; setup.world = world;
SetupUtils.manager.setupWorld(setup); SetupUtils.manager.setupWorld(setup);
GlobalBlockQueue.IMP.addTask(() -> { GlobalBlockQueue.IMP.addEmptyTask(() -> {
MainUtil.sendMessage(player, "Done!"); MainUtil.sendMessage(player, "Done!");
player.teleport(WorldUtil.IMP.getSpawn(world)); 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) { @Override public boolean unClaimPlot(Plot plot, Runnable whenDone) {
setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING); setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING);
setWall(plot.getId(), classicPlotWorld.WALL_BLOCK); setWall(plot.getId(), classicPlotWorld.WALL_BLOCK);
return GlobalBlockQueue.IMP.addTask(whenDone); return GlobalBlockQueue.IMP.addEmptyTask(whenDone);
} }
public boolean setFloor(PlotId plotId, BlockBucket blocks) { public boolean setFloor(PlotId plotId, BlockBucket blocks) {

View file

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

View file

@ -223,7 +223,7 @@ public abstract class HybridUtils {
PlotSquared.debug("&d - Potentially skipping 1024 chunks"); PlotSquared.debug("&d - Potentially skipping 1024 chunks");
PlotSquared.debug("&d - TODO: recommend chunkster if corrupt"); 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); manager.claimPlot(current);
} }
} }
GlobalBlockQueue.IMP.addTask(run); GlobalBlockQueue.IMP.addEmptyTask(run);
return; return;
} }
Plot current = queue.poll(); Plot current = queue.poll();
@ -982,7 +982,7 @@ public class Plot {
current.setMerged(merged); current.setMerged(merged);
} }
if (createSign) { if (createSign) {
GlobalBlockQueue.IMP.addTask(() -> { GlobalBlockQueue.IMP.addEmptyTask(() -> {
for (Plot current : plots) { for (Plot current : plots) {
current.setSign(MainUtil.getName(current.owner)); current.setSign(MainUtil.getName(current.owner));
} }

View file

@ -8,7 +8,6 @@ import java.util.ArrayList;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Vector;
import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -21,8 +20,10 @@ public class GlobalBlockQueue {
private final ConcurrentLinkedDeque<Runnable> runnables; private final ConcurrentLinkedDeque<Runnable> runnables;
private final AtomicBoolean running; private final AtomicBoolean running;
private QueueProvider provider; 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 last;
private long secondLast; private long secondLast;
@ -35,11 +36,12 @@ public class GlobalBlockQueue {
if (!more) { if (!more) {
lastSuccess = last; lastSuccess = last;
if (inactiveQueues.size() == 0 && activeQueues.size() == 0) { if (inactiveQueues.size() == 0 && activeQueues.size() == 0) {
tasks(); runEmptyTasks();
} }
return; 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() { @Override public void run() {
if (inactiveQueues.isEmpty() && activeQueues.isEmpty()) { if (inactiveQueues.isEmpty() && activeQueues.isEmpty()) {
lastSuccess = System.currentTimeMillis(); lastSuccess = System.currentTimeMillis();
GlobalBlockQueue.this.tasks(); GlobalBlockQueue.this.runEmptyTasks();
return; 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()); GlobalBlockQueue.this.secondLast - System.currentTimeMillis());
SET_TASK.value2 = GlobalBlockQueue.this.getNextQueue(); SET_TASK.value2 = GlobalBlockQueue.this.getNextQueue();
if (SET_TASK.value2 == null) { if (SET_TASK.value2 == null) {
@ -231,7 +235,7 @@ public class GlobalBlockQueue {
public LocalBlockQueue getNextQueue() { public LocalBlockQueue getNextQueue() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
while (activeQueues.size() > 0) { while (!activeQueues.isEmpty()) {
LocalBlockQueue queue = activeQueues.peek(); LocalBlockQueue queue = activeQueues.peek();
if (queue != null && queue.size() > 0) { if (queue != null && queue.size() > 0) {
queue.setModified(now); queue.setModified(now);
@ -251,7 +255,7 @@ public class GlobalBlockQueue {
long age = now - queue.getModified(); long age = now - queue.getModified();
total += queue.size(); total += queue.size();
if (queue.size() == 0) { if (queue.size() == 0) {
if (age > 1000) { if (age > 60000) {
iter.remove(); iter.remove();
} }
continue; continue;
@ -263,7 +267,7 @@ public class GlobalBlockQueue {
firstNonEmpty.setModified(now); firstNonEmpty.setModified(now);
return firstNonEmpty; return firstNonEmpty;
} }
if (age > 60000) { if (age > 1000) {
queue.setModified(now); queue.setModified(now);
return queue; return queue;
} }
@ -279,10 +283,10 @@ public class GlobalBlockQueue {
return activeQueues.size() == 0 && inactiveQueues.size() == 0; return activeQueues.size() == 0 && inactiveQueues.size() == 0;
} }
public boolean addTask(final Runnable whenDone) { public boolean addEmptyTask(final Runnable whenDone) {
if (this.isDone()) { if (this.isDone()) {
// Run // Run
this.tasks(); this.runEmptyTasks();
if (whenDone != null) { if (whenDone != null) {
whenDone.run(); whenDone.run();
} }
@ -294,19 +298,18 @@ public class GlobalBlockQueue {
return false; return false;
} }
public synchronized boolean tasks() { private synchronized void runEmptyTasks() {
if (this.runnables.isEmpty()) { 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(); this.runnables.clear();
for (final Runnable runnable : tmp) { for (final Runnable runnable : tmp) {
runnable.run(); runnable.run();
} }
return true;
} }
public enum QueueStage { public enum QueueStage {
INACTIVE, ACTIVE, NONE; INACTIVE, ACTIVE, NONE
} }
} }