3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-26 02:50:06 +01:00

Merge pull request #433 from sk89q/bugfix/flushing-when-done

Flush or disable buffers in tools
Dieser Commit ist enthalten in:
Matthew Miller 2018-10-21 12:57:13 +10:00 committet von GitHub
Commit 93a696455f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
10 geänderte Dateien mit 113 neuen und 76 gelöschten Zeilen

Datei anzeigen

@ -285,7 +285,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer); LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);
session.remember(editSession); session.remember(editSession);
editSession.flushQueue(); editSession.flushSession();
WorldEdit.getInstance().flushBlockBag(wePlayer, editSession); WorldEdit.getInstance().flushBlockBag(wePlayer, editSession);
} }

Datei anzeigen

@ -134,7 +134,7 @@ import javax.annotation.Nullable;
* using the {@link ChangeSetExtent}.</p> * using the {@link ChangeSetExtent}.</p>
*/ */
@SuppressWarnings({"FieldCanBeLocal"}) @SuppressWarnings({"FieldCanBeLocal"})
public class EditSession implements Extent { public class EditSession implements Extent, AutoCloseable {
private static final Logger log = Logger.getLogger(EditSession.class.getCanonicalName()); private static final Logger log = Logger.getLogger(EditSession.class.getCanonicalName());
@ -298,13 +298,13 @@ public class EditSession implements Extent {
} }
/** /**
* Disable the queue. This will flush the queue. * Disable the queue. This will {@linkplain #flushSession() flush the session}.
*/ */
public void disableQueue() { public void disableQueue() {
if (isQueueEnabled()) { if (isQueueEnabled()) {
flushQueue(); flushSession();
} }
reorderExtent.setEnabled(true); reorderExtent.setEnabled(false);
} }
/** /**
@ -393,10 +393,21 @@ public class EditSession implements Extent {
return blockBagExtent.popMissing(); return blockBagExtent.popMissing();
} }
/**
* Returns chunk batching status.
*
* @return whether chunk batching is enabled
*/
public boolean isBatchingChunks() { public boolean isBatchingChunks() {
return chunkBatchingExtent != null && chunkBatchingExtent.isEnabled(); return chunkBatchingExtent != null && chunkBatchingExtent.isEnabled();
} }
/**
* Enable or disable chunk batching. Disabling will
* {@linkplain #flushSession() flush the session}.
*
* @param batchingChunks {@code true} to enable, {@code false} to disable
*/
public void setBatchingChunks(boolean batchingChunks) { public void setBatchingChunks(boolean batchingChunks) {
if (chunkBatchingExtent == null) { if (chunkBatchingExtent == null) {
if (batchingChunks) { if (batchingChunks) {
@ -404,12 +415,30 @@ public class EditSession implements Extent {
} }
return; return;
} }
if (!batchingChunks) { if (!batchingChunks && isBatchingChunks()) {
flushQueue(); flushSession();
} }
chunkBatchingExtent.setEnabled(batchingChunks); chunkBatchingExtent.setEnabled(batchingChunks);
} }
/**
* Disable all buffering extents.
*
* @see #disableQueue()
* @see #setBatchingChunks(boolean)
*/
public void disableBuffering() {
// We optimize here to avoid repeated calls to flushSession.
boolean needsFlush = isQueueEnabled() || isBatchingChunks();
if (needsFlush) {
flushSession();
}
reorderExtent.setEnabled(false);
if (chunkBatchingExtent != null) {
chunkBatchingExtent.setEnabled(false);
}
}
/** /**
* Get the number of blocks changed, including repeated block changes. * Get the number of blocks changed, including repeated block changes.
* *
@ -569,7 +598,7 @@ public class EditSession implements Extent {
UndoContext context = new UndoContext(); UndoContext context = new UndoContext();
context.setExtent(editSession.bypassHistory); context.setExtent(editSession.bypassHistory);
Operations.completeBlindly(ChangeSetExecutor.createUndo(changeSet, context)); Operations.completeBlindly(ChangeSetExecutor.createUndo(changeSet, context));
editSession.flushQueue(); editSession.flushSession();
} }
/** /**
@ -581,7 +610,7 @@ public class EditSession implements Extent {
UndoContext context = new UndoContext(); UndoContext context = new UndoContext();
context.setExtent(editSession.bypassHistory); context.setExtent(editSession.bypassHistory);
Operations.completeBlindly(ChangeSetExecutor.createRedo(changeSet, context)); Operations.completeBlindly(ChangeSetExecutor.createRedo(changeSet, context));
editSession.flushQueue(); editSession.flushSession();
} }
/** /**
@ -614,9 +643,18 @@ public class EditSession implements Extent {
} }
/** /**
* Finish off the queue. * Closing an EditSession {@linkplain #flushSession() flushes its buffers}.
*/ */
public void flushQueue() { @Override
public void close() {
flushSession();
}
/**
* Communicate to the EditSession that all block changes are complete,
* and that it should apply them to the world.
*/
public void flushSession() {
Operations.completeBlindly(commit()); Operations.completeBlindly(commit());
} }

Datei anzeigen

@ -628,7 +628,7 @@ public class WorldEdit {
logger.log(Level.WARNING, "Failed to execute script", e); logger.log(Level.WARNING, "Failed to execute script", e);
} finally { } finally {
for (EditSession editSession : scriptContext.getEditSessions()) { for (EditSession editSession : scriptContext.getEditSessions()) {
editSession.flushQueue(); editSession.flushSession();
session.remember(editSession); session.remember(editSession);
} }
} }

Datei anzeigen

@ -460,7 +460,7 @@ public class UtilityCommands {
if (editSession != null) { if (editSession != null) {
session.remember(editSession); session.remember(editSession);
editSession.flushQueue(); editSession.flushSession();
} }
} }
@ -520,7 +520,7 @@ public class UtilityCommands {
if (editSession != null) { if (editSession != null) {
session.remember(editSession); session.remember(editSession);
editSession.flushQueue(); editSession.flushSession();
} }
} }

Datei anzeigen

@ -62,7 +62,7 @@ public class AreaPickaxe implements BlockTool {
return true; return true;
} }
EditSession editSession = session.createEditSession(player); try (EditSession editSession = session.createEditSession(player)) {
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop); editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
try { try {
@ -83,9 +83,9 @@ public class AreaPickaxe implements BlockTool {
} catch (MaxChangedBlocksException e) { } catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached."); player.printError("Max blocks change limit reached.");
} finally { } finally {
editSession.flushQueue();
session.remember(editSession); session.remember(editSession);
} }
}
return true; return true;
} }

Datei anzeigen

@ -52,17 +52,19 @@ public class BlockReplacer implements DoubleActionBlockTool {
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
BlockBag bag = session.getBlockBag(player); BlockBag bag = session.getBlockBag(player);
EditSession editSession = session.createEditSession(player); try (EditSession editSession = session.createEditSession(player)) {
try { try {
editSession.disableBuffering();
Vector position = clicked.toVector(); Vector position = clicked.toVector();
editSession.setBlock(position, pattern.apply(position)); editSession.setBlock(position, pattern.apply(position));
} catch (MaxChangedBlocksException ignored) { } catch (MaxChangedBlocksException ignored) {
} finally {
session.remember(editSession);
}
} finally { } finally {
if (bag != null) { if (bag != null) {
bag.flushChanges(); bag.flushChanges();
} }
session.remember(editSession);
} }
return true; return true;
@ -71,8 +73,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
@Override @Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
EditSession editSession = session.createEditSession(player); BlockStateHolder targetBlock = player.getWorld().getBlock(clicked.toVector());
BlockStateHolder targetBlock = editSession.getBlock(clicked.toVector());
if (targetBlock != null) { if (targetBlock != null) {
pattern = new BlockPattern(targetBlock); pattern = new BlockPattern(targetBlock);

Datei anzeigen

@ -172,7 +172,7 @@ public class BrushTool implements TraceTool {
BlockBag bag = session.getBlockBag(player); BlockBag bag = session.getBlockBag(player);
EditSession editSession = session.createEditSession(player); try (EditSession editSession = session.createEditSession(player)) {
Request.request().setEditSession(editSession); Request.request().setEditSession(editSession);
if (mask != null) { if (mask != null) {
Mask existingMask = editSession.getMask(); Mask existingMask = editSession.getMask();
@ -192,11 +192,13 @@ public class BrushTool implements TraceTool {
brush.build(editSession, target.toVector(), material, size); brush.build(editSession, target.toVector(), material, size);
} catch (MaxChangedBlocksException e) { } catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached."); player.printError("Max blocks change limit reached.");
} finally {
session.remember(editSession);
}
} finally { } finally {
if (bag != null) { if (bag != null) {
bag.flushChanges(); bag.flushChanges();
} }
session.remember(editSession);
} }
return true; return true;

Datei anzeigen

@ -66,7 +66,7 @@ public class RecursivePickaxe implements BlockTool {
return true; return true;
} }
EditSession editSession = session.createEditSession(player); try (EditSession editSession = session.createEditSession(player)) {
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop); editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
try { try {
@ -75,9 +75,9 @@ public class RecursivePickaxe implements BlockTool {
} catch (MaxChangedBlocksException e) { } catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached."); player.printError("Max blocks change limit reached.");
} finally { } finally {
editSession.flushQueue();
session.remember(editSession); session.remember(editSession);
} }
}
return true; return true;
} }

Datei anzeigen

@ -49,15 +49,11 @@ public class SinglePickaxe implements BlockTool {
return true; return true;
} }
EditSession editSession = session.createEditSession(player); try (EditSession editSession = session.createEditSession(player)) {
editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop); editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop);
try {
editSession.setBlock(clicked.toVector(), BlockTypes.AIR.getDefaultState()); editSession.setBlock(clicked.toVector(), BlockTypes.AIR.getDefaultState());
} catch (MaxChangedBlocksException e) { } catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached."); player.printError("Max blocks change limit reached.");
} finally {
editSession.flushQueue();
} }
world.playEffect(clicked.toVector(), 2001, blockType.getLegacyId()); world.playEffect(clicked.toVector(), 2001, blockType.getLegacyId());

Datei anzeigen

@ -316,7 +316,7 @@ public final class CommandManager {
if (editSession != null) { if (editSession != null) {
session.remember(editSession); session.remember(editSession);
editSession.flushQueue(); editSession.flushSession();
if (config.profile) { if (config.profile) {
long time = System.currentTimeMillis() - start; long time = System.currentTimeMillis() - start;