From 43489ca0871239aedbf51f8d1ad24adfd4b55923 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 12 Feb 2011 15:49:55 -0800 Subject: [PATCH] Changed how ApplicableRegionSet iterated over the region set, allowing it to be reused. --- .../worldguard/protection/ApplicableRegionSet.java | 13 ++++++++----- .../worldguard/protection/FlatRegionManager.java | 6 +++--- .../worldguard/protection/ProtectedRegion.java | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java b/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java index 268ca4bb..7475084a 100644 --- a/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java +++ b/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java @@ -20,8 +20,9 @@ package com.sk89q.worldguard.protection; import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; import java.util.Set; -import java.util.SortedMap; import com.sk89q.worldedit.Vector; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.protection.AreaFlags.State; @@ -34,7 +35,7 @@ public class ApplicableRegionSet { private GlobalFlags global; private Vector pt; - private SortedMap regions; + private Iterator applicable; /** * Construct the object. @@ -43,10 +44,10 @@ public class ApplicableRegionSet { * @param regions * @param global */ - public ApplicableRegionSet(Vector pt, SortedMap regions, + public ApplicableRegionSet(Vector pt, Iterator applicable, GlobalFlags global) { this.pt = pt; - this.regions = regions; + this.applicable = applicable; this.global = global; } @@ -111,7 +112,9 @@ private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) { Set needsClear = new HashSet(); Set hasCleared = new HashSet(); - for (ProtectedRegion region : regions.values()) { + while (applicable.hasNext()) { + ProtectedRegion region = applicable.next(); + // Ignore non-build regions if (player != null && region.getFlags().get(AreaFlags.FLAG_PASSTHROUGH) == State.ALLOW) { continue; diff --git a/src/com/sk89q/worldguard/protection/FlatRegionManager.java b/src/com/sk89q/worldguard/protection/FlatRegionManager.java index 6c6fe2e2..812e0a20 100644 --- a/src/com/sk89q/worldguard/protection/FlatRegionManager.java +++ b/src/com/sk89q/worldguard/protection/FlatRegionManager.java @@ -38,7 +38,7 @@ public class FlatRegionManager implements RegionManager { /** * List of protected regions. */ - private SortedMap regions; + private Map regions; /** * Global flags. */ @@ -60,7 +60,6 @@ public FlatRegionManager(GlobalFlags global) { public Map getRegions() { return regions; } - /** * Set a list of protected regions. @@ -70,6 +69,7 @@ public Map getRegions() { public void setRegions(Map regions) { this.regions = new TreeMap(regions); } + /** * Adds a region. * @@ -125,7 +125,7 @@ public ProtectedRegion getRegion(String id) { * @return */ public ApplicableRegionSet getApplicableRegions(Vector pt) { - return new ApplicableRegionSet(pt, regions, global); + return new ApplicableRegionSet(pt, regions.values().iterator(), global); } /** diff --git a/src/com/sk89q/worldguard/protection/ProtectedRegion.java b/src/com/sk89q/worldguard/protection/ProtectedRegion.java index 365cd8b0..e3351a40 100644 --- a/src/com/sk89q/worldguard/protection/ProtectedRegion.java +++ b/src/com/sk89q/worldguard/protection/ProtectedRegion.java @@ -79,6 +79,20 @@ public String getId() { return id; } + /** + * Get the lower point of the cuboid. + * + * @return min point + */ + public abstract BlockVector getMinimumPoint(); + + /** + * Get the upper point of the cuboid. + * + * @return max point + */ + public abstract BlockVector getMaximumPoint(); + /** * @return the priority */