From cab42af53bcde6fdfb8d59e96a21f88c9a0ccd06 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sun, 17 Aug 2014 00:49:32 -0700 Subject: [PATCH] Reimplemented the quirks of the old flag code. --- .../sk89q/worldguard/bukkit/RegionQuery.java | 80 +- .../protection/ApplicableRegionSet.java | 139 +- .../protection/FlagValueCalculator.java | 94 +- .../protection/flags/DefaultFlag.java | 52 +- .../protection/ApplicableRegionSetTest.java | 38 +- .../protection/FlagValueCalculatorTest.java | 1614 ++++++++--------- 6 files changed, 918 insertions(+), 1099 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/RegionQuery.java b/src/main/java/com/sk89q/worldguard/bukkit/RegionQuery.java index 9a4ef736..5fafb41a 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/RegionQuery.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/RegionQuery.java @@ -22,6 +22,7 @@ import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.GlobalRegionManager; +import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StateFlag.State; @@ -96,10 +97,12 @@ public ApplicableRegionSet getApplicableRegions(Location location) { } /** - * Test whether the given player is permitted to modify or interact with - * blocks at the given location. Additional flags to be considered can be - * provided. The {@code BUILD} flag is already included in the list of - * flags considered. + * Test whether the given flags evaluate to {@code ALLOW}, implicitly also + * considering the {@link DefaultFlag#BUILD} flag. + * + *

This method is equivalent to calling + * {@link #testState(Location, Player, StateFlag...)} with + * {@code flags} plus the {@code BUILD} flag.

* * @param location the location * @param player the player @@ -128,19 +131,14 @@ public boolean testBuild(Location location, Player player, StateFlag... flags) { } /** - * Get the effective value for a flag. If there are multiple values - * (for example, if there are multiple regions with the same priority - * but with different farewell messages set, there would be multiple - * completing values), then the selected (or "winning") value will depend - * on the flag type. + * Test whether the (effective) value for a list of state flags equals + * {@code ALLOW}. * - *

This method does not properly process build - * permissions. Instead, use {@link #testBuild(Location, Player, StateFlag...)} - * for that purpose.

- * - *

This method does the same as - * {@link #queryState(Location, Player, StateFlag...)} except that it - * returns a boolean when the result is {@code ALLOW}.

+ *

{@code player} can be non-null to satisfy region group requirements, + * otherwise it will be assumed that the caller that is not a member of any + * regions. (Flags on a region can be changed so that they only apply + * to certain users.) The player argument is required if the + * {@link DefaultFlag#BUILD} flag is in the list of flags.

* * @param location the location * @param player an optional player, which would be used to determine the region group to apply @@ -148,21 +146,20 @@ public boolean testBuild(Location location, Player player, StateFlag... flags) { * @return true if the result was {@code ALLOW} * @see ApplicableRegionSet#queryValue(LocalPlayer, Flag) */ - public boolean testState(Location location, @Nullable Player player, StateFlag flag) { + public boolean testState(Location location, @Nullable Player player, StateFlag... flag) { return StateFlag.test(queryState(location, player, flag)); } /** - * Get the effective value for a list of state flags. The rules of + * Get the (effective) value for a list of state flags. The rules of * states is observed here; that is, {@code DENY} overrides {@code ALLOW}, - * and {@code ALLOW} overrides {@code NONE}. + * and {@code ALLOW} overrides {@code NONE}. One flag may override another. * - *

This method does not properly process build - * permissions. Instead, use {@link #testBuild(Location, Player, StateFlag...)} - * for that purpose.

- * - * See {@link ApplicableRegionSet#queryState(LocalPlayer, StateFlag...)} - * for more information. + *

{@code player} can be non-null to satisfy region group requirements, + * otherwise it will be assumed that the caller that is not a member of any + * regions. (Flags on a region can be changed so that they only apply + * to certain users.) The player argument is required if the + * {@link DefaultFlag#BUILD} flag is in the list of flags.

* * @param location the location * @param player an optional player, which would be used to determine the region groups that apply @@ -178,17 +175,21 @@ public State queryState(Location location, @Nullable Player player, StateFlag... /** * Get the effective value for a flag. If there are multiple values - * (for example, if there are multiple regions with the same priority - * but with different farewell messages set, there would be multiple - * completing values), then the selected (or "winning") value will depend - * on the flag type. + * (for example, multiple overlapping regions with + * the same priority may have the same flag set), then the selected + * (or "winning") value will depend on the flag type. * - *

This method does not properly process build - * permissions. Instead, use {@link #testBuild(Location, Player, StateFlag...)} - * for that purpose.

+ *

Only some flag types actually have a strategy for picking the + * "best value." For most types, the actual value that is chosen to be + * returned is undefined (it could be any value). As of writing, the only + * type of flag that actually has a strategy for picking a value is the + * {@link StateFlag}.

* - *

See {@link ApplicableRegionSet#queryValue(LocalPlayer, Flag)} for - * more information.

+ *

{@code player} can be non-null to satisfy region group requirements, + * otherwise it will be assumed that the caller that is not a member of any + * regions. (Flags on a region can be changed so that they only apply + * to certain users.) The player argument is required if the + * {@link DefaultFlag#BUILD} flag is the flag being queried.

* * @param location the location * @param player an optional player, which would be used to determine the region group to apply @@ -207,12 +208,11 @@ public V queryValue(Location location, @Nullable Player player, Flag flag * values. It is up to the caller to determine which value, if any, * from the collection will be used. * - *

This method does not properly process build - * permissions. Instead, use {@link #testBuild(Location, Player, StateFlag...)} - * for that purpose.

- * - *

See {@link ApplicableRegionSet#queryAllValues(LocalPlayer, Flag)} - * for more information.

+ *

{@code player} can be non-null to satisfy region group requirements, + * otherwise it will be assumed that the caller that is not a member of any + * regions. (Flags on a region can be changed so that they only apply + * to certain users.) The player argument is required if the + * {@link DefaultFlag#BUILD} flag is the flag being queried.

* * @param location the location * @param player an optional player, which would be used to determine the region group to apply diff --git a/src/main/java/com/sk89q/worldguard/protection/ApplicableRegionSet.java b/src/main/java/com/sk89q/worldguard/protection/ApplicableRegionSet.java index 3dc013ca..1ec49a7e 100644 --- a/src/main/java/com/sk89q/worldguard/protection/ApplicableRegionSet.java +++ b/src/main/java/com/sk89q/worldguard/protection/ApplicableRegionSet.java @@ -97,43 +97,56 @@ public ApplicableRegionSet(SortedSet applicable, @Nullable Prot @Deprecated public boolean canBuild(LocalPlayer player) { checkNotNull(player); - return test(flagValueCalculator.queryPermission(player, DefaultFlag.BUILD)); + return test(flagValueCalculator.queryState(player, DefaultFlag.BUILD)); } /** - * Test whether the given player is permitted to modify or interact with - * blocks. Additional flags to be considered can be provided. The - * {@code BUILD} flag is already included in the list of flags considered. + * Test whether the given flags evaluate to {@code ALLOW}, implicitly also + * considering the {@link DefaultFlag#BUILD} flag. + * + *

This method is equivalent to calling + * {@link #testState(LocalPlayer, StateFlag...)} with {@code flags} plus + * the {@code BUILD} flag.

* * @param player the player * @param flags zero or more flags * @return true if permission is granted + * @see #queryState(LocalPlayer, StateFlag...) */ public boolean testBuild(LocalPlayer player, StateFlag... flags) { - return test(flagValueCalculator.queryPermission(player, ObjectArrays.concat(flags, DefaultFlag.BUILD))); + checkNotNull(player); + return test(flagValueCalculator.queryState(player, ObjectArrays.concat(flags, DefaultFlag.BUILD))); } /** - * Get the effective value for a list of state flags. The rules of + * Test whether the (effective) value for a list of state flags equals + * {@code ALLOW}. + * + *

{@code player} can be non-null to satisfy region group requirements, + * otherwise it will be assumed that the caller that is not a member of any + * regions. (Flags on a region can be changed so that they only apply + * to certain users.) The player argument is required if the + * {@link DefaultFlag#BUILD} flag is in the list of flags.

+ * + * @param player an optional player, which would be used to determine the region groups that apply + * @param flags a list of flags to check + * @return true if the result was {@code ALLOW} + * @see #queryState(LocalPlayer, StateFlag...) + */ + public boolean testState(@Nullable LocalPlayer player, StateFlag... flags) { + return test(flagValueCalculator.queryState(player, flags)); + } + + /** + * Get the (effective) value for a list of state flags. The rules of * states is observed here; that is, {@code DENY} overrides {@code ALLOW}, - * and {@code ALLOW} overrides {@code NONE}. + * and {@code ALLOW} overrides {@code NONE}. One flag may override another. * - *

This method does not properly process build - * permissions. Instead, use {@link #testBuild(LocalPlayer, StateFlag...)} - * for that purpose. This method is ideal for testing non-build related - * state flags (although a rarity), an example of which would be whether - * to play a song to players that enter an area.

- * - *

A player can be provided that is used to determine whether the value - * of a flag on a particular region should be used. For example, if a - * flag's region group is set to {@link RegionGroup#MEMBERS} and the given - * player is not a member, then the region would be skipped when - * querying that flag. If {@code null} is provided for the player, then - * only flags that use {@link RegionGroup#ALL}, - * {@link RegionGroup#NON_MEMBERS}, etc. will apply.

- * - *

This method does not use a {@link StateFlag}'s - * default value ({@link StateFlag#getDefault()}).

+ *

{@code player} can be non-null to satisfy region group requirements, + * otherwise it will be assumed that the caller that is not a member of any + * regions. (Flags on a region can be changed so that they only apply + * to certain users.) The player argument is required if the + * {@link DefaultFlag#BUILD} flag is in the list of flags.

* * @param player an optional player, which would be used to determine the region groups that apply * @param flags a list of flags to check @@ -144,51 +157,23 @@ public State queryState(@Nullable LocalPlayer player, StateFlag... flags) { return flagValueCalculator.queryState(player, flags); } - /** - * Get the effective value for a list of state flags. The rules of - * states is observed here; that is, {@code DENY} overrides {@code ALLOW}, - * and {@code ALLOW} overrides {@code NONE}. - * - *

This method is the same as - * {@link #queryState(LocalPlayer, StateFlag...)} except that it returns - * a boolean when the return value is {@code ALLOW}.

- * - * @param player an optional player, which would be used to determine the region groups that apply - * @param flags a list of flags to check - * @return true if the result was {@code ALLOW} - */ - public boolean testState(@Nullable LocalPlayer player, StateFlag... flags) { - return test(flagValueCalculator.queryState(player, flags)); - } - /** * Get the effective value for a flag. If there are multiple values - * (for example, if there are multiple regions with the same priority - * but with different farewell messages set, there would be multiple - * completing values), then the selected (or "winning") value will depend - * on the flag type. + * (for example, multiple overlapping regions with + * the same priority may have the same flag set), then the selected + * (or "winning") value will depend on the flag type. * *

Only some flag types actually have a strategy for picking the * "best value." For most types, the actual value that is chosen to be * returned is undefined (it could be any value). As of writing, the only - * type of flag that can consistently return the same 'best' value is + * type of flag that actually has a strategy for picking a value is the * {@link StateFlag}.

* - *

This method does not properly process build - * permissions. Instead, use {@link #testBuild(LocalPlayer, StateFlag...)} - * for that purpose.

- * - *

A player can be provided that is used to determine whether the value - * of a flag on a particular region should be used. For example, if a - * flag's region group is set to {@link RegionGroup#MEMBERS} and the given - * player is not a member, then the region would be skipped when - * querying that flag. If {@code null} is provided for the player, then - * only flags that use {@link RegionGroup#ALL}, - * {@link RegionGroup#NON_MEMBERS}, etc. will apply.

- * - *

This method does not use a {@link StateFlag}'s - * default value ({@link StateFlag#getDefault()}) if the provided flag is - * a {@code StateFlag}.

+ *

{@code player} can be non-null to satisfy region group requirements, + * otherwise it will be assumed that the caller that is not a member of any + * regions. (Flags on a region can be changed so that they only apply + * to certain users.) The player argument is required if the + * {@link DefaultFlag#BUILD} flag is the flag being queried.

* * @param player an optional player, which would be used to determine the region group to apply * @param flag the flag @@ -204,21 +189,11 @@ public V queryValue(@Nullable LocalPlayer player, Flag flag) { * values. It is up to the caller to determine which value, if any, * from the collection will be used. * - *

This method does not properly process build - * permissions. Instead, use {@link #testBuild(LocalPlayer, StateFlag...)} - * for that purpose.

- * - *

A player can be provided that is used to determine whether the value - * of a flag on a particular region should be used. For example, if a - * flag's region group is set to {@link RegionGroup#MEMBERS} and the given - * player is not a member, then the region would be skipped when - * querying that flag. If {@code null} is provided for the player, then - * only flags that use {@link RegionGroup#ALL}, - * {@link RegionGroup#NON_MEMBERS}, etc. will apply.

- * - *

This method does not include a {@link StateFlag}'s - * default value ({@link StateFlag#getDefault()}) if the provided flag is - * a {@code StateFlag}.

+ *

{@code player} can be non-null to satisfy region group requirements, + * otherwise it will be assumed that the caller that is not a member of any + * regions. (Flags on a region can be changed so that they only apply + * to certain users.) The player argument is required if the + * {@link DefaultFlag#BUILD} flag is the flag being queried.

* * @param player an optional player, which would be used to determine the region group to apply * @param flag the flag @@ -249,12 +224,7 @@ public boolean canConstruct(LocalPlayer player) { * @param flag flag to check * @return whether it is allowed * @throws IllegalArgumentException if the build flag is given - * @deprecated Use {@link #queryState(LocalPlayer, StateFlag...)} instead, although - * be aware that the default value of the flag is not - * considered in that method. Default values, however, are being - * deprecated (except when using it in the context of testing - * build permissions) because they have historically been applied - * very inconsistently. + * @deprecated use {@link #queryState(LocalPlayer, StateFlag...)} instead */ @Deprecated public boolean allows(StateFlag flag) { @@ -274,12 +244,7 @@ public boolean allows(StateFlag flag) { * @param player player (used by some flags) * @return whether the state is allows for it * @throws IllegalArgumentException if the build flag is given - * @deprecated Use {@link #queryState(LocalPlayer, StateFlag...)} instead, although - * be aware that the default value of the flag is not - * considered in that method. Default values, however, are being - * deprecated (except when using it in the context of testing - * build permissions) because they have historically been applied - * very inconsistently. + * @deprecated use {@link #queryState(LocalPlayer, StateFlag...)} instead */ @Deprecated public boolean allows(StateFlag flag, @Nullable LocalPlayer player) { diff --git a/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java b/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java index fc1bea54..6b2e1a49 100644 --- a/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java +++ b/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java @@ -169,75 +169,12 @@ public Result getMembership(LocalPlayer player) { } } - /** - * Test whether the given player is permitted to place, break, or - * modify any block, entity, or other object. A list of flags is to be - * provided (one of which should probably be {@link DefaultFlag#BUILD}) - * so that the calculation can consider all of those flags. - * - *

For example, if we are checking for the ability to interact - * with a chest, we would want to give permission if (1) the player is - * a member of the region, (2) the {@code build} flag is set to - * {@code ALLOW}, or (3) the {@code chest-access} flag is set to - * {@code ALLOW}. However, if any of the two flags are set - * to {@code DENY}, that must override everything else and deny access.

- * - *

This method handles that example perfectly. To use the method for - * the example, the call would look like this:

- * - *
queryPermission(player, DefaultFlag.BUILD, DefaultFlag.CHEST_ACCESS)
- * - * @param player the player - * @param flags zero or more flags - * @return true if permission is granted - */ - public State queryPermission(LocalPlayer player, StateFlag... flags) { - checkNotNull(player); - checkNotNull(flags); - - // Legacy behavior dictates that the global region is really a - // "wilderness" region. It has no effect when there are one or more - // regions without the PASSTHROUGH flag set. - // - // In addition, the global region can never override any PASSTHROUGH - // region. - // - // Lastly, if the global region has members, then permission will - // be denied by default except to those members that are a part of - // the global region, turning the global region into a region itself - // that covers the entire world. Unfortunately, this is really a hack - // and we support it for legacy reasons. - - switch (getMembership(player)) { - case SUCCESS: - return StateFlag.combine(queryState(player, flags), State.ALLOW); - case FAIL: - return queryState(player, flags); - case NO_REGIONS: - default: - State fallback = null; - for (StateFlag flag : flags) { - if (flag.getDefault()) { - fallback = State.ALLOW; - break; - } - } - return StateFlag.combine(queryState(player, flags), fallback); - } - } - /** * Get the effective value for a list of state flags. The rules of * states is observed here; that is, {@code DENY} overrides {@code ALLOW}, * and {@code ALLOW} overrides {@code NONE}. * - *

This method does not properly process build - * permissions. Instead, use {@link #queryPermission(LocalPlayer, StateFlag...)} - * for that purpose. This method is ideal for testing non-build related - * state flags (although a rarity), an example of which would be whether - * to play a song to players that enter an area.

- * *

A player can be provided that is used to determine whether the value * of a flag on a particular region should be used. For example, if a * flag's region group is set to {@link RegionGroup#MEMBERS} and the given @@ -277,10 +214,6 @@ public State queryState(@Nullable LocalPlayer player, StateFlag... flags) { * type of flag that can consistently return the same 'best' value is * {@link StateFlag}.

* - *

This method does not properly process build - * permissions. Instead, use {@link #queryPermission(LocalPlayer, StateFlag...)} - * for that purpose.

- * *

A player can be provided that is used to determine whether the value * of a flag on a particular region should be used. For example, if a * flag's region group is set to {@link RegionGroup#MEMBERS} and the given @@ -304,10 +237,6 @@ public V queryValue(@Nullable LocalPlayer player, Flag flag) { * values. It is up to the caller to determine which value, if any, * from the collection will be used. * - *

This method does not properly process build - * permissions. Instead, use {@link #queryPermission(LocalPlayer, StateFlag...)} - * for that purpose.

- * *

A player can be provided that is used to determine whether the value * of a flag on a particular region should be used. For example, if a * flag's region group is set to {@link RegionGroup#MEMBERS} and the given @@ -320,6 +249,7 @@ public V queryValue(@Nullable LocalPlayer player, Flag flag) { * @param flag the flag * @return a collection of values */ + @SuppressWarnings("unchecked") public Collection queryAllValues(@Nullable LocalPlayer player, Flag flag) { checkNotNull(flag); @@ -383,6 +313,28 @@ public Collection queryAllValues(@Nullable LocalPlayer player, Flag fl } } + if (flag == DefaultFlag.BUILD && consideredValues.isEmpty()) { + if (player == null) { + throw new NullPointerException("The BUILD flag is handled in a special fashion and requires a non-null player parameter"); + } + + switch (getMembership(player)) { + case FAIL: + return ImmutableList.of(); + case SUCCESS: + return (Collection) ImmutableList.of(State.ALLOW); + } + } + + if (consideredValues.isEmpty()) { + if (flag instanceof StateFlag) { + //noinspection unchecked + return (Collection) (((StateFlag) flag).getDefault() + ? ImmutableList.of(State.ALLOW) + : ImmutableList.of()); + } + } + return consideredValues.values(); } diff --git a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java index c936150a..10e59401 100644 --- a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java +++ b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java @@ -29,27 +29,32 @@ public final class DefaultFlag { public static final StateFlag PASSTHROUGH = new StateFlag("passthrough", false); - public static final StateFlag BUILD = new StateFlag("build", true); public static final RegionGroupFlag CONSTRUCT = new RegionGroupFlag("construct", RegionGroup.MEMBERS); - public static final StateFlag PVP = new StateFlag("pvp", true); + + // This flag is unlike the others. It forces the checking of region + // membership. + public static final StateFlag BUILD = new StateFlag("build", true); + + public static final StateFlag USE = new StateFlag("use", false); + public static final StateFlag PVP = new StateFlag("pvp", false); + public static final StateFlag SLEEP = new StateFlag("sleep", false); + public static final StateFlag TNT = new StateFlag("tnt", false); + public static final StateFlag CHEST_ACCESS = new StateFlag("chest-access", false); + public static final StateFlag PLACE_VEHICLE = new StateFlag("vehicle-place", false); + public static final StateFlag DESTROY_VEHICLE = new StateFlag("vehicle-destroy", false); + public static final StateFlag LIGHTER = new StateFlag("lighter", false); + public static final StateFlag MOB_DAMAGE = new StateFlag("mob-damage", true); public static final StateFlag MOB_SPAWNING = new StateFlag("mob-spawning", true); public static final StateFlag CREEPER_EXPLOSION = new StateFlag("creeper-explosion", true); public static final StateFlag ENDERDRAGON_BLOCK_DAMAGE = new StateFlag("enderdragon-block-damage", true); public static final StateFlag GHAST_FIREBALL = new StateFlag("ghast-fireball", true); public static final StateFlag OTHER_EXPLOSION = new StateFlag("other-explosion", true); - public static final StateFlag SLEEP = new StateFlag("sleep", true); - public static final StateFlag TNT = new StateFlag("tnt", true); - public static final StateFlag LIGHTER = new StateFlag("lighter", true); public static final StateFlag FIRE_SPREAD = new StateFlag("fire-spread", true); public static final StateFlag LAVA_FIRE = new StateFlag("lava-fire", true); public static final StateFlag LIGHTNING = new StateFlag("lightning", true); - public static final StateFlag CHEST_ACCESS = new StateFlag("chest-access", true); public static final StateFlag WATER_FLOW = new StateFlag("water-flow", true); public static final StateFlag LAVA_FLOW = new StateFlag("lava-flow", true); - public static final StateFlag USE = new StateFlag("use", true); - public static final StateFlag PLACE_VEHICLE = new StateFlag("vehicle-place", true); - public static final StateFlag DESTROY_VEHICLE = new StateFlag("vehicle-destroy", true); public static final StateFlag PISTONS = new StateFlag("pistons", true); public static final StateFlag SNOW_FALL = new StateFlag("snow-fall", true); public static final StateFlag SNOW_MELT = new StateFlag("snow-melt", true); @@ -73,6 +78,7 @@ public final class DefaultFlag { public static final StateFlag ENTITY_PAINTING_DESTROY = new StateFlag("entity-painting-destroy", true); public static final StateFlag ENTITY_ITEM_FRAME_DESTROY = new StateFlag("entity-item-frame-destroy", true); public static final StateFlag POTION_SPLASH = new StateFlag("potion-splash", true); + public static final StringFlag GREET_MESSAGE = new StringFlag("greeting"); public static final StringFlag FAREWELL_MESSAGE = new StringFlag("farewell"); public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter"); @@ -98,20 +104,20 @@ public final class DefaultFlag { public static final SetFlag ALLOWED_CMDS = new SetFlag("allowed-cmds", new CommandStringFlag(null)); public static final Flag[] flagsList = new Flag[] { - PASSTHROUGH, BUILD, CONSTRUCT, PVP, CHEST_ACCESS, PISTONS, - TNT, LIGHTER, USE, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP, - MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS, - CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD, - GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE, - EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY, ENDERPEARL, - ENTITY_ITEM_FRAME_DESTROY, ITEM_DROP, /*MAX_PLAYERS, MAX_PLAYERS_MESSAGE,*/ - HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL, - FEED_DELAY, FEED_AMOUNT, MIN_FOOD, MAX_FOOD, - SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, SOIL_DRY, GAME_MODE, - MUSHROOMS, LEAF_DECAY, GRASS_SPREAD, MYCELIUM_SPREAD, VINE_GROWTH, - SEND_CHAT, RECEIVE_CHAT, FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW, - TELE_LOC, SPAWN_LOC, POTION_SPLASH, - BLOCKED_CMDS, ALLOWED_CMDS, PRICE, BUYABLE, ENABLE_SHOP + PASSTHROUGH, BUILD, CONSTRUCT, PVP, CHEST_ACCESS, PISTONS, + TNT, LIGHTER, USE, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP, + MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS, + CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD, + GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE, + EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY, ENDERPEARL, + ENTITY_ITEM_FRAME_DESTROY, ITEM_DROP, /*MAX_PLAYERS, MAX_PLAYERS_MESSAGE,*/ + HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL, + FEED_DELAY, FEED_AMOUNT, MIN_FOOD, MAX_FOOD, + SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, SOIL_DRY, GAME_MODE, + MUSHROOMS, LEAF_DECAY, GRASS_SPREAD, MYCELIUM_SPREAD, VINE_GROWTH, + SEND_CHAT, RECEIVE_CHAT, FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW, + TELE_LOC, SPAWN_LOC, POTION_SPLASH, + BLOCKED_CMDS, ALLOWED_CMDS, PRICE, BUYABLE, ENABLE_SHOP }; private DefaultFlag() { diff --git a/src/test/java/com/sk89q/worldguard/protection/ApplicableRegionSetTest.java b/src/test/java/com/sk89q/worldguard/protection/ApplicableRegionSetTest.java index 1480d640..cb06ce1b 100644 --- a/src/test/java/com/sk89q/worldguard/protection/ApplicableRegionSetTest.java +++ b/src/test/java/com/sk89q/worldguard/protection/ApplicableRegionSetTest.java @@ -73,24 +73,25 @@ public void testWildernessBuildWithRegion() { } @Test - public void testFlags() { + public void testWildernessFlags() { MockApplicableRegionSet mock = new MockApplicableRegionSet(); LocalPlayer player = mock.createPlayer(); ApplicableRegionSet set = mock.getApplicableSet(); - assertThat(set.testState(player, DefaultFlag.PVP), is(true)); - assertThat(set.testState(player, DefaultFlag.MOB_DAMAGE), is(true)); + assertThat(set.testState(player, DefaultFlag.MOB_DAMAGE), is(true)); assertThat(set.testState(player, DefaultFlag.ENTRY), is(true)); assertThat(set.testState(player, DefaultFlag.EXIT), is(true)); - assertThat(set.testState(player, DefaultFlag.CHEST_ACCESS), is(true)); - assertThat(set.testState(player, DefaultFlag.SLEEP), is(true)); - assertThat(set.testState(player, DefaultFlag.TNT), is(true)); assertThat(set.testState(player, DefaultFlag.LEAF_DECAY), is(true)); assertThat(set.testState(player, DefaultFlag.RECEIVE_CHAT), is(true)); assertThat(set.testState(player, DefaultFlag.SEND_CHAT), is(true)); assertThat(set.testState(player, DefaultFlag.INVINCIBILITY), is(false)); + + assertThat(set.testBuild(player, DefaultFlag.CHEST_ACCESS), is(true)); + assertThat(set.testBuild(player, DefaultFlag.SLEEP), is(true)); + assertThat(set.testBuild(player, DefaultFlag.TNT), is(true)); + assertThat(set.testBuild(player, DefaultFlag.PVP), is(true)); } @Test @@ -102,18 +103,19 @@ public void testWildernessFlagsWithGlobalRegion() { ProtectedRegion global = mock.global(); ApplicableRegionSet set = mock.getApplicableSet(); - assertThat(set.testState(player, DefaultFlag.PVP), is(true)); - assertThat(set.testState(player, DefaultFlag.MOB_DAMAGE), is(true)); + assertThat(set.testState(player, DefaultFlag.MOB_DAMAGE), is(true)); assertThat(set.testState(player, DefaultFlag.ENTRY), is(true)); assertThat(set.testState(player, DefaultFlag.EXIT), is(true)); - assertThat(set.testState(player, DefaultFlag.CHEST_ACCESS), is(true)); - assertThat(set.testState(player, DefaultFlag.SLEEP), is(true)); - assertThat(set.testState(player, DefaultFlag.TNT), is(true)); assertThat(set.testState(player, DefaultFlag.LEAF_DECAY), is(true)); assertThat(set.testState(player, DefaultFlag.RECEIVE_CHAT), is(true)); assertThat(set.testState(player, DefaultFlag.SEND_CHAT), is(true)); assertThat(set.testState(player, DefaultFlag.INVINCIBILITY), is(false)); + + assertThat(set.testBuild(player, DefaultFlag.CHEST_ACCESS), is(true)); + assertThat(set.testBuild(player, DefaultFlag.SLEEP), is(true)); + assertThat(set.testBuild(player, DefaultFlag.TNT), is(true)); + assertThat(set.testBuild(player, DefaultFlag.PVP), is(true)); } @Test @@ -127,18 +129,32 @@ public void testFlagsWithRegion() { region.getMembers().addPlayer(member); ApplicableRegionSet set = mock.getApplicableSet(); + + assertThat(set.testState(member, DefaultFlag.MOB_DAMAGE), is(true)); assertThat(set.testState(member, DefaultFlag.ENTRY), is(true)); assertThat(set.testState(member, DefaultFlag.EXIT), is(true)); assertThat(set.testState(member, DefaultFlag.LEAF_DECAY), is(true)); assertThat(set.testState(member, DefaultFlag.RECEIVE_CHAT), is(true)); assertThat(set.testState(member, DefaultFlag.SEND_CHAT), is(true)); assertThat(set.testState(member, DefaultFlag.INVINCIBILITY), is(false)); + + assertThat(set.testBuild(member, DefaultFlag.CHEST_ACCESS), is(true)); + assertThat(set.testBuild(member, DefaultFlag.SLEEP), is(true)); + assertThat(set.testBuild(member, DefaultFlag.TNT), is(true)); + assertThat(set.testBuild(member, DefaultFlag.PVP), is(true)); + + assertThat(set.testState(nonMember, DefaultFlag.MOB_DAMAGE), is(true)); assertThat(set.testState(nonMember, DefaultFlag.ENTRY), is(true)); assertThat(set.testState(nonMember, DefaultFlag.EXIT), is(true)); assertThat(set.testState(nonMember, DefaultFlag.LEAF_DECAY), is(true)); assertThat(set.testState(nonMember, DefaultFlag.RECEIVE_CHAT), is(true)); assertThat(set.testState(nonMember, DefaultFlag.SEND_CHAT), is(true)); assertThat(set.testState(nonMember, DefaultFlag.INVINCIBILITY), is(false)); + + assertThat(set.testBuild(nonMember, DefaultFlag.CHEST_ACCESS), is(false)); + assertThat(set.testBuild(nonMember, DefaultFlag.SLEEP), is(false)); + assertThat(set.testBuild(nonMember, DefaultFlag.TNT), is(false)); + assertThat(set.testBuild(nonMember, DefaultFlag.PVP), is(false)); } @Test diff --git a/src/test/java/com/sk89q/worldguard/protection/FlagValueCalculatorTest.java b/src/test/java/com/sk89q/worldguard/protection/FlagValueCalculatorTest.java index 117f90eb..b5c3601e 100644 --- a/src/test/java/com/sk89q/worldguard/protection/FlagValueCalculatorTest.java +++ b/src/test/java/com/sk89q/worldguard/protection/FlagValueCalculatorTest.java @@ -277,678 +277,6 @@ public void testGetMembershipThirdPriorityLower() throws Exception { // ======================================================================== // ======================================================================== - @Test - public void testQueryPermissionWildernessDefaults() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer player = mock.createPlayer(); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(player, flag1), is((State) null)); - assertThat(result.queryPermission(player, flag2), is(State.ALLOW)); - } - - @Test - public void testQueryPermissionWildernessDefaultsWithGlobalRegion() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer player = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(player, flag1), is((State) null)); - assertThat(result.queryPermission(player, flag2), is(State.ALLOW)); - } - - @Test - public void testQueryPermissionWildernessDefaultsWithGlobalRegionOverride() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer player = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.setFlag(flag1, State.ALLOW); - global.setFlag(flag2, State.DENY); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(player, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(player, flag2), is(State.DENY)); - assertThat(result.queryPermission(player, flag1, flag2), is(State.DENY)); - } - - @Test - public void testQueryPermissionWildernessWithGlobalRegion() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", false); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion region = mock.global(); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1), is((State) null)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWildernessWithGlobalRegionOverride() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", false); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion region = mock.global(); - region.setFlag(flag2, State.ALLOW); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1), is((State) null)); - assertThat(result.queryPermission(nonMember, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithPassthroughRegion() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.PASSTHROUGH, State.ALLOW); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is((State) null)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1), is((State) null)); - assertThat(result.queryPermission(nonMember, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithPassthroughRegionAndFlagAllow() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion region = mock.add(0); - region.setFlag(flag1, State.ALLOW); - region.setFlag(DefaultFlag.PASSTHROUGH, State.ALLOW); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithPassthroughRegionAndFlagDeny() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", false); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion region = mock.add(0); - region.setFlag(flag1, State.DENY); - region.setFlag(DefaultFlag.PASSTHROUGH, State.ALLOW); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.DENY)); - assertThat(result.queryPermission(member, flag2), is((State) null)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(member), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithPassthroughRegionAndFlagDenyAndRegionGroups() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", false); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion region = mock.add(0); - region.setFlag(flag1, State.DENY); - region.setFlag(flag1.getRegionGroupFlag(), RegionGroup.MEMBERS); - region.setFlag(DefaultFlag.PASSTHROUGH, State.ALLOW); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.DENY)); - assertThat(result.queryPermission(member, flag2), is((State) null)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(member), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1), is((State) null)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithRegion() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion region = mock.add(0); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1), is((State) null)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithRegionAndFlagAllow() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion region = mock.add(0); - region.getMembers().addPlayer(member); - region.setFlag(flag1, State.ALLOW); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithRegionAndFlagDeny() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion region = mock.add(0); - region.getMembers().addPlayer(member); - region.setFlag(flag1, State.DENY); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.DENY)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(member), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithRegionAndFlagDenyAndRegionGroup() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion region = mock.add(0); - region.getMembers().addPlayer(member); - region.setFlag(flag1, State.DENY); - region.setFlag(flag1.getRegionGroupFlag(), RegionGroup.NON_MEMBERS); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.DENY)); - } - - @Test - public void testQueryPermissionWithRegionAndGlobalRegion() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - - ProtectedRegion region = mock.add(0); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1), is((State) null)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithRegionAndGlobalRegionDeny() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.setFlag(flag1, State.DENY); - - ProtectedRegion region = mock.add(0); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.DENY)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag1), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.DENY)); - } - - @Test - public void testQueryPermissionWithRegionAndGlobalRegionAllow() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.setFlag(flag1, State.ALLOW); - - ProtectedRegion region = mock.add(0); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithRegionAllowAndGlobalRegionDeny() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.setFlag(flag1, State.DENY); - - ProtectedRegion region = mock.add(0); - region.setFlag(flag1, State.ALLOW); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.ALLOW)); - } - - @Test - public void testQueryPermissionWithRegionAllowAndGlobalRegionDenyDifferentFlags() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.setFlag(flag1, State.DENY); - - ProtectedRegion region = mock.add(0); - region.setFlag(flag2, State.ALLOW); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.DENY)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag1), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.DENY)); - } - - @Test - public void testQueryPermissionWithPassthroughRegionAllowAndGlobalRegionDenyWithRegionGroup() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", false); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.setFlag(flag1, State.DENY); - - ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.PASSTHROUGH, State.ALLOW); - region.setFlag(flag1, State.ALLOW); - region.setFlag(flag1.getRegionGroupFlag(), RegionGroup.NON_MEMBERS); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.DENY)); - assertThat(result.queryPermission(member, flag2), is((State) null)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.ALLOW)); - } - - @Test - public void testQueryPermissionWithRegionAllowAndGlobalRegionDenyWithRegionGroup() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.setFlag(flag1, State.DENY); - - ProtectedRegion region = mock.add(0); - region.setFlag(flag1, State.ALLOW); - region.setFlag(flag1.getRegionGroupFlag(), RegionGroup.NON_MEMBERS); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.DENY)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.ALLOW)); - } - - @Test - public void testQueryPermissionWithRegionAllowAndGlobalRegionDenyDifferentFlagsWithRegionGroup() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer member = mock.createPlayer(); - LocalPlayer nonMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.setFlag(flag1, State.DENY); - - ProtectedRegion region = mock.add(0); - region.setFlag(flag2, State.ALLOW); - region.setFlag(flag2.getRegionGroupFlag(), RegionGroup.MEMBERS); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.DENY)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag1), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.DENY)); - } - - @Test - public void testQueryPermissionWithGlobalRegionMembership() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer nonMember = mock.createPlayer(); - LocalPlayer globalMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.getMembers().addPlayer(globalMember); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(globalMember, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(globalMember, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(globalMember, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(globalMember), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1), is((State) null)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithGlobalRegionMembershipAndRegion() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer nonMember = mock.createPlayer(); - LocalPlayer member = mock.createPlayer(); - LocalPlayer globalMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.getMembers().addPlayer(globalMember); - - ProtectedRegion region = mock.add(0); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member), is(State.ALLOW)); - assertThat(result.queryPermission(globalMember, flag1), is((State) null)); - assertThat(result.queryPermission(globalMember, flag2), is((State) null)); - assertThat(result.queryPermission(globalMember, flag1, flag2), is((State) null)); - assertThat(result.queryPermission(globalMember), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1), is((State) null)); - assertThat(result.queryPermission(nonMember, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is((State) null)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithGlobalRegionMembershipAndRegionGlobalFlag() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer nonMember = mock.createPlayer(); - LocalPlayer member = mock.createPlayer(); - LocalPlayer globalMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.setFlag(flag2, State.DENY); - global.getMembers().addPlayer(globalMember); - - ProtectedRegion region = mock.add(0); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.DENY)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(member), is(State.ALLOW)); - assertThat(result.queryPermission(globalMember, flag1), is((State) null)); - assertThat(result.queryPermission(globalMember, flag2), is(State.DENY)); - assertThat(result.queryPermission(globalMember, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(globalMember), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1), is((State) null)); - assertThat(result.queryPermission(nonMember, flag2), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithGlobalRegionMembershipAndRegionGlobalFlagRegionOverride() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer nonMember = mock.createPlayer(); - LocalPlayer member = mock.createPlayer(); - LocalPlayer globalMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.setFlag(flag2, State.DENY); - global.getMembers().addPlayer(globalMember); - - ProtectedRegion region = mock.add(0); - region.setFlag(flag2, State.ALLOW); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member), is(State.ALLOW)); - assertThat(result.queryPermission(globalMember, flag1), is((State) null)); - assertThat(result.queryPermission(globalMember, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(globalMember, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(globalMember), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1), is((State) null)); - assertThat(result.queryPermission(nonMember, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - @Test - public void testQueryPermissionWithGlobalRegionMembershipAndRegionGlobalFlagRegionOverrideAndRegionGroups() throws Exception { - MockApplicableRegionSet mock = new MockApplicableRegionSet(); - - StateFlag flag1 = new StateFlag("test1", false); - StateFlag flag2 = new StateFlag("test2", true); - - LocalPlayer nonMember = mock.createPlayer(); - LocalPlayer member = mock.createPlayer(); - LocalPlayer globalMember = mock.createPlayer(); - - ProtectedRegion global = mock.global(); - global.setFlag(flag2, State.DENY); - global.getMembers().addPlayer(globalMember); - - ProtectedRegion region = mock.add(0); - region.setFlag(flag2, State.ALLOW); - region.setFlag(flag2.getRegionGroupFlag(), RegionGroup.MEMBERS); - region.getMembers().addPlayer(member); - - FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryPermission(member, flag1), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member, flag1, flag2), is(State.ALLOW)); - assertThat(result.queryPermission(member), is(State.ALLOW)); - assertThat(result.queryPermission(globalMember, flag1), is((State) null)); - assertThat(result.queryPermission(globalMember, flag2), is(State.DENY)); - assertThat(result.queryPermission(globalMember, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(globalMember), is((State) null)); - assertThat(result.queryPermission(nonMember, flag1), is((State) null)); - assertThat(result.queryPermission(nonMember, flag2), is(State.DENY)); - assertThat(result.queryPermission(nonMember, flag1, flag2), is(State.DENY)); - assertThat(result.queryPermission(nonMember), is((State) null)); - } - - // ======================================================================== - // ======================================================================== - @Test public void testQueryStateWilderness() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); @@ -958,7 +286,7 @@ public void testQueryStateWilderness() throws Exception { FlagValueCalculator result = mock.getFlagCalculator(); assertThat(result.queryState(null, flag1), is((State) null)); - assertThat(result.queryState(null, flag2), is((State) null)); + assertThat(result.queryState(null, flag2), is(State.ALLOW)); } // ======================================================================== @@ -968,27 +296,33 @@ public void testQueryStateWilderness() throws Exception { public void testQueryValueSingleRegion() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StateFlag flag1 = new StateFlag("test1", false); + StateFlag flag2 = new StateFlag("test2", false); + ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.PVP, State.DENY); + region.setFlag(flag2, State.DENY); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryValue(null, DefaultFlag.LIGHTER), is((State) null)); - assertThat(result.queryValue(null, DefaultFlag.PVP), is(State.DENY)); + assertThat(result.queryValue(null, flag1), is((State) null)); + assertThat(result.queryValue(null, flag2), is(State.DENY)); } @Test public void testQueryValueDenyOverridesAllow() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StateFlag flag1 = new StateFlag("test1", false); + StateFlag flag2 = new StateFlag("test2", false); + ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.PVP, State.DENY); + region.setFlag(flag2, State.DENY); region = mock.add(0); - region.setFlag(DefaultFlag.PVP, State.ALLOW); + region.setFlag(flag2, State.ALLOW); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryValue(null, DefaultFlag.LIGHTER), is((State) null)); - assertThat(result.queryValue(null, DefaultFlag.PVP), is(State.DENY)); + assertThat(result.queryValue(null, flag1), is((State) null)); + assertThat(result.queryValue(null, flag2), is(State.DENY)); } @Test @@ -997,45 +331,56 @@ public void testQueryValueAllowOverridesNone() throws Exception { ProtectedRegion region = mock.add(0); + StateFlag flag1 = new StateFlag("test1", false); + StateFlag flag2 = new StateFlag("test2", false); + region = mock.add(0); - region.setFlag(DefaultFlag.PVP, State.ALLOW); + region.setFlag(flag2, State.ALLOW); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryValue(null, DefaultFlag.LIGHTER), is((State) null)); - assertThat(result.queryValue(null, DefaultFlag.PVP), is(State.ALLOW)); + assertThat(result.queryValue(null, flag1), is((State) null)); + assertThat(result.queryValue(null, flag2), is(State.ALLOW)); } @Test public void testQueryValueMultipleFlags() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StateFlag flag1 = new StateFlag("test1", false); + StateFlag flag2 = new StateFlag("test2", false); + StateFlag flag3 = new StateFlag("test3", false); + ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.LIGHTER, State.DENY); - region.setFlag(DefaultFlag.PVP, State.ALLOW); + region.setFlag(flag1, State.DENY); + region.setFlag(flag2, State.ALLOW); region = mock.add(0); - region.setFlag(DefaultFlag.PVP, State.DENY); + region.setFlag(flag2, State.DENY); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryValue(null, DefaultFlag.LIGHTER), is(State.DENY)); - assertThat(result.queryValue(null, DefaultFlag.PVP), is(State.DENY)); - assertThat(result.queryValue(null, DefaultFlag.LAVA_FIRE), is((State) null)); + assertThat(result.queryValue(null, flag1), is(State.DENY)); + assertThat(result.queryValue(null, flag2), is(State.DENY)); + assertThat(result.queryValue(null, flag3), is((State) null)); } @Test public void testQueryValueStringFlag() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + StateFlag flag1 = new StateFlag("test1", false); + ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); + region.setFlag(stringFlag1, "test1"); region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); + region.setFlag(stringFlag1, "test2"); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryValue(null, DefaultFlag.FAREWELL_MESSAGE), isOneOf("test1", "test2")); - assertThat(result.queryValue(null, DefaultFlag.GREET_MESSAGE), is((String) null)); - assertThat(result.queryValue(null, DefaultFlag.LAVA_FIRE), is((State) null)); + assertThat(result.queryValue(null, stringFlag1), isOneOf("test1", "test2")); + assertThat(result.queryValue(null, stringFlag2), is((String) null)); + assertThat(result.queryValue(null, flag1), is((State) null)); } @Test @@ -1047,7 +392,7 @@ public void testQueryValueEmptyGlobalRegion() throws Exception { ProtectedRegion global = mock.global(); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.queryValue(null, flag), is((State) null)); + assertThat(result.queryValue(null, flag), is(State.ALLOW)); } @Test @@ -1160,6 +505,434 @@ public void testQueryValueStringFlagWithEverything() throws Exception { assertThat(result.queryValue(member, flag), is("beep beep")); } + @Test + public void testQueryValueBuildFlagWilderness() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagWildernessAndGlobalRegion() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagWildernessAndGlobalRegionDeny() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + global.setFlag(DefaultFlag.BUILD, State.DENY); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is(State.DENY)); + } + + @Test + public void testQueryValueBuildFlagWildernessAndGlobalRegionAllow() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + global.setFlag(DefaultFlag.BUILD, State.ALLOW); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagWildernessAndGlobalRegionMembership() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer member = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + global.getMembers().addPlayer(member); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(member, DefaultFlag.BUILD), is(State.ALLOW)); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + } + + @Test + public void testQueryValueBuildFlagWildernessAndGlobalRegionMembershipAndDeny() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer member = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + global.getMembers().addPlayer(member); + global.setFlag(DefaultFlag.BUILD, State.DENY); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(member, DefaultFlag.BUILD), is(State.DENY)); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is(State.DENY)); + } + + @Test + public void testQueryValueBuildFlagWildernessAndGlobalRegionMembershipAndAllow() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer member = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + global.getMembers().addPlayer(member); + global.setFlag(DefaultFlag.BUILD, State.ALLOW); + + // Cannot set ALLOW on BUILD + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(member, DefaultFlag.BUILD), is(State.ALLOW)); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + } + + @Test + public void testQueryValueBuildFlagRegion() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer member = mock.createPlayer(); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(member); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(member, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlapping() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberOne); + region.getMembers().addPlayer(memberBoth); + + region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingDifferingPriority() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberOne); + region.getMembers().addPlayer(memberBoth); + region.setPriority(10); + + region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is(State.ALLOW)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingInheritanceFromParent() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion parent = mock.add(0); + parent.getMembers().addPlayer(memberOne); + parent.getMembers().addPlayer(memberBoth); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + region.setParent(parent); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is(State.ALLOW)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingInheritanceFromChild() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion parent = mock.add(0); + parent.getMembers().addPlayer(memberBoth); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + region.getMembers().addPlayer(memberOne); + region.setParent(parent); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is(State.ALLOW)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingInheritanceFromChildAndPriority() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion parent = mock.add(0); + parent.getMembers().addPlayer(memberBoth); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + region.getMembers().addPlayer(memberOne); + region.setParent(parent); + + ProtectedRegion priority = mock.add(10); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is((State) null)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingInheritanceFromChildAndPriorityPassthrough() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion parent = mock.add(0); + parent.getMembers().addPlayer(memberBoth); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + region.getMembers().addPlayer(memberOne); + region.setParent(parent); + + ProtectedRegion priority = mock.add(10); + priority.setFlag(DefaultFlag.PASSTHROUGH, State.ALLOW); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is(State.ALLOW)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingAndGlobalRegion() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberOne); + region.getMembers().addPlayer(memberBoth); + + region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingAndGlobalRegionDenyRegionOverride() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + global.setFlag(DefaultFlag.BUILD, State.DENY); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberOne); + region.getMembers().addPlayer(memberBoth); + + region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + region.setFlag(DefaultFlag.BUILD, State.ALLOW); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is(State.ALLOW)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is(State.ALLOW)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingAndGlobalRegionDenyRegionOverrideDenyAndAllow() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + global.setFlag(DefaultFlag.BUILD, State.DENY); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberOne); + region.getMembers().addPlayer(memberBoth); + region.setFlag(DefaultFlag.BUILD, State.DENY); + + region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + region.setFlag(DefaultFlag.BUILD, State.ALLOW); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is(State.DENY)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is(State.DENY)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.DENY)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingAndGlobalRegionAllow() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + global.setFlag(DefaultFlag.BUILD, State.ALLOW); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberOne); + region.getMembers().addPlayer(memberBoth); + + region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + + // Disable setting ALLOW for safety reasons + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingAndGlobalRegionMembership() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer globalMember = mock.createPlayer(); + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + global.getMembers().addPlayer(globalMember); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberOne); + region.getMembers().addPlayer(memberBoth); + + region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(globalMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.ALLOW)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingAndGlobalRegionMembershipAndGlobalDeny() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer globalMember = mock.createPlayer(); + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + global.getMembers().addPlayer(globalMember); + global.setFlag(DefaultFlag.BUILD, State.DENY); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberOne); + region.getMembers().addPlayer(memberBoth); + + region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(globalMember, DefaultFlag.BUILD), is(State.DENY)); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is(State.DENY)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is(State.DENY)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.DENY)); + } + + @Test + public void testQueryValueBuildFlagRegionsOverlappingAndGlobalRegionMembershipAndGlobalAllow() throws Exception { + MockApplicableRegionSet mock = new MockApplicableRegionSet(); + + LocalPlayer globalMember = mock.createPlayer(); + LocalPlayer nonMember = mock.createPlayer(); + LocalPlayer memberOne = mock.createPlayer(); + LocalPlayer memberBoth = mock.createPlayer(); + + ProtectedRegion global = mock.global(); + global.getMembers().addPlayer(globalMember); + global.setFlag(DefaultFlag.BUILD, State.ALLOW); + + ProtectedRegion region = mock.add(0); + region.getMembers().addPlayer(memberOne); + region.getMembers().addPlayer(memberBoth); + + region = mock.add(0); + region.getMembers().addPlayer(memberBoth); + + FlagValueCalculator result = mock.getFlagCalculator(); + assertThat(result.queryValue(globalMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(nonMember, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberOne, DefaultFlag.BUILD), is((State) null)); + assertThat(result.queryValue(memberBoth, DefaultFlag.BUILD), is(State.ALLOW)); + } + // ======================================================================== // ======================================================================== @@ -1171,15 +944,18 @@ public void testQueryAllValuesTwoWithSamePriority() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); + region.setFlag(stringFlag1, "test1"); region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); + region.setFlag(stringFlag1, "test2"); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(copyOf(result.queryAllValues(null, DefaultFlag.FAREWELL_MESSAGE)), equalTo(of("test1", "test2"))); - assertThat(result.queryAllValues(null, DefaultFlag.GREET_MESSAGE), is(Matchers.empty())); + assertThat(copyOf(result.queryAllValues(null, stringFlag1)), equalTo(of("test1", "test2"))); + assertThat(result.queryAllValues(null, stringFlag2), is(Matchers.empty())); } @Test @@ -1190,15 +966,18 @@ public void testQueryAllValuesTwoWithDuplicateFlagValues() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test"); + region.setFlag(stringFlag1, "test"); region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test"); + region.setFlag(stringFlag1, "test"); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(copyOf(result.queryAllValues(null, DefaultFlag.FAREWELL_MESSAGE)), equalTo(of("test", "test"))); - assertThat(result.queryAllValues(null, DefaultFlag.GREET_MESSAGE), is(Matchers.empty())); + assertThat(copyOf(result.queryAllValues(null, stringFlag1)), equalTo(of("test", "test"))); + assertThat(result.queryAllValues(null, stringFlag2), is(Matchers.empty())); } @Test @@ -1209,15 +988,18 @@ public void testQueryAllValuesWithHigherPriority() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion region = mock.add(10); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); + region.setFlag(stringFlag1, "test1"); region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); + region.setFlag(stringFlag1, "test2"); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(copyOf(result.queryAllValues(null, DefaultFlag.FAREWELL_MESSAGE)), equalTo(of("test1"))); - assertThat(result.queryAllValues(null, DefaultFlag.GREET_MESSAGE), is(Matchers.empty())); + assertThat(copyOf(result.queryAllValues(null, stringFlag1)), equalTo(of("test1"))); + assertThat(result.queryAllValues(null, stringFlag2), is(Matchers.empty())); } @Test @@ -1228,18 +1010,21 @@ public void testQueryAllValuesWithTwoElevatedPriorities() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion region = mock.add(10); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test3"); + region.setFlag(stringFlag1, "test3"); region = mock.add(10); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); + region.setFlag(stringFlag1, "test1"); region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); + region.setFlag(stringFlag1, "test2"); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(copyOf(result.queryAllValues(null, DefaultFlag.FAREWELL_MESSAGE)), equalTo(of("test1", "test3"))); - assertThat(result.queryAllValues(null, DefaultFlag.GREET_MESSAGE), is(Matchers.empty())); + assertThat(copyOf(result.queryAllValues(null, stringFlag1)), equalTo(of("test1", "test3"))); + assertThat(result.queryAllValues(null, stringFlag2), is(Matchers.empty())); } @Test @@ -1250,19 +1035,22 @@ public void testQueryAllValuesParentChildWithSamePriority() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion parent1 = mock.add(10); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test3"); + parent1.setFlag(stringFlag1, "test3"); ProtectedRegion region = mock.add(10); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); + region.setFlag(stringFlag1, "test1"); region.setParent(parent1); region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); + region.setFlag(stringFlag1, "test2"); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(copyOf(result.queryAllValues(null, DefaultFlag.FAREWELL_MESSAGE)), equalTo(of("test1"))); - assertThat(result.queryAllValues(null, DefaultFlag.GREET_MESSAGE), is(Matchers.empty())); + assertThat(copyOf(result.queryAllValues(null, stringFlag1)), equalTo(of("test1"))); + assertThat(result.queryAllValues(null, stringFlag2), is(Matchers.empty())); } @Test @@ -1273,19 +1061,22 @@ public void testQueryAllValuesParentWithHigherPriority() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion parent1 = mock.add(20); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test3"); + parent1.setFlag(stringFlag1, "test3"); ProtectedRegion region = mock.add(10); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); + region.setFlag(stringFlag1, "test1"); region.setParent(parent1); region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); + region.setFlag(stringFlag1, "test2"); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(copyOf(result.queryAllValues(null, DefaultFlag.FAREWELL_MESSAGE)), equalTo(of("test3"))); - assertThat(result.queryAllValues(null, DefaultFlag.GREET_MESSAGE), is(Matchers.empty())); + assertThat(copyOf(result.queryAllValues(null, stringFlag1)), equalTo(of("test3"))); + assertThat(result.queryAllValues(null, stringFlag2), is(Matchers.empty())); } @Test @@ -1296,19 +1087,22 @@ public void testQueryAllValuesParentWithLowerPriority() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion parent1 = mock.add(5); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test3"); + parent1.setFlag(stringFlag1, "test3"); ProtectedRegion region = mock.add(10); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); + region.setFlag(stringFlag1, "test1"); region.setParent(parent1); region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); + region.setFlag(stringFlag1, "test2"); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(copyOf(result.queryAllValues(null, DefaultFlag.FAREWELL_MESSAGE)), equalTo(of("test1"))); - assertThat(result.queryAllValues(null, DefaultFlag.GREET_MESSAGE), is(Matchers.empty())); + assertThat(copyOf(result.queryAllValues(null, stringFlag1)), equalTo(of("test1"))); + assertThat(result.queryAllValues(null, stringFlag2), is(Matchers.empty())); } @Test @@ -1319,19 +1113,22 @@ public void testQueryAllValuesThirdRegionWithHigherPriorityThanParentChild() thr MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion parent1 = mock.add(5); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test3"); + parent1.setFlag(stringFlag1, "test3"); ProtectedRegion region = mock.add(10); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); + region.setFlag(stringFlag1, "test1"); region.setParent(parent1); region = mock.add(20); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); + region.setFlag(stringFlag1, "test2"); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(copyOf(result.queryAllValues(null, DefaultFlag.FAREWELL_MESSAGE)), equalTo(of("test2"))); - assertThat(result.queryAllValues(null, DefaultFlag.GREET_MESSAGE), is(Matchers.empty())); + assertThat(copyOf(result.queryAllValues(null, stringFlag1)), equalTo(of("test2"))); + assertThat(result.queryAllValues(null, stringFlag2), is(Matchers.empty())); } @Test @@ -1342,22 +1139,25 @@ public void testQueryAllValuesParentsAndInheritance() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion parent1 = mock.add(5); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); + parent1.setFlag(stringFlag1, "test1"); ProtectedRegion region = mock.add(20); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); + region.setFlag(stringFlag1, "test2"); region.setParent(parent1); ProtectedRegion parent2 = mock.add(6); - parent2.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test3"); + parent2.setFlag(stringFlag1, "test3"); region = mock.add(20); region.setParent(parent2); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(copyOf(result.queryAllValues(null, DefaultFlag.FAREWELL_MESSAGE)), equalTo(of("test2", "test3"))); - assertThat(result.queryAllValues(null, DefaultFlag.GREET_MESSAGE), is(Matchers.empty())); + assertThat(copyOf(result.queryAllValues(null, stringFlag1)), equalTo(of("test2", "test3"))); + assertThat(result.queryAllValues(null, stringFlag2), is(Matchers.empty())); } @Test @@ -1368,21 +1168,25 @@ public void testQueryAllValuesParentsAndInheritanceHighPriorityAndNoFlag() throw MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + StateFlag flag1 = new StateFlag("test1", false); + ProtectedRegion parent1 = mock.add(5); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); + parent1.setFlag(stringFlag1, "test1"); ProtectedRegion region = mock.add(20); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); + region.setFlag(stringFlag1, "test2"); region.setParent(parent1); ProtectedRegion parent2 = mock.add(6); - parent2.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test3"); + parent2.setFlag(stringFlag1, "test3"); region = mock.add(30); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(copyOf(result.queryAllValues(null, DefaultFlag.FAREWELL_MESSAGE)), equalTo(of("test2"))); - assertThat(result.queryAllValues(null, DefaultFlag.GREET_MESSAGE), is(Matchers.empty())); + assertThat(copyOf(result.queryAllValues(null, stringFlag1)), equalTo(of("test2"))); + assertThat(result.queryAllValues(null, stringFlag2), is(Matchers.empty())); } @Test @@ -1393,21 +1197,25 @@ public void testQueryAllValuesParentWithSamePriorityAsHighest() throws Exception MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + StateFlag flag1 = new StateFlag("test1", false); + ProtectedRegion parent1 = mock.add(30); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); + parent1.setFlag(stringFlag1, "test1"); ProtectedRegion region = mock.add(20); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); + region.setFlag(stringFlag1, "test2"); region.setParent(parent1); ProtectedRegion parent2 = mock.add(6); - parent2.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test3"); + parent2.setFlag(stringFlag1, "test3"); region = mock.add(30); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(copyOf(result.queryAllValues(null, DefaultFlag.FAREWELL_MESSAGE)), equalTo(of("test1"))); - assertThat(result.queryAllValues(null, DefaultFlag.GREET_MESSAGE), is(Matchers.empty())); + assertThat(copyOf(result.queryAllValues(null, stringFlag1)), equalTo(of("test1"))); + assertThat(result.queryAllValues(null, stringFlag2), is(Matchers.empty())); } // ======================================================================== @@ -1444,13 +1252,16 @@ public void testGetEffectiveFlagSingleRegion() throws Exception { // Single region // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1461,15 +1272,18 @@ public void testGetEffectiveFlagWithALLGroupAndNonMember() throws Exception { // Single region with group ALL and non-member player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); LocalPlayer player = mock.createPlayer(); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1480,13 +1294,16 @@ public void testGetEffectiveFlagWithALLGroupAndNull() throws Exception { // Single region with group ALL and null player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1495,17 +1312,20 @@ public void testGetEffectiveFlagNONMEMBERSGroupNonMember() throws Exception { // Single region with group NON-MEMBERS and non-member player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.NON_MEMBERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.NON_MEMBERS); LocalPlayer player = mock.createPlayer(); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1514,15 +1334,18 @@ public void testGetEffectiveFlagNONMEMBERSGroupNull() throws Exception { // Single region with group NON-MEMBERS and null player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.NON_MEMBERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.NON_MEMBERS); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1531,17 +1354,20 @@ public void testGetEffectiveFlagNONOWNERSGroupNonMember() throws Exception { // Single region with group NON-OWNERS and non-member player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.NON_OWNERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.NON_OWNERS); LocalPlayer player = mock.createPlayer(); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1550,17 +1376,20 @@ public void testGetEffectiveFlagMEMBERSGroupNonMember() throws Exception { // Single region with group MEMBERS and non-member player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.MEMBERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.MEMBERS); LocalPlayer player = mock.createPlayer(); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo(null)); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1569,15 +1398,18 @@ public void testGetEffectiveFlagMEMBERSGroupNull() throws Exception { // Single region with group MEMBERS and null player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.MEMBERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.MEMBERS); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo(null)); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1586,18 +1418,21 @@ public void testGetEffectiveFlagMEMBERSGroupMember() throws Exception { // Single region with group MEMBERS and member player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.MEMBERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.MEMBERS); LocalPlayer player = mock.createPlayer(); region.getMembers().addPlayer(player); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1606,18 +1441,21 @@ public void testGetEffectiveFlagMEMBERSGroupOwner() throws Exception { // Single region with group MEMBERS and owner player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.MEMBERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.MEMBERS); LocalPlayer player = mock.createPlayer(); region.getOwners().addPlayer(player); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1626,18 +1464,21 @@ public void testGetEffectiveFlagOWNERSGroupOwner() throws Exception { // Single region with group OWNERS and owner player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.OWNERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.OWNERS); LocalPlayer player = mock.createPlayer(); region.getOwners().addPlayer(player); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1646,18 +1487,21 @@ public void testGetEffectiveFlagOWNERSGroupMember() throws Exception { // Single region with group OWNERS and member player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.OWNERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.OWNERS); LocalPlayer player = mock.createPlayer(); region.getMembers().addPlayer(player); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo(null)); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1666,18 +1510,21 @@ public void testGetEffectiveFlagNONOWNERSGroupOwner() throws Exception { // Single region with group NON-OWNERS and owner player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.NON_OWNERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.NON_OWNERS); LocalPlayer player = mock.createPlayer(); region.getOwners().addPlayer(player); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo(null)); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1688,16 +1535,19 @@ public void testGetEffectiveFlagNONMEMBERSGroupOwner() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.NON_MEMBERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.NON_MEMBERS); LocalPlayer player = mock.createPlayer(); region.getOwners().addPlayer(player); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo(null)); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1708,16 +1558,19 @@ public void testGetEffectiveFlagNONOWNERSGroupMember() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.NON_OWNERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.NON_OWNERS); LocalPlayer player = mock.createPlayer(); region.getMembers().addPlayer(player); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1726,17 +1579,20 @@ public void testGetEffectiveFlagNONOWNERSNonMember() throws Exception { // Single region with group NON-OWNERS and non-member player // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.NON_OWNERS); + region.setFlag(stringFlag1, "test1"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.NON_OWNERS); LocalPlayer player = mock.createPlayer(); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1745,11 +1601,14 @@ public void testGetEffectiveFlagThreeInheritance() throws Exception { // Three-level inheritance // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion parent1 = mock.add(0); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + parent1.setFlag(stringFlag1, "test1"); + parent1.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); ProtectedRegion parent2 = mock.add(0); parent2.setParent(parent1); @@ -1758,8 +1617,8 @@ public void testGetEffectiveFlagThreeInheritance() throws Exception { region.setParent(parent2); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("test1")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo("test1")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1768,23 +1627,26 @@ public void testGetEffectiveFlagThreeInheritanceMiddleOverride() throws Exceptio // Three-level inheritance, overridden on middle level // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion parent1 = mock.add(0); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + parent1.setFlag(stringFlag1, "test1"); + parent1.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); ProtectedRegion parent2 = mock.add(0); parent2.setParent(parent1); - parent2.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test2"); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + parent2.setFlag(stringFlag1, "test2"); + parent1.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); ProtectedRegion region = mock.add(0); region.setParent(parent2); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("test2")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo("test2")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1793,23 +1655,26 @@ public void testGetEffectiveFlagThreeInheritanceLastOverride() throws Exception // Three-level inheritance, overridden on last level // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion parent1 = mock.add(0); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test1"); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + parent1.setFlag(stringFlag1, "test1"); + parent1.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); ProtectedRegion parent2 = mock.add(0); parent2.setParent(parent1); ProtectedRegion region = mock.add(0); region.setParent(parent2); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "test3"); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + region.setFlag(stringFlag1, "test3"); + parent1.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("test3")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo("test3")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1818,15 +1683,18 @@ public void testGetEffectiveFlagInheritanceAndDifferingGroups() throws Exception // Three-level inheritance, overridden on last level // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion parent1 = mock.add(0); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "everyone"); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + parent1.setFlag(stringFlag1, "everyone"); + parent1.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); ProtectedRegion parent2 = mock.add(0); - parent2.setFlag(DefaultFlag.FAREWELL_MESSAGE, "members"); - parent2.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.MEMBERS); + parent2.setFlag(stringFlag1, "members"); + parent2.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.MEMBERS); parent2.setParent(parent1); ProtectedRegion region = mock.add(0); @@ -1838,10 +1706,10 @@ public void testGetEffectiveFlagInheritanceAndDifferingGroups() throws Exception LocalPlayer player2 = mock.createPlayer(); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player1), equalTo("members")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player2), equalTo("everyone")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("everyone")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player1), equalTo("members")); + assertThat(result.getEffectiveFlag(region, stringFlag1, player2), equalTo("everyone")); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo("everyone")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test @@ -1850,15 +1718,18 @@ public void testGetEffectiveFlagInheritanceAndDifferingGroupsMemberOnChild() thr // Three-level inheritance, overridden on last level // ==================================================================== + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + MockApplicableRegionSet mock = new MockApplicableRegionSet(); ProtectedRegion parent1 = mock.add(0); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "everyone"); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + parent1.setFlag(stringFlag1, "everyone"); + parent1.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); ProtectedRegion parent2 = mock.add(0); - parent2.setFlag(DefaultFlag.FAREWELL_MESSAGE, "members"); - parent2.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.MEMBERS); + parent2.setFlag(stringFlag1, "members"); + parent2.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.MEMBERS); parent2.setParent(parent1); ProtectedRegion region = mock.add(0); @@ -1870,23 +1741,26 @@ public void testGetEffectiveFlagInheritanceAndDifferingGroupsMemberOnChild() thr LocalPlayer player2 = mock.createPlayer(); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player1), equalTo("members")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player2), equalTo("everyone")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("everyone")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player1), equalTo("members")); + assertThat(result.getEffectiveFlag(region, stringFlag1, player2), equalTo("everyone")); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo("everyone")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test public void testGetEffectiveFlagInheritanceAndDifferingGroupsMemberOnParent() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion parent1 = mock.add(0); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "everyone"); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + parent1.setFlag(stringFlag1, "everyone"); + parent1.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); ProtectedRegion parent2 = mock.add(0); - parent2.setFlag(DefaultFlag.FAREWELL_MESSAGE, "members"); - parent2.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.MEMBERS); + parent2.setFlag(stringFlag1, "members"); + parent2.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.MEMBERS); parent2.setParent(parent1); ProtectedRegion region = mock.add(0); @@ -1898,26 +1772,29 @@ public void testGetEffectiveFlagInheritanceAndDifferingGroupsMemberOnParent() th LocalPlayer player2 = mock.createPlayer(); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player1), equalTo("members")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player2), equalTo("everyone")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("everyone")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player1), equalTo("members")); + assertThat(result.getEffectiveFlag(region, stringFlag1, player2), equalTo("everyone")); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo("everyone")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test public void testGetEffectiveFlagInheritanceAndDifferingGroupsMemberOnParentFlagOnBottom() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion parent1 = mock.add(0); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "everyone"); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + parent1.setFlag(stringFlag1, "everyone"); + parent1.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); ProtectedRegion parent2 = mock.add(0); parent2.setParent(parent1); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "members"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.MEMBERS); + region.setFlag(stringFlag1, "members"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.MEMBERS); region.setParent(parent2); LocalPlayer player1 = mock.createPlayer(); @@ -1926,26 +1803,29 @@ public void testGetEffectiveFlagInheritanceAndDifferingGroupsMemberOnParentFlagO LocalPlayer player2 = mock.createPlayer(); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player1), equalTo("members")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player2), equalTo("everyone")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("everyone")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player1), equalTo("members")); + assertThat(result.getEffectiveFlag(region, stringFlag1, player2), equalTo("everyone")); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo("everyone")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test public void testGetEffectiveFlagInheritanceAndDifferingGroupsMemberOnParentFlagOnBottomGroupOutside() throws Exception { MockApplicableRegionSet mock = new MockApplicableRegionSet(); + StringFlag stringFlag1 = new StringFlag("string1"); + StringFlag stringFlag2 = new StringFlag("string2"); + ProtectedRegion parent1 = mock.createOutside(0); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE, "everyone"); - parent1.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.ALL); + parent1.setFlag(stringFlag1, "everyone"); + parent1.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.ALL); ProtectedRegion parent2 = mock.add(0); parent2.setParent(parent1); ProtectedRegion region = mock.add(0); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE, "members"); - region.setFlag(DefaultFlag.FAREWELL_MESSAGE.getRegionGroupFlag(), RegionGroup.MEMBERS); + region.setFlag(stringFlag1, "members"); + region.setFlag(stringFlag1.getRegionGroupFlag(), RegionGroup.MEMBERS); region.setParent(parent2); LocalPlayer player1 = mock.createPlayer(); @@ -1954,10 +1834,10 @@ public void testGetEffectiveFlagInheritanceAndDifferingGroupsMemberOnParentFlagO LocalPlayer player2 = mock.createPlayer(); FlagValueCalculator result = mock.getFlagCalculator(); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player1), equalTo("members")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, player2), equalTo("everyone")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.FAREWELL_MESSAGE, null), equalTo("everyone")); - assertThat(result.getEffectiveFlag(region, DefaultFlag.GREET_MESSAGE, null), equalTo(null)); + assertThat(result.getEffectiveFlag(region, stringFlag1, player1), equalTo("members")); + assertThat(result.getEffectiveFlag(region, stringFlag1, player2), equalTo("everyone")); + assertThat(result.getEffectiveFlag(region, stringFlag1, null), equalTo("everyone")); + assertThat(result.getEffectiveFlag(region, stringFlag2, null), equalTo(null)); } @Test