Force __global__ BUILD flag to NONE.

This is due to the legacy reason of the global region having not
been previously processed as a regular region.
This commit is contained in:
sk89q 2014-08-16 13:54:04 -07:00
parent bfb3f9e840
commit a35aaf9659
2 changed files with 47 additions and 7 deletions

View File

@ -407,14 +407,20 @@ public int getPriority(final ProtectedRegion region) {
*/
@SuppressWarnings("unchecked")
public <V> V getEffectiveFlag(final ProtectedRegion region, Flag<V> flag, @Nullable LocalPlayer player) {
// The global region normally does not prevent building so
// PASSTHROUGH has to be ALLOW, except when people use the global
// region as a whitelist
if (region == globalRegion && flag == DefaultFlag.PASSTHROUGH) {
if (region.hasMembersOrOwners()) {
if (region == globalRegion) {
if (flag == DefaultFlag.PASSTHROUGH) {
// Has members/owners -> the global region acts like
// a regular region without PASSTHROUGH
if (region.hasMembersOrOwners()) {
return null;
} else {
return (V) State.ALLOW;
}
} else if (flag == DefaultFlag.BUILD) {
// Legacy behavior -> we can't let people change BUILD on
// the global region
return null;
} else {
return (V) State.ALLOW;
}
}

View File

@ -1959,4 +1959,38 @@ public void testGetEffectiveFlagInheritanceAndDifferingGroupsMemberOnParentFlagO
assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("everyone"));
assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null));
}
@Test
public void testGetEffectiveFlagGlobalRegionBuild() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion global = mock.global();
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.getEffectiveFlag(global, DefaultFlag.BUILD, null), equalTo(null));
}
@Test
public void testGetEffectiveFlagGlobalRegionBuildDeny() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion global = mock.global();
global.setFlag(DefaultFlag.BUILD, State.DENY);
FlagValueCalculator result = mock.getFlagCalculator();
// Cannot let users override BUILD on GLOBAL
assertThat(result.getEffectiveFlag(global, DefaultFlag.BUILD, null), equalTo(null));
}
@Test
public void testGetEffectiveFlagGlobalRegionBuildAllow() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
ProtectedRegion global = mock.global();
global.setFlag(DefaultFlag.BUILD, State.ALLOW);
FlagValueCalculator result = mock.getFlagCalculator();
// Cannot let users override BUILD on GLOBAL
assertThat(result.getEffectiveFlag(global, DefaultFlag.BUILD, null), equalTo(null));
}
}