Fix child regions not inheriting parent flags.

This also fixes a unit test.
This commit is contained in:
sk89q 2014-08-15 03:48:25 -07:00
parent 3f16fef57e
commit d3f3489c7e
2 changed files with 35 additions and 8 deletions

View File

@ -251,8 +251,7 @@ private boolean internalGetState(StateFlag flag, @Nullable LocalPlayer player, @
lastPriority = region.getPriority(); lastPriority = region.getPriority();
// Ignore non-build regions // Ignore non-build regions
if (player != null if (player != null && getStateFlagIncludingParents(region, DefaultFlag.PASSTHROUGH) == State.ALLOW) {
&& region.getFlag(DefaultFlag.PASSTHROUGH) == State.ALLOW) {
continue; continue;
} }
@ -267,7 +266,7 @@ private boolean internalGetState(StateFlag flag, @Nullable LocalPlayer player, @
} }
} }
State v = region.getFlag(flag); State v = getStateFlagIncludingParents(region, flag);
// Allow DENY to override everything // Allow DENY to override everything
if (v == State.DENY) { if (v == State.DENY) {
@ -327,6 +326,28 @@ private void clearParents(Set<ProtectedRegion> needsClear, Set<ProtectedRegion>
} }
} }
/**
* Get a region's state flag, checking parent regions until a value for the
* flag can be found (if one even exists).
*
* @param region the region
* @param flag the flag
* @return the value
*/
private static State getStateFlagIncludingParents(ProtectedRegion region, StateFlag flag) {
while (region != null) {
State value = region.getFlag(flag);
if (value != null) {
return value;
}
region = region.getParent();
}
return null;
}
/** /**
* Gets the value of a flag. Do not use this for state flags * Gets the value of a flag. Do not use this for state flags
* (use {@link #allows(StateFlag, LocalPlayer)} for that). * (use {@link #allows(StateFlag, LocalPlayer)} for that).

View File

@ -19,8 +19,6 @@
package com.sk89q.worldguard.protection; package com.sk89q.worldguard.protection;
import java.util.ArrayList;
import org.junit.Before;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
@ -29,9 +27,17 @@
import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.*; import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
import java.util.ArrayList;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public abstract class RegionPriorityTest { public abstract class RegionPriorityTest {
static String COURTYARD_ID = "courtyard"; static String COURTYARD_ID = "courtyard";
@ -143,7 +149,7 @@ public void testPriorities() throws Exception {
public void testPriorities2() throws Exception { public void testPriorities2() throws Exception {
ApplicableRegionSet appl; ApplicableRegionSet appl;
fountain.setPriority(0); courtyard.setPriority(0);
fountain.setPriority(5); fountain.setPriority(5);
appl = manager.getApplicableRegions(inCourtyard); appl = manager.getApplicableRegions(inCourtyard);