From 65c0d77d3e87099ca9abdf07034005a02c13c1a7 Mon Sep 17 00:00:00 2001 From: Redecouverte Date: Sun, 27 Feb 2011 18:16:09 +0100 Subject: [PATCH] updated protection classes for getIntersectingRegions() --- .../regionmanager/FlatRegionManager.java | 37 ++++++++++--------- .../regionmanager/PRTreeRegionManager.java | 36 +++++++++--------- .../regions/ProtectedCuboidRegion.java | 18 +++++---- .../regions/ProtectedPolygonalRegion.java | 21 +++-------- .../protection/regions/ProtectedRegion.java | 13 ++----- 5 files changed, 59 insertions(+), 66 deletions(-) diff --git a/src/com/sk89q/worldguard/protection/regionmanager/FlatRegionManager.java b/src/com/sk89q/worldguard/protection/regionmanager/FlatRegionManager.java index c6dd8005..f5030ef4 100644 --- a/src/com/sk89q/worldguard/protection/regionmanager/FlatRegionManager.java +++ b/src/com/sk89q/worldguard/protection/regionmanager/FlatRegionManager.java @@ -149,17 +149,16 @@ public ApplicableRegionSet getApplicableRegions(Vector pt) { public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) { List appRegions = new ArrayList(); + appRegions.addAll(regions.values()); - for (ProtectedRegion region : regions.values()) { - try { - if (region.intersectsWith(checkRegion)) { - appRegions.add(region); - } - } catch (UnsupportedIntersectionException ex) { - } + List intersectRegions; + try { + intersectRegions = checkRegion.getIntersectingRegions(appRegions); + } catch (Exception e) { + intersectRegions = new ArrayList(); } - return new ApplicableRegionSet(appRegions, global); + return new ApplicableRegionSet(intersectRegions, global); } /** @@ -188,22 +187,26 @@ public List getApplicableRegionsIDs(Vector pt) { * @param player * @return */ - public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player) { + public boolean overlapsUnownedRegion(ProtectedRegion checkRegion, LocalPlayer player) { + + List appRegions = new ArrayList(); + for (ProtectedRegion other : regions.values()) { if (other.getOwners().contains(player)) { continue; } - try { - if (region.intersectsWith(other)) { - return true; - } - } catch (UnsupportedIntersectionException e) { - // TODO: Maybe do something here - } + appRegions.add(other); } - return false; + List intersectRegions; + try { + intersectRegions = checkRegion.getIntersectingRegions(appRegions); + } catch (Exception e) { + intersectRegions = new ArrayList(); + } + + return intersectRegions.size() > 0; } /** diff --git a/src/com/sk89q/worldguard/protection/regionmanager/PRTreeRegionManager.java b/src/com/sk89q/worldguard/protection/regionmanager/PRTreeRegionManager.java index 63637baf..60af0097 100644 --- a/src/com/sk89q/worldguard/protection/regionmanager/PRTreeRegionManager.java +++ b/src/com/sk89q/worldguard/protection/regionmanager/PRTreeRegionManager.java @@ -157,17 +157,16 @@ public ApplicableRegionSet getApplicableRegions(Vector pt) { public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) { List appRegions = new ArrayList(); + appRegions.addAll(regions.values()); - for (ProtectedRegion region : regions.values()) { - try { - if (region.intersectsWith(checkRegion)) { - appRegions.add(region); - } - } catch (UnsupportedIntersectionException ex) { - } + List intersectRegions; + try { + intersectRegions = checkRegion.getIntersectingRegions(appRegions); + } catch (Exception e) { + intersectRegions = new ArrayList(); } - return new ApplicableRegionSet(appRegions, global); + return new ApplicableRegionSet(intersectRegions, global); } /** @@ -199,22 +198,25 @@ public List getApplicableRegionsIDs(Vector pt) { * @param player * @return */ - public boolean overlapsUnownedRegion(ProtectedRegion region, LocalPlayer player) { + public boolean overlapsUnownedRegion(ProtectedRegion checkRegion, LocalPlayer player) { + List appRegions = new ArrayList(); + for (ProtectedRegion other : regions.values()) { if (other.getOwners().contains(player)) { continue; } - try { - if (region.intersectsWith(other)) { - return true; - } - } catch (UnsupportedIntersectionException e) { - // TODO: Maybe do something here - } + appRegions.add(other); } - return false; + List intersectRegions; + try { + intersectRegions = checkRegion.getIntersectingRegions(appRegions); + } catch (Exception e) { + intersectRegions = new ArrayList(); + } + + return intersectRegions.size() > 0; } /** diff --git a/src/com/sk89q/worldguard/protection/regions/ProtectedCuboidRegion.java b/src/com/sk89q/worldguard/protection/regions/ProtectedCuboidRegion.java index e01ae518..884271c4 100644 --- a/src/com/sk89q/worldguard/protection/regions/ProtectedCuboidRegion.java +++ b/src/com/sk89q/worldguard/protection/regions/ProtectedCuboidRegion.java @@ -20,6 +20,7 @@ import com.sk89q.worldedit.*; import com.sk89q.worldguard.protection.UnsupportedIntersectionException; +import java.util.List; /** * Represents a cuboid region that can be protected. @@ -100,13 +101,8 @@ public boolean contains(Vector pt) { && z >= min.getBlockZ() && z <= max.getBlockZ(); } - /** - * Checks if two region intersects. - * - * @param region - * @throws UnsupportedIntersectionException - * @return - */ + + /* public boolean intersectsWith(ProtectedRegion region) throws UnsupportedIntersectionException { if (region instanceof ProtectedCuboidRegion) { @@ -129,6 +125,12 @@ public boolean intersectsWith(ProtectedRegion region) throws UnsupportedIntersec throw new UnsupportedIntersectionException(); } } + */ + + public List getIntersectingRegions(List regions) throws UnsupportedIntersectionException { + throw new UnsupportedOperationException("Not supported yet."); + } + /** * Return the type of region as a user-friendly name. @@ -152,4 +154,6 @@ public int countBlocks() { int volume = xLength * yLength * zLength; return volume; } + + } diff --git a/src/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java b/src/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java index c1c3d7a2..a493bdc0 100644 --- a/src/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java +++ b/src/com/sk89q/worldguard/protection/regions/ProtectedPolygonalRegion.java @@ -131,24 +131,13 @@ public boolean contains(Vector pt) { return inside; } - /** - * Checks if two region intersects. - * - * @param region - * @throws UnsupportedIntersectionException - * @return - */ - public boolean intersectsWith(ProtectedRegion region) throws UnsupportedIntersectionException { - - if (region instanceof ProtectedCuboidRegion) { - throw new UnsupportedIntersectionException(); - } else if (region instanceof ProtectedPolygonalRegion) { - throw new UnsupportedIntersectionException(); - } else { - throw new UnsupportedIntersectionException(); - } + + + public List getIntersectingRegions(List regions) throws UnsupportedIntersectionException { + throw new UnsupportedOperationException("Not supported yet."); } + /** * Return the type of region as a user-friendly name. * diff --git a/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java b/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java index e339df84..f2320deb 100644 --- a/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java +++ b/src/com/sk89q/worldguard/protection/regions/ProtectedRegion.java @@ -24,6 +24,7 @@ import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.domains.DefaultDomain; import com.sk89q.worldguard.protection.UnsupportedIntersectionException; +import java.util.List; /** * Represents a region of any shape and size that can be protected. @@ -298,15 +299,9 @@ public int compareTo(ProtectedRegion other) { */ public abstract String getTypeName(); - /** - * Checks if two region intersects. - * - * @param region - * @throws UnsupportedIntersectionException - * @return - */ - public abstract boolean intersectsWith(ProtectedRegion region) throws UnsupportedIntersectionException; - + + public abstract List getIntersectingRegions(List regions) throws UnsupportedIntersectionException; + /** * Thrown when setting a parent would create a circular inheritance