From 470ba64fe4ee9e8dda701e9713b1083d728c4dae Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 10 Sep 2021 17:46:21 +0100 Subject: [PATCH] Fix #1260 --- .../com/sk89q/worldedit/LocalSession.java | 11 ++++ .../worldedit/command/ClipboardCommands.java | 57 ++++++++++--------- .../com/sk89q/worldedit/entity/Player.java | 2 +- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index 819e6b375..9932993ae 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -838,6 +838,17 @@ public class LocalSession implements TextureHolder { } setClipboard(multi); } + + /** + * Ensure the player's clipboard is closed. (will only do something with clipboard-on-disk) + */ + public void closeClipboard() { + synchronized (clipboardLock) { + if (this.clipboard != null) { + this.clipboard.close(); + } + } + } //FAWE end /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 493e11e94..ca515d29e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -139,37 +139,38 @@ public class ClipboardCommands { } session.setClipboard(null); - Clipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId()); + try (Clipboard clipboard = new BlockArrayClipboard(region, actor.getUniqueId())) { - clipboard.setOrigin(centerClipboard ? region.getCenter().toBlockPoint() : session.getPlacementPosition(actor)); - ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); - copy.setCopyingEntities(copyEntities); - copy.setCopyingBiomes(copyBiomes); + clipboard.setOrigin(centerClipboard ? region.getCenter().toBlockPoint() : session.getPlacementPosition(actor)); + ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); + copy.setCopyingEntities(copyEntities); + copy.setCopyingBiomes(copyBiomes); - Mask sourceMask = editSession.getSourceMask(); - Region[] regions = editSession.getAllowedRegions(); - Region allowedRegion; - if (regions == null || regions.length == 0) { - allowedRegion = new NullRegion(); - } else { - allowedRegion = new RegionIntersection(regions); + Mask sourceMask = editSession.getSourceMask(); + Region[] regions = editSession.getAllowedRegions(); + Region allowedRegion; + if (regions == null || regions.length == 0) { + allowedRegion = new NullRegion(); + } else { + allowedRegion = new RegionIntersection(regions); + } + final Mask firstSourceMask = mask != null ? mask : sourceMask; + final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize(); + if (finalMask != Masks.alwaysTrue()) { + copy.setSourceMask(finalMask); + } + if (sourceMask != null) { + editSession.setSourceMask(null); + new MaskTraverser(sourceMask).reset(editSession); + editSession.setSourceMask(null); + } + + Operations.completeLegacy(copy); + saveDiskClipboard(clipboard); + session.setClipboard(new ClipboardHolder(clipboard)); + + copy.getStatusMessages().forEach(actor::print); } - final Mask firstSourceMask = mask != null ? mask : sourceMask; - final Mask finalMask = MaskIntersection.of(firstSourceMask, new RegionMask(allowedRegion)).optimize(); - if (finalMask != Masks.alwaysTrue()) { - copy.setSourceMask(finalMask); - } - if (sourceMask != null) { - editSession.setSourceMask(null); - new MaskTraverser(sourceMask).reset(editSession); - editSession.setSourceMask(null); - } - - Operations.completeLegacy(copy); - saveDiskClipboard(clipboard); - session.setClipboard(new ClipboardHolder(clipboard)); - - copy.getStatusMessages().forEach(actor::print); //FAWE end } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java index e0380bfc9..87e1f518b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java @@ -391,7 +391,7 @@ public interface Player extends Entity, Actor { */ default void unregister() { cancel(true); - getSession().setClipboard(null); + getSession().closeClipboard(); if (Settings.IMP.HISTORY.DELETE_ON_LOGOUT) { getSession().clearHistory(); }