mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-23 19:16:40 +01:00
Fix incorrect region group inheritance and broken flag override in children.
This commit is contained in:
parent
f516fd5e54
commit
01276dfc62
@ -24,6 +24,7 @@
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class LocalPlayer implements RegionAssociable {
|
||||
@ -94,14 +95,18 @@ public abstract class LocalPlayer implements RegionAssociable {
|
||||
public abstract boolean hasPermission(String perm);
|
||||
|
||||
@Override
|
||||
public Association getAssociation(ProtectedRegion region) {
|
||||
if (region.isOwner(this)) {
|
||||
return Association.OWNER;
|
||||
} else if (region.isMember(this)) {
|
||||
return Association.MEMBER;
|
||||
} else {
|
||||
return Association.NON_MEMBER;
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
boolean member = false;
|
||||
|
||||
for (ProtectedRegion region : regions) {
|
||||
if (region.isOwner(this)) {
|
||||
return Association.OWNER;
|
||||
} else if (!member && region.isMember(this)) {
|
||||
member = true;
|
||||
}
|
||||
}
|
||||
|
||||
return member ? Association.MEMBER : Association.NON_MEMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,6 +27,7 @@
|
||||
import org.bukkit.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -36,7 +37,7 @@
|
||||
* region is in a set of source regions.
|
||||
*
|
||||
* <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 {
|
||||
|
||||
@ -59,17 +60,19 @@ public DelayedRegionOverlapAssociation(RegionQuery query, Location location) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Association getAssociation(ProtectedRegion region) {
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
if (source == null) {
|
||||
ApplicableRegionSet result = query.getApplicableRegions(location);
|
||||
source = result.getRegions();
|
||||
}
|
||||
|
||||
if ((region.getId().equals(ProtectedRegion.GLOBAL_REGION) && source.isEmpty()) || source.contains(region)) {
|
||||
return Association.OWNER;
|
||||
} else {
|
||||
return Association.NON_MEMBER;
|
||||
for (ProtectedRegion region : regions) {
|
||||
if ((region.getId().equals(ProtectedRegion.GLOBAL_REGION) && source.isEmpty()) || source.contains(region)) {
|
||||
return Association.OWNER;
|
||||
}
|
||||
}
|
||||
|
||||
return Association.NON_MEMBER;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,13 +31,7 @@
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
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 java.util.*;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -157,7 +151,7 @@ public Result getMembership(RegionAssociable subject) {
|
||||
foundApplicableRegion = true;
|
||||
|
||||
if (!hasCleared.contains(region)) {
|
||||
if (!RegionGroup.MEMBERS.contains(subject.getAssociation(region))) {
|
||||
if (!RegionGroup.MEMBERS.contains(subject.getAssociation(Arrays.asList(region)))) {
|
||||
needsClear.add(region);
|
||||
} else {
|
||||
// Need to clear all parents
|
||||
@ -330,12 +324,6 @@ public <V> Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag
|
||||
|
||||
ignoreValuesOfParents(consideredValues, ignoredRegions, region);
|
||||
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;
|
||||
|
||||
List<ProtectedRegion> seen = new ArrayList<ProtectedRegion>();
|
||||
|
||||
while (current != null) {
|
||||
seen.add(current);
|
||||
|
||||
V value = current.getFlag(flag);
|
||||
|
||||
if (value != null) {
|
||||
@ -427,7 +419,7 @@ public <V> V getEffectiveFlag(final ProtectedRegion region, Flag<V> flag, @Nulla
|
||||
use = false;
|
||||
} else if (subject == null) {
|
||||
use = group.contains(Association.NON_MEMBER);
|
||||
} else if (!group.contains(subject.getAssociation(region))) {
|
||||
} else if (!group.contains(subject.getAssociation(seen))) {
|
||||
use = false;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class ConstantAssociation implements RegionAssociable {
|
||||
|
||||
private final Association association;
|
||||
@ -31,7 +33,7 @@ class ConstantAssociation implements RegionAssociable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Association getAssociation(ProtectedRegion region) {
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
return association;
|
||||
}
|
||||
|
||||
|
@ -22,17 +22,19 @@
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An object that can have membership in a region.
|
||||
*/
|
||||
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
|
||||
* @return the most specific membership level
|
||||
* @param regions a list of regions
|
||||
* @return the highest membership level
|
||||
*/
|
||||
Association getAssociation(ProtectedRegion region);
|
||||
Association getAssociation(List<ProtectedRegion> regions);
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -45,12 +46,14 @@ public RegionOverlapAssociation(Set<ProtectedRegion> source) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Association getAssociation(ProtectedRegion region) {
|
||||
if (source.contains(region)) {
|
||||
return Association.OWNER;
|
||||
} else {
|
||||
return Association.NON_MEMBER;
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
for (ProtectedRegion region : regions) {
|
||||
if (source.contains(region)) {
|
||||
return Association.OWNER;
|
||||
}
|
||||
}
|
||||
|
||||
return Association.NON_MEMBER;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user