Changed how ApplicableRegionSet iterated over the region set, allowing it to be reused.

This commit is contained in:
sk89q 2011-02-12 15:49:55 -08:00
parent ce1a15e6ea
commit 43489ca087
3 changed files with 25 additions and 8 deletions

View File

@ -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<String,ProtectedRegion> regions;
private Iterator<ProtectedRegion> applicable;
/**
* Construct the object.
@ -43,10 +44,10 @@ public class ApplicableRegionSet {
* @param regions
* @param global
*/
public ApplicableRegionSet(Vector pt, SortedMap<String,ProtectedRegion> regions,
public ApplicableRegionSet(Vector pt, Iterator<ProtectedRegion> 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<ProtectedRegion> needsClear = new HashSet<ProtectedRegion>();
Set<ProtectedRegion> hasCleared = new HashSet<ProtectedRegion>();
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;

View File

@ -38,7 +38,7 @@ public class FlatRegionManager implements RegionManager {
/**
* List of protected regions.
*/
private SortedMap<String,ProtectedRegion> regions;
private Map<String,ProtectedRegion> regions;
/**
* Global flags.
*/
@ -60,7 +60,6 @@ public FlatRegionManager(GlobalFlags global) {
public Map<String,ProtectedRegion> getRegions() {
return regions;
}
/**
* Set a list of protected regions.
@ -70,6 +69,7 @@ public Map<String,ProtectedRegion> getRegions() {
public void setRegions(Map<String,ProtectedRegion> regions) {
this.regions = new TreeMap<String,ProtectedRegion>(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);
}
/**

View File

@ -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
*/