Fix incorrect region group inheritance and broken flag override in children.

This commit is contained in:
sk89q 2015-01-09 13:21:17 -08:00
parent f516fd5e54
commit 01276dfc62
6 changed files with 45 additions and 38 deletions

View File

@ -24,6 +24,7 @@
import com.sk89q.worldguard.protection.association.RegionAssociable; import com.sk89q.worldguard.protection.association.RegionAssociable;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public abstract class LocalPlayer implements RegionAssociable { public abstract class LocalPlayer implements RegionAssociable {
@ -94,14 +95,18 @@ public abstract class LocalPlayer implements RegionAssociable {
public abstract boolean hasPermission(String perm); public abstract boolean hasPermission(String perm);
@Override @Override
public Association getAssociation(ProtectedRegion region) { public Association getAssociation(List<ProtectedRegion> regions) {
if (region.isOwner(this)) { boolean member = false;
return Association.OWNER;
} else if (region.isMember(this)) { for (ProtectedRegion region : regions) {
return Association.MEMBER; if (region.isOwner(this)) {
} else { return Association.OWNER;
return Association.NON_MEMBER; } else if (!member && region.isMember(this)) {
member = true;
}
} }
return member ? Association.MEMBER : Association.NON_MEMBER;
} }
@Override @Override

View File

@ -27,6 +27,7 @@
import org.bukkit.Location; import org.bukkit.Location;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
import java.util.Set; import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -36,7 +37,7 @@
* region is in a set of source regions. * region is in a set of source regions.
* *
* <p>This class only performs a spatial query if its * <p>This class only performs a spatial query if its
* {@link #getAssociation(ProtectedRegion)} method is called.</p> * {@link #getAssociation(List)} method is called.</p>
*/ */
public class DelayedRegionOverlapAssociation implements RegionAssociable { public class DelayedRegionOverlapAssociation implements RegionAssociable {
@ -59,17 +60,19 @@ public DelayedRegionOverlapAssociation(RegionQuery query, Location location) {
} }
@Override @Override
public Association getAssociation(ProtectedRegion region) { public Association getAssociation(List<ProtectedRegion> regions) {
if (source == null) { if (source == null) {
ApplicableRegionSet result = query.getApplicableRegions(location); ApplicableRegionSet result = query.getApplicableRegions(location);
source = result.getRegions(); source = result.getRegions();
} }
if ((region.getId().equals(ProtectedRegion.GLOBAL_REGION) && source.isEmpty()) || source.contains(region)) { for (ProtectedRegion region : regions) {
return Association.OWNER; if ((region.getId().equals(ProtectedRegion.GLOBAL_REGION) && source.isEmpty()) || source.contains(region)) {
} else { return Association.OWNER;
return Association.NON_MEMBER; }
} }
return Association.NON_MEMBER;
} }
} }

View File

@ -31,13 +31,7 @@
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Arrays; import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -157,7 +151,7 @@ public Result getMembership(RegionAssociable subject) {
foundApplicableRegion = true; foundApplicableRegion = true;
if (!hasCleared.contains(region)) { if (!hasCleared.contains(region)) {
if (!RegionGroup.MEMBERS.contains(subject.getAssociation(region))) { if (!RegionGroup.MEMBERS.contains(subject.getAssociation(Arrays.asList(region)))) {
needsClear.add(region); needsClear.add(region);
} else { } else {
// Need to clear all parents // Need to clear all parents
@ -330,12 +324,6 @@ public <V> Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag
ignoreValuesOfParents(consideredValues, ignoredRegions, region); ignoreValuesOfParents(consideredValues, ignoredRegions, region);
consideredValues.put(region, value); consideredValues.put(region, value);
if (value == State.DENY) {
// Since DENY overrides all other values, there
// is no need to consider any further regions
break;
}
} }
} }
@ -411,7 +399,11 @@ public <V> V getEffectiveFlag(final ProtectedRegion region, Flag<V> flag, @Nulla
ProtectedRegion current = region; ProtectedRegion current = region;
List<ProtectedRegion> seen = new ArrayList<ProtectedRegion>();
while (current != null) { while (current != null) {
seen.add(current);
V value = current.getFlag(flag); V value = current.getFlag(flag);
if (value != null) { if (value != null) {
@ -427,7 +419,7 @@ public <V> V getEffectiveFlag(final ProtectedRegion region, Flag<V> flag, @Nulla
use = false; use = false;
} else if (subject == null) { } else if (subject == null) {
use = group.contains(Association.NON_MEMBER); use = group.contains(Association.NON_MEMBER);
} else if (!group.contains(subject.getAssociation(region))) { } else if (!group.contains(subject.getAssociation(seen))) {
use = false; use = false;
} }
} }

View File

@ -22,6 +22,8 @@
import com.sk89q.worldguard.domains.Association; import com.sk89q.worldguard.domains.Association;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.List;
class ConstantAssociation implements RegionAssociable { class ConstantAssociation implements RegionAssociable {
private final Association association; private final Association association;
@ -31,7 +33,7 @@ class ConstantAssociation implements RegionAssociable {
} }
@Override @Override
public Association getAssociation(ProtectedRegion region) { public Association getAssociation(List<ProtectedRegion> regions) {
return association; return association;
} }

View File

@ -22,17 +22,19 @@
import com.sk89q.worldguard.domains.Association; import com.sk89q.worldguard.domains.Association;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.List;
/** /**
* An object that can have membership in a region. * An object that can have membership in a region.
*/ */
public interface RegionAssociable { public interface RegionAssociable {
/** /**
* Get the most specific association level for the input region. * Get the highest association level for the input regions.
* *
* @param region the input region * @param regions a list of regions
* @return the most specific membership level * @return the highest membership level
*/ */
Association getAssociation(ProtectedRegion region); Association getAssociation(List<ProtectedRegion> regions);
} }

View File

@ -22,6 +22,7 @@
import com.sk89q.worldguard.domains.Association; import com.sk89q.worldguard.domains.Association;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.List;
import java.util.Set; import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -45,12 +46,14 @@ public RegionOverlapAssociation(Set<ProtectedRegion> source) {
} }
@Override @Override
public Association getAssociation(ProtectedRegion region) { public Association getAssociation(List<ProtectedRegion> regions) {
if (source.contains(region)) { for (ProtectedRegion region : regions) {
return Association.OWNER; if (source.contains(region)) {
} else { return Association.OWNER;
return Association.NON_MEMBER; }
} }
return Association.NON_MEMBER;
} }
} }