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
Dieser Commit ist enthalten in:
TomyLobo 2012-01-01 14:08:22 +01:00
Ursprung 3b87953da0
Commit f2e26b07ec
4 geänderte Dateien mit 22 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -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");
}
@ -45,16 +45,17 @@ public class CuboidSelection extends RegionSelection {
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);
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -76,7 +76,7 @@ public class Polygonal2DRegion implements Region {
* @param maxY
*/
public Polygonal2DRegion(LocalWorld world, List<BlockVector2D> points, int minY, int maxY) {
this.points = points;
this.points = new ArrayList<BlockVector2D>(points);
this.minY = minY;
this.maxY = maxY;
hasY = true;

Datei anzeigen

@ -80,6 +80,12 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
}
}
public Polygonal2DRegionSelector(LocalWorld world, List<BlockVector2D> 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;