From 0fa9d7a4a7a90160fc351a46a1f65fb44b98ecc8 Mon Sep 17 00:00:00 2001 From: IronApollo Date: Wed, 27 Feb 2019 09:01:07 -0500 Subject: [PATCH] Changes to EditSession to improve upstream compatibility --- .../java/com/sk89q/worldedit/EditSession.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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 530793a5e..bd4185b1e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -149,7 +149,7 @@ import static com.sk89q.worldedit.regions.Regions.minimumBlockY; * {@link Extent}s that are chained together. For example, history is logged * using the {@link ChangeSetExtent}.

*/ -public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, SimpleWorld { +public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, SimpleWorld, AutoCloseable { /** * Used by {@link EditSession#setBlock(BlockVector3, BlockStateHolder, Stage)} to * determine which {@link Extent}s should be bypassed. @@ -1262,6 +1262,27 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, public List getEntities() { return this.extent.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. + */ + public void flushSession() { + Operations.completeBlindly(commit()); + } + + @Override + public @Nullable Operation commit() { + return extent.commit(); + } /** * Finish off the queue.