Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-25 18:40:05 +01:00
Make EditSession closeable for easy flushing
Dieser Commit ist enthalten in:
Ursprung
1fa1ff895b
Commit
a3f1c71d97
@ -134,7 +134,7 @@ import javax.annotation.Nullable;
|
||||
* using the {@link ChangeSetExtent}.</p>
|
||||
*/
|
||||
@SuppressWarnings({"FieldCanBeLocal"})
|
||||
public class EditSession implements Extent {
|
||||
public class EditSession implements Extent, AutoCloseable {
|
||||
|
||||
private static final Logger log = Logger.getLogger(EditSession.class.getCanonicalName());
|
||||
|
||||
@ -636,6 +636,14 @@ public class EditSession implements Extent {
|
||||
return bypassNone.getEntities();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closing an EditSession {@linkplain #flushSession() flushes its buffers}.
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
flushSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Communicate to the EditSession that all block changes are complete,
|
||||
* and that it should apply them to the world.
|
||||
|
@ -62,7 +62,7 @@ public class AreaPickaxe implements BlockTool {
|
||||
return true;
|
||||
}
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
try (EditSession editSession = session.createEditSession(player)) {
|
||||
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
|
||||
|
||||
try {
|
||||
@ -83,9 +83,9 @@ public class AreaPickaxe implements BlockTool {
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
editSession.flushSession();
|
||||
session.remember(editSession);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -52,15 +52,16 @@ public class BlockReplacer implements DoubleActionBlockTool {
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
BlockBag bag = session.getBlockBag(player);
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
editSession.disableBuffering();
|
||||
|
||||
try (EditSession editSession = session.createEditSession(player)) {
|
||||
try {
|
||||
editSession.disableBuffering();
|
||||
Vector position = clicked.toVector();
|
||||
editSession.setBlock(position, pattern.apply(position));
|
||||
} catch (MaxChangedBlocksException ignored) {
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
} finally {
|
||||
if (bag != null) {
|
||||
bag.flushChanges();
|
||||
}
|
||||
@ -72,8 +73,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
|
||||
|
||||
@Override
|
||||
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
BlockStateHolder targetBlock = editSession.getBlock(clicked.toVector());
|
||||
BlockStateHolder targetBlock = player.getWorld().getBlock(clicked.toVector());
|
||||
|
||||
if (targetBlock != null) {
|
||||
pattern = new BlockPattern(targetBlock);
|
||||
|
@ -172,7 +172,7 @@ public class BrushTool implements TraceTool {
|
||||
|
||||
BlockBag bag = session.getBlockBag(player);
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
try (EditSession editSession = session.createEditSession(player)) {
|
||||
Request.request().setEditSession(editSession);
|
||||
if (mask != null) {
|
||||
Mask existingMask = editSession.getMask();
|
||||
@ -194,7 +194,8 @@ public class BrushTool implements TraceTool {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
editSession.flushSession();
|
||||
}
|
||||
} finally {
|
||||
if (bag != null) {
|
||||
bag.flushChanges();
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class RecursivePickaxe implements BlockTool {
|
||||
return true;
|
||||
}
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
try (EditSession editSession = session.createEditSession(player)) {
|
||||
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
|
||||
|
||||
try {
|
||||
@ -75,9 +75,9 @@ public class RecursivePickaxe implements BlockTool {
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
editSession.flushSession();
|
||||
session.remember(editSession);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -49,15 +49,11 @@ public class SinglePickaxe implements BlockTool {
|
||||
return true;
|
||||
}
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
try (EditSession editSession = session.createEditSession(player)) {
|
||||
editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop);
|
||||
|
||||
try {
|
||||
editSession.setBlock(clicked.toVector(), BlockTypes.AIR.getDefaultState());
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
editSession.flushSession();
|
||||
}
|
||||
|
||||
world.playEffect(clicked.toVector(), 2001, blockType.getLegacyId());
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren