From b3f5bc030ed343fcddefa9406956f2c8604d5e22 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Thu, 15 Nov 2018 19:18:22 +1000 Subject: [PATCH] Few fixes for FastModeExtent. --- .../java/com/sk89q/worldedit/EditSession.java | 3 +++ .../worldedit/extent/world/FastModeExtent.java | 17 +++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index fad8c8850..5088a2bdf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -246,6 +246,9 @@ public class EditSession implements Extent, AutoCloseable { if (isBatchingChunks() && chunkBatchingExtent.commitRequired()) { return true; } + if (hasFastMode() && fastModeExtent.commitRequired()) { + return true; + } return false; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java index 37f524ad0..9ca43b63f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java @@ -31,10 +31,9 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; -import java.util.ArrayDeque; import java.util.HashSet; +import java.util.Iterator; import java.util.List; -import java.util.Queue; import java.util.Set; /** @@ -43,7 +42,7 @@ import java.util.Set; public class FastModeExtent extends AbstractDelegateExtent { private final World world; - private final Queue positions = new ArrayDeque<>(); + private final Set positions = new HashSet<>(); private final Set dirtyChunks = new HashSet<>(); private boolean enabled = true; private boolean postEditSimulation; @@ -106,7 +105,7 @@ public class FastModeExtent extends AbstractDelegateExtent { if (world.setBlock(location, block, false)) { if (postEditSimulation) { - positions.offer(location); + positions.add(location); } return true; } @@ -117,6 +116,10 @@ public class FastModeExtent extends AbstractDelegateExtent { } } + public boolean commitRequired() { + return !dirtyChunks.isEmpty() || !positions.isEmpty(); + } + @Override protected Operation commitBefore() { return new Operation() { @@ -127,9 +130,11 @@ public class FastModeExtent extends AbstractDelegateExtent { } if (postEditSimulation) { - while (run.shouldContinue() && !positions.isEmpty()) { - BlockVector3 position = positions.poll(); // Remove from queue + Iterator positionIterator = positions.iterator(); + while (run.shouldContinue() && positionIterator.hasNext()) { + BlockVector3 position = positionIterator.next(); world.notifyAndLightBlock(position, BlockTypes.AIR.getDefaultState()); + positionIterator.remove(); } return !positions.isEmpty() ? this : null;