From 41de2041864f35c2b439d53d69b5ebe452fe7095 Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 19 Mar 2017 11:56:04 -0400 Subject: [PATCH] Allow copyEntities to be used in ForwardExtentCopy again. The -e flag should now work for //copy and //cut as it used to. Fixes WORLDEDIT-3557. --- .../worldedit/command/ClipboardCommands.java | 8 +++-- .../function/operation/ForwardExtentCopy.java | 35 +++++++++++++++---- 2 files changed, 34 insertions(+), 9 deletions(-) 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 ab6a294cd..9d7cb265a 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 @@ -70,7 +70,7 @@ public class ClipboardCommands { desc = "Copy the selection to the clipboard", help = "Copy the selection to the clipboard\n" + "Flags:\n" + - " -e controls whether entities are copied\n" + + " -e will also copy entities\n" + " -m sets a source mask so that excluded blocks become air\n" + "WARNING: Pasting entities cannot yet be undone!", min = 0, @@ -84,6 +84,7 @@ public class ClipboardCommands { BlockArrayClipboard clipboard = new BlockArrayClipboard(region); clipboard.setOrigin(session.getPlacementPosition(player)); ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); + copy.setCopyingEntities(copyEntities); if (mask != null) { copy.setSourceMask(mask); } @@ -100,10 +101,9 @@ public class ClipboardCommands { desc = "Cut the selection to the clipboard", help = "Copy the selection to the clipboard\n" + "Flags:\n" + - " -e controls whether entities are copied\n" + + " -e will also cut entities\n" + " -m sets a source mask so that excluded blocks become air\n" + "WARNING: Cutting and pasting entities cannot yet be undone!", - min = 0, max = 1 ) @CommandPermissions("worldedit.clipboard.cut") @@ -116,6 +116,8 @@ public class ClipboardCommands { clipboard.setOrigin(session.getPlacementPosition(player)); ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); copy.setSourceFunction(new BlockReplace(editSession, leavePattern)); + copy.setCopyingEntities(copyEntities); + copy.setRemovingEntities(true); if (mask != null) { copy.setSourceMask(mask); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index b1fafe611..3883ec5b4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -58,6 +58,7 @@ public class ForwardExtentCopy implements Operation { private int repetitions = 1; private Mask sourceMask = Masks.alwaysTrue(); private boolean removingEntities; + private boolean copyingEntities = true; // default to true for backwards compatibility, sort of private RegionFunction sourceFunction = null; private Transform transform = new Identity(); private Transform currentTransform = null; @@ -183,6 +184,24 @@ public class ForwardExtentCopy implements Operation { this.repetitions = repetitions; } + /** + * Return whether entities should be copied along with blocks. + * + * @return true if copying + */ + public boolean isCopyingEntities() { + return copyingEntities; + } + + /** + * Set whether entities should be copied along with blocks. + * + * @param copyingEntities true if copying + */ + public void setCopyingEntities(boolean copyingEntities) { + this.copyingEntities = copyingEntities; + } + /** * Return whether entities that are copied should be removed. * @@ -229,14 +248,18 @@ public class ForwardExtentCopy implements Operation { RegionFunction function = sourceFunction != null ? new CombinedRegionFunction(filter, sourceFunction) : filter; RegionVisitor blockVisitor = new RegionVisitor(region, function); - ExtentEntityCopy entityCopy = new ExtentEntityCopy(from, destination, to, currentTransform); - entityCopy.setRemoving(removingEntities); - List entities = source.getEntities(region); - EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy); - lastVisitor = blockVisitor; currentTransform = currentTransform.combine(transform); - return new DelegateOperation(this, new OperationQueue(blockVisitor, entityVisitor)); + + if (copyingEntities) { + ExtentEntityCopy entityCopy = new ExtentEntityCopy(from, destination, to, currentTransform); + entityCopy.setRemoving(removingEntities); + List entities = source.getEntities(region); + EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy); + return new DelegateOperation(this, new OperationQueue(blockVisitor, entityVisitor)); + } else { + return new DelegateOperation(this, blockVisitor); + } } else { return null; }