From ab659eadded7e5235310ba0f1e828f319cf65da7 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Fri, 19 Aug 2022 13:41:24 +0200 Subject: [PATCH] fix: upstream missing `Region#getBoundingBox()` (#1908) Use block change limit for //copy and //cut (cherry picked from commit fd8dbdd7b7b8b561db98a45b4eae3810dedb1551) --- .../worldedit/command/ClipboardCommands.java | 15 +++++++++++++++ .../com/sk89q/worldedit/regions/CuboidRegion.java | 5 +++++ .../java/com/sk89q/worldedit/regions/Region.java | 9 +++++++++ 3 files changed, 29 insertions(+) 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 258ad965e..0cb9f6798 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 @@ -38,6 +38,7 @@ import com.google.common.collect.Lists; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.util.CommandPermissions; @@ -105,6 +106,20 @@ import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION; @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class ClipboardCommands { + /** + * Throws if the region would allocate a clipboard larger than the block change limit. + * + * @param region The region to check + * @param session The session + * @throws MaxChangedBlocksException if the volume exceeds the limit + */ + private void checkRegionBounds(Region region, LocalSession session) throws MaxChangedBlocksException { + int limit = session.getBlockChangeLimit(); + if (region.getBoundingBox().getVolume() > limit) { + throw new MaxChangedBlocksException(limit); + } + } + @Command( name = "/copy", aliases = "/cp", diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index 26b20cd8c..26f7636f4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -256,6 +256,11 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { return pos1.getMaximum(pos2); } + @Override + public CuboidRegion getBoundingBox() { + return this; + } + @Override public int getMinimumY() { return minY; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java index b0b4e9785..8d718fb05 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -72,6 +72,15 @@ public interface Region extends Iterable, Cloneable, IBatchProcess } //FAWE end + /** + * Get the bounding box of this region as a {@link CuboidRegion}. + * + * @return the bounding box + */ + default CuboidRegion getBoundingBox() { + return new CuboidRegion(getMinimumPoint(), getMaximumPoint()); + } + /** * Get the center point of a region. * Note: Coordinates will not be integers