From c804aeb03efbda42193953f9df7d2624d571c313 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 29 Mar 2014 18:34:34 -0700 Subject: [PATCH] Make FlatRegionVisitor take FlatRegions only. --- .../java/com/sk89q/worldedit/EditSession.java | 4 ++-- .../worldedit/commands/RegionCommands.java | 4 ++-- .../function/visitor/FlatRegionVisitor.java | 24 +++++++++++-------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index cd7778c4f..1f49bd86a 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -1162,7 +1162,7 @@ public class EditSession { RegionOffset offset = new RegionOffset(new Vector(0, 1, 0), replace); GroundSearch search = new MaskingGroundSearch(this, new ExistingBlockMask()); GroundFunction groundFunction = new GroundFunction(search, lowerY, upperY, offset); - FlatRegionVisitor operation = new FlatRegionVisitor(region, groundFunction); + FlatRegionVisitor operation = new FlatRegionVisitor(Regions.asFlatRegion(region), groundFunction); OperationHelper.completeLegacy(operation); return operation.getAffected(); @@ -1966,7 +1966,7 @@ public class EditSession { FlatRegionMaskingFilter filter = new FlatRegionMaskingFilter(this, mask, groundFunction); // Generate those patches! - FlatRegionVisitor operation = new FlatRegionVisitor(region, filter); + FlatRegionVisitor operation = new FlatRegionVisitor(Regions.asFlatRegion(region), filter); OperationHelper.completeLegacy(operation); return operation.getAffected(); diff --git a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java index 15572c813..01a6ad7b1 100644 --- a/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/RegionCommands.java @@ -561,7 +561,7 @@ public class RegionCommands { FlatRegionMaskingFilter filter = new FlatRegionMaskingFilter(editSession, mask, groundFunction); // Execute - FlatRegionVisitor operation = new FlatRegionVisitor(region, filter); + FlatRegionVisitor operation = new FlatRegionVisitor(Regions.asFlatRegion(region), filter); OperationHelper.complete(operation); player.print(operation.getAffected() + " trees created."); @@ -591,7 +591,7 @@ public class RegionCommands { FlatRegionMaskingFilter filter = new FlatRegionMaskingFilter(editSession, mask, groundFunction); // Execute - FlatRegionVisitor operation = new FlatRegionVisitor(region, filter); + FlatRegionVisitor operation = new FlatRegionVisitor(Regions.asFlatRegion(region), filter); OperationHelper.complete(operation); player.print(operation.getAffected() + " flora created."); diff --git a/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java b/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java index 33a7dbb81..546dc0f2b 100644 --- a/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java +++ b/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java @@ -23,12 +23,12 @@ import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.FlatRegionFunction; import com.sk89q.worldedit.function.operation.Operation; -import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.FlatRegion; -import com.sk89q.worldedit.regions.Region; + +import static com.google.common.base.Preconditions.checkNotNull; /** - * Utility class to apply region functions to {@link com.sk89q.worldedit.regions.Region}. + * Applies region functions to columns in a {@link FlatRegion}. */ public class FlatRegionVisitor implements Operation { @@ -36,14 +36,18 @@ public class FlatRegionVisitor implements Operation { private final FlatRegionFunction function; private int affected = 0; - public FlatRegionVisitor(Region region, FlatRegionFunction function) { - this.function = function; + /** + * Create a new visitor. + * + * @param flatRegion a flat region + * @param function a function to apply to columns + */ + public FlatRegionVisitor(FlatRegion flatRegion, FlatRegionFunction function) { + checkNotNull(flatRegion); + checkNotNull(function); - if (region instanceof FlatRegion) { - flatRegion = (FlatRegion) region; - } else { - flatRegion = CuboidRegion.makeCuboid(region); - } + this.flatRegion = flatRegion; + this.function = function; } /**