From cd64ca459d632402c22f851a19e1716cb4125a99 Mon Sep 17 00:00:00 2001 From: aumgn Date: Sun, 22 Apr 2012 17:11:50 +0200 Subject: [PATCH] Add config entries for polygonal region points limit --- .../com/sk89q/worldedit/LocalConfiguration.java | 2 ++ src/main/java/com/sk89q/worldedit/WorldEdit.java | 12 ++++++++++++ .../worldedit/commands/SelectionCommands.java | 6 +++++- .../regions/Polygonal2DRegionSelector.java | 14 ++++++++++++-- .../sk89q/worldedit/util/YAMLConfiguration.java | 4 ++++ src/main/resources/config.yml | 3 +++ 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java index d10ed86ec..570decf20 100644 --- a/src/main/java/com/sk89q/worldedit/LocalConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/LocalConfiguration.java @@ -82,6 +82,8 @@ public abstract class LocalConfiguration { public Set disallowedBlocks = new HashSet(); public int defaultChangeLimit = -1; public int maxChangeLimit = -1; + public int defaultMaxPolygonalPoints = -1; + public int maxPolygonalPoints = 20; public String shellSaveType = ""; public SnapshotRepository snapshotRepo = null; public int maxRadius = -1; diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index 265f9c697..31fa7748d 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -761,6 +761,18 @@ public class WorldEdit { } } + public int getMaximumPolygonalPoints(LocalPlayer player) { + if (player.hasPermission("worldedit.limit.unrestricted") || config.maxPolygonalPoints < 0) { + return config.defaultMaxPolygonalPoints; + } else { + if (config.defaultMaxPolygonalPoints < 0) { + return config.maxPolygonalPoints; + } + return Math.min(config.defaultMaxPolygonalPoints, + config.maxPolygonalPoints); + } + } + /** * Checks to see if the specified radius is within bounds. * diff --git a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java index 9a0f82411..616c3b86c 100644 --- a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java @@ -609,8 +609,12 @@ public class SelectionCommands { selector = new ExtendingCuboidRegionSelector(oldSelector); player.print("Cuboid: left click for a starting point, right click to extend"); } else if (typeName.equalsIgnoreCase("poly")) { - selector = new Polygonal2DRegionSelector(oldSelector); + int maxPoints = we.getMaximumPolygonalPoints(player); + selector = new Polygonal2DRegionSelector(oldSelector, maxPoints); player.print("2D polygon selector: Left/right click to add a point."); + if (maxPoints > -1) { + player.print(maxPoints + " points maximum."); + } } else if (typeName.equalsIgnoreCase("ellipsoid")) { selector = new EllipsoidRegionSelector(oldSelector); player.print("Ellipsoid selector: left click=center, right click to extend"); diff --git a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java index 04aeb6bf6..de0527844 100644 --- a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java @@ -40,15 +40,25 @@ import com.sk89q.worldedit.cui.SelectionShapeEvent; * @author sk89q */ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { + private int maxPoints; private BlockVector pos1; private Polygonal2DRegion region; public Polygonal2DRegionSelector(LocalWorld world) { + this(world, 20); + } + + public Polygonal2DRegionSelector(LocalWorld world, int maxPoints) { + this.maxPoints = maxPoints; region = new Polygonal2DRegion(world); } public Polygonal2DRegionSelector(RegionSelector oldSelector) { - this(oldSelector.getIncompleteRegion().getWorld()); + this(oldSelector, 20); + } + + public Polygonal2DRegionSelector(RegionSelector oldSelector, int maxPoints) { + this(oldSelector.getIncompleteRegion().getWorld(), maxPoints); if (oldSelector instanceof Polygonal2DRegionSelector) { final Polygonal2DRegionSelector polygonal2DRegionSelector = (Polygonal2DRegionSelector) oldSelector; @@ -108,7 +118,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { return false; } - if (points.size() >= 20) { + if (maxPoints > -1 && points.size() >= maxPoints) { return false; } } diff --git a/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java b/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java index 95846d5f3..d9a40da9b 100644 --- a/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java +++ b/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java @@ -65,6 +65,10 @@ public class YAMLConfiguration extends LocalConfiguration { "limits.max-blocks-changed.default", defaultChangeLimit)); maxChangeLimit = Math.max(-1, config.getInt("limits.max-blocks-changed.maximum", maxChangeLimit)); + defaultMaxPolygonalPoints = Math.max(-1, + config.getInt("limits.max-polygonal-points.default", defaultMaxPolygonalPoints)); + maxPolygonalPoints = Math.max(-1, + config.getInt("limits.max-polygonal-points.maximum", maxPolygonalPoints)); maxRadius = Math.max(-1, config.getInt("limits.max-radius", maxRadius)); maxSuperPickaxeSize = Math.max(1, config.getInt( "limits.max-super-pickaxe-size", maxSuperPickaxeSize)); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c8f550fb2..d2756114a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -19,6 +19,9 @@ limits: max-blocks-changed: default: -1 maximum: -1 + max-polygonal-points: + default: -1 + maximum: 20 max-radius: -1 max-super-pickaxe-size: 5 max-brush-radius: 5