From f2e26b07ec6f4c43e675a049ea50842b19c45d2c Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 1 Jan 2012 14:08:22 +0100 Subject: [PATCH] Some region selection fixes - CuboidSelection no longer deals with IncompleteRegionExceptions - Fixed Polygonal2DSelection not passing its region to the selector - Fixed Polygonal2DRegion not cloning the list it receives in its constructor - Gave PolygonalRegionSelector a new constructor where it takes a list of points --- .../bukkit/selections/CuboidSelection.java | 15 ++++++++------- .../bukkit/selections/Polygonal2DSelection.java | 10 +++++++--- .../worldedit/regions/Polygonal2DRegion.java | 2 +- .../regions/Polygonal2DRegionSelector.java | 6 ++++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java b/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java index 24ab3ab2c..a3afd3ba7 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/selections/CuboidSelection.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.bukkit.selections; import org.bukkit.Location; import org.bukkit.World; -import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.bukkit.BukkitUtil; import com.sk89q.worldedit.regions.*; @@ -37,6 +36,7 @@ public class CuboidSelection extends RegionSelection { public CuboidSelection(World world, Vector pt1, Vector pt2) { super(world); + // Validate input if (pt1 == null) { throw new IllegalArgumentException("Null point 1 not permitted"); } @@ -44,17 +44,18 @@ public class CuboidSelection extends RegionSelection { if (pt2 == null) { throw new IllegalArgumentException("Null point 2 not permitted"); } - + + // Create new selector CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world)); + + // set up selector sel.selectPrimary(pt1); sel.selectSecondary(pt2); - try { - cuboid = sel.getRegion(); - } catch (IncompleteRegionException e) { - throw new RuntimeException("IncompleteRegionException unexpectedly thrown"); - } + // set up CuboidSelection + cuboid = sel.getIncompleteRegion(); + // set up RegionSelection setRegionSelector(sel); setRegion(cuboid); } diff --git a/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java b/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java index 0a892479a..3ecaaead8 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/selections/Polygonal2DSelection.java @@ -41,13 +41,17 @@ public class Polygonal2DSelection extends RegionSelection { super(world); LocalWorld lWorld = BukkitUtil.getLocalWorld(world); + // Validate input minY = Math.min(Math.max(0, minY), world.getMaxHeight()); maxY = Math.min(Math.max(0, maxY), world.getMaxHeight()); - Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector(BukkitUtil.getLocalWorld(world)); - poly2d = new Polygonal2DRegion(lWorld, points, minY, maxY); - sel.learnChanges(); + // Create and set up new selector + Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector(lWorld, points, minY, maxY); + // set up CuboidSelection + poly2d = sel.getIncompleteRegion(); + + // set up RegionSelection setRegionSelector(sel); setRegion(poly2d); } diff --git a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java index 65bafc16a..561c3f200 100644 --- a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java +++ b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java @@ -76,7 +76,7 @@ public class Polygonal2DRegion implements Region { * @param maxY */ public Polygonal2DRegion(LocalWorld world, List points, int minY, int maxY) { - this.points = points; + this.points = new ArrayList(points); this.minY = minY; this.maxY = maxY; hasY = true; diff --git a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java index 3cceb5809..e15be5961 100644 --- a/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java +++ b/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegionSelector.java @@ -80,6 +80,12 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { } } + public Polygonal2DRegionSelector(LocalWorld world, List points, int minY, int maxY) { + final BlockVector2D pos2D = points.get(0); + pos1 = new BlockVector(pos2D.getX(), minY, pos2D.getZ()); + region = new Polygonal2DRegion(world, points, minY, maxY); + } + public boolean selectPrimary(Vector pos) { if (pos.equals(pos1)) { return false;