diff --git a/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java b/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java index 3455ab9d..2514f031 100644 --- a/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java +++ b/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java @@ -407,14 +407,20 @@ public int getPriority(final ProtectedRegion region) { */ @SuppressWarnings("unchecked") public V getEffectiveFlag(final ProtectedRegion region, Flag 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; } } diff --git a/src/test/java/com/sk89q/worldguard/protection/FlagValueCalculatorTest.java b/src/test/java/com/sk89q/worldguard/protection/FlagValueCalculatorTest.java index 2837cf00..9a116086 100644 --- a/src/test/java/com/sk89q/worldguard/protection/FlagValueCalculatorTest.java +++ b/src/test/java/com/sk89q/worldguard/protection/FlagValueCalculatorTest.java @@ -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)); + } } \ No newline at end of file