Implement new methods for accessing flags.

This commit is contained in:
sk89q 2014-08-16 21:09:01 -07:00
parent a4fd29c30c
commit fac6ebef40
12 changed files with 544 additions and 381 deletions

View File

@ -22,14 +22,16 @@
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;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import javax.annotation.Nullable;
import java.util.Collection;
import static com.google.common.base.Preconditions.checkNotNull;
@ -42,6 +44,7 @@ public class RegionQuery {
private final WorldGuardPlugin plugin;
private final ConfigurationManager config;
@SuppressWarnings("deprecation")
private final GlobalRegionManager globalManager;
private final QueryCache cache;
@ -66,15 +69,15 @@ public class RegionQuery {
* Query for regions containing the given location.
*
* <p>An instance of {@link ApplicableRegionSet} will always be returned,
* even if regions are disabled or region data failed to load. The most
* appropriate implementation will be returned in such a case
* (for example, if regions are disable, the returned implementation
* even if regions are disabled or region data failed to load. An
* appropriate "virtual" set will be returned in such a case
* (for example, if regions are disabled, the returned set
* would permit all activities).</p>
*
* @param location the location
* @return a region set
*/
public ApplicableRegionSet queryContains(Location location) {
public ApplicableRegionSet getApplicableRegions(Location location) {
checkNotNull(location);
World world = location.getWorld();
@ -93,52 +96,22 @@ public ApplicableRegionSet queryContains(Location location) {
}
/**
* Test a the player can build at the given location, checking membership
* information and the state of the {@link DefaultFlag#BUILD} flag.
*
* <p>This method is used to check blocks and entities for which there
* are no other related flags for (i.e. beds have the
* {@link DefaultFlag#SLEEP} flag).</p>
*
* <p>If region data is not available (it failed to load or region support
* is disabled), then either {@code true} or {@code false} may be returned
* depending on the configuration.</p>
* 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.
*
* @param location the location
* @param player the player
* @return true if building is permitted
* @throws NullPointerException if there is no player for this query
* @param flags zero or more flags
* @return true if permission is granted
* @see ApplicableRegionSet#testBuild(LocalPlayer, StateFlag...)
*/
public boolean testPermission(Location location, Player player) {
return testPermission(location, player, new StateFlag[0]);
}
/**
* Test a the player can build at the given location, checking membership
* information, state of the {@link DefaultFlag#BUILD} flag, and the state
* of any passed flags.
*
* <p>This method is used to check blocks and entities for which there
* are other related flags for (i.e. beds have the
* {@link DefaultFlag#SLEEP} flag). The criteria under which this method
* returns true is subject to change (i.e. all flags must be true or
* one cannot be DENY, etc.).</p>
*
* <p>If region data is not available (it failed to load or region support
* is disabled), then either {@code true} or {@code false} may be returned
* depending on the configuration.</p>
*
* @param location the location to test
* @param player the player
* @param flags an array of flags
* @return true if the flag tests true
*/
public boolean testPermission(Location location, Player player, StateFlag... flags) {
public boolean testBuild(Location location, Player player, StateFlag... flags) {
checkNotNull(location);
checkNotNull(player);
checkNotNull(flags);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
World world = location.getWorld();
WorldConfiguration worldConfig = config.get(world);
@ -150,61 +123,106 @@ public boolean testPermission(Location location, Player player, StateFlag... fla
return true;
}
RegionManager manager = globalManager.get(location.getWorld());
if (manager != null) {
ApplicableRegionSet result = cache.queryContains(manager, location);
if (result.canBuild(localPlayer)) {
return true;
}
for (StateFlag flag : flags) {
if (result.allows(flag, localPlayer)) {
return true;
}
}
return false;
} else{
return true; // null manager -> return true for now
}
LocalPlayer localPlayer = plugin.wrapPlayer(player);
return getApplicableRegions(location).testBuild(localPlayer, flags);
}
/**
* Test whether a {@link StateFlag} is evaluates to {@code ALLOW}.
* 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.
*
* <p>This method is to check whether certain functionality
* is enabled (i.e. water flow). The player, if provided, may be used
* in evaluation of the flag.</p>
* <p>This method does <strong>not</strong> properly process build
* permissions. Instead, use {@link #testBuild(Location, Player, StateFlag...)}
* for that purpose.</p>
*
* <p>If region data is not available (it failed to load or region support
* is disabled), then either {@code true} or {@code false} may be returned
* depending on the configuration.</p>
* <p>This method does the same as
* {@link #queryState(Location, Player, StateFlag...)} except that it
* returns a boolean when the result is {@code ALLOW}.</p>
*
* @param location the location
* @param player the player (or null)
* @param player an optional player, which would be used to determine the region group to apply
* @param flag the flag
* @return true if the flag evaluates to {@code ALLOW}
* @return true if the result was {@code ALLOW}
* @see ApplicableRegionSet#queryValue(LocalPlayer, Flag)
*/
public boolean testState(Location location, @Nullable Player player, StateFlag flag) {
checkNotNull(location);
checkNotNull(flag);
return StateFlag.test(queryState(location, player, flag));
}
/**
* 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}.
*
* <p>This method does <strong>not</strong> properly process build
* permissions. Instead, use {@link #testBuild(Location, Player, StateFlag...)}
* for that purpose.</p>
*
* See {@link ApplicableRegionSet#queryState(LocalPlayer, StateFlag...)}
* for more information.
*
* @param location the location
* @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 a state
* @see ApplicableRegionSet#queryState(LocalPlayer, StateFlag...)
*/
@Nullable
public State queryState(Location location, @Nullable Player player, StateFlag... flags) {
LocalPlayer localPlayer = player != null ? plugin.wrapPlayer(player) : null;
World world = location.getWorld();
WorldConfiguration worldConfig = config.get(world);
if (!worldConfig.useRegions) {
return true;
return getApplicableRegions(location).queryState(localPlayer, flags);
}
if (localPlayer != null && globalManager.hasBypass(localPlayer, world)) {
return true;
} else {
RegionManager manager = globalManager.get(location.getWorld());
return manager == null || cache.queryContains(manager, location).allows(flag, localPlayer);
/**
* 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.
*
* <p>This method does <strong>not</strong> properly process build
* permissions. Instead, use {@link #testBuild(Location, Player, StateFlag...)}
* for that purpose.</p>
*
* <p>See {@link ApplicableRegionSet#queryValue(LocalPlayer, Flag)} for
* more information.</p>
*
* @param location the location
* @param player an optional player, which would be used to determine the region group to apply
* @param flag the flag
* @return a value, which could be {@code null}
* @see ApplicableRegionSet#queryValue(LocalPlayer, Flag)
*/
@Nullable
public <V> V queryValue(Location location, @Nullable Player player, Flag<V> flag) {
LocalPlayer localPlayer = player != null ? plugin.wrapPlayer(player) : null;
return getApplicableRegions(location).queryValue(localPlayer, flag);
}
/**
* Get the effective values for a flag, returning a collection of all
* values. It is up to the caller to determine which value, if any,
* from the collection will be used.
*
* <p>This method does <strong>not</strong> properly process build
* permissions. Instead, use {@link #testBuild(Location, Player, StateFlag...)}
* for that purpose.</p>
*
* <p>See {@link ApplicableRegionSet#queryAllValues(LocalPlayer, Flag)}
* for more information.</p>
*
* @param location the location
* @param player an optional player, which would be used to determine the region group to apply
* @param flag the flag
* @return a collection of values
* @see ApplicableRegionSet#queryAllValues(LocalPlayer, Flag)
*/
public <V> Collection<V> queryAllValues(Location location, @Nullable Player player, Flag<V> flag) {
LocalPlayer localPlayer = player != null ? plugin.wrapPlayer(player) : null;
return getApplicableRegions(location).queryAllValues(localPlayer, flag);
}
}

View File

@ -82,7 +82,7 @@ public void run() {
}
}
ApplicableRegionSet applicable = plugin.getRegionContainer().createQuery().queryContains(player.getLocation());
ApplicableRegionSet applicable = plugin.getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
if (!RegionQueryUtil.isInvincible(plugin, player, applicable)
&& !plugin.getGlobalStateManager().hasGodMode(player)

View File

@ -89,7 +89,7 @@ private boolean isWhitelisted(Cause cause) {
* @param flag the flag
* @return a predicate
*/
private Predicate<Location> createStateFlagPredicate(final RegionQuery query, final StateFlag flag) {
private Predicate<Location> createStateTest(final RegionQuery query, final StateFlag flag) {
return new Predicate<Location>() {
@Override
public boolean apply(@Nullable Location location) {
@ -118,10 +118,10 @@ public boolean apply(Location target) {
// Flint and steel, fire charge
if (type == Material.FIRE) {
canPlace = query.testPermission(target, player, DefaultFlag.LIGHTER);
canPlace = query.testBuild(target, player, DefaultFlag.LIGHTER);
} else {
canPlace = query.testPermission(target, player);
canPlace = query.testBuild(target, player);
}
if (!canPlace) {
@ -158,7 +158,7 @@ public void onBreakBlock(final BreakBlockEvent event) {
event.filterBlocks(new Predicate<Location>() {
@Override
public boolean apply(Location target) {
boolean canBreak = query.testPermission(target, player);
boolean canBreak = query.testBuild(target, player);
if (!canBreak) {
tellErrorMessage(player, target);
@ -176,15 +176,15 @@ public boolean apply(Location target) {
} else if ((entity = event.getCause().getEntityRootCause()) != null) {
// Creeper
if (entity instanceof Creeper) {
event.filterBlocks(createStateFlagPredicate(query, DefaultFlag.CREEPER_EXPLOSION), config.explosionFlagCancellation);
event.filterBlocks(createStateTest(query, DefaultFlag.CREEPER_EXPLOSION), config.explosionFlagCancellation);
// Enderdragon
} else if (entity instanceof EnderDragon) {
event.filterBlocks(createStateFlagPredicate(query, DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE), config.explosionFlagCancellation);
event.filterBlocks(createStateTest(query, DefaultFlag.ENDERDRAGON_BLOCK_DAMAGE), config.explosionFlagCancellation);
// TNT + explosive TNT carts
} else if (Entities.isTNTBased(entity)) {
event.filterBlocks(createStateFlagPredicate(query, DefaultFlag.TNT), config.explosionFlagCancellation);
event.filterBlocks(createStateTest(query, DefaultFlag.TNT), config.explosionFlagCancellation);
}
} else {
@ -212,19 +212,19 @@ public boolean apply(Location target) {
// Inventory blocks (CHEST_ACCESS)
if (Materials.isInventoryBlock(type)) {
canUse = query.testPermission(target, player, DefaultFlag.USE, DefaultFlag.CHEST_ACCESS);
canUse = query.testBuild(target, player, DefaultFlag.USE, DefaultFlag.CHEST_ACCESS);
// Beds (SLEEP)
} else if (type == Material.BED) {
canUse = query.testPermission(target, player, DefaultFlag.USE, DefaultFlag.SLEEP);
canUse = query.testBuild(target, player, DefaultFlag.USE, DefaultFlag.SLEEP);
// TNT (TNT)
} else if (type == Material.TNT) {
canUse = query.testPermission(target, player, DefaultFlag.TNT);
canUse = query.testBuild(target, player, DefaultFlag.TNT);
// Everything else
} else {
canUse = query.testPermission(target, player, DefaultFlag.USE);
canUse = query.testBuild(target, player, DefaultFlag.USE);
}
if (!canUse) {
@ -256,9 +256,9 @@ public void onSpawnEntity(SpawnEntityEvent event) {
boolean canSpawn;
if (Entities.isVehicle(type)) {
canSpawn = query.testPermission(target, player, DefaultFlag.PLACE_VEHICLE);
canSpawn = query.testBuild(target, player, DefaultFlag.PLACE_VEHICLE);
} else {
canSpawn = query.testPermission(target, player);
canSpawn = query.testBuild(target, player);
}
if (!canSpawn) {
@ -286,9 +286,9 @@ public void onDestroyEntity(DestroyEntityEvent event) {
boolean canDestroy;
if (Entities.isVehicle(type)) {
canDestroy = query.testPermission(target, player, DefaultFlag.DESTROY_VEHICLE);
canDestroy = query.testBuild(target, player, DefaultFlag.DESTROY_VEHICLE);
} else {
canDestroy = query.testPermission(target, player);
canDestroy = query.testBuild(target, player);
}
if (!canDestroy) {
@ -312,7 +312,7 @@ public void onUseEntity(UseEntityEvent event) {
if ((player = event.getCause().getPlayerRootCause()) != null) {
RegionQuery query = getPlugin().getRegionContainer().createQuery();
boolean canUse = query.testPermission(target, player, DefaultFlag.USE);
boolean canUse = query.testBuild(target, player, DefaultFlag.USE);
if (!canUse) {
tellErrorMessage(player, target);

View File

@ -271,7 +271,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
}
if (wcfg.useRegions) {
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().queryContains(block.getLocation());
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
if (wcfg.highFreqFlags && isFireSpread
&& !set.allows(DefaultFlag.FIRE_SPREAD)) {
@ -345,7 +345,7 @@ public void onBlockBurn(BlockBurnEvent event) {
int x = block.getX();
int y = block.getY();
int z = block.getZ();
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().queryContains(block.getLocation());
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
if (!set.allows(DefaultFlag.FIRE_SPREAD)) {
checkAndDestroyAround(block.getWorld(), x, y, z, BlockID.FIRE);

View File

@ -44,7 +44,7 @@ public void onPlayerWhois(InfoComponent.PlayerWhoisEvent event) {
Player player = (Player) event.getPlayer();
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (plugin.getGlobalStateManager().get(player.getWorld()).useRegions) {
ApplicableRegionSet regions = plugin.getRegionContainer().createQuery().queryContains(player.getLocation());
ApplicableRegionSet regions = plugin.getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
// Current regions
StringBuilder regionStr = new StringBuilder();

View File

@ -266,9 +266,9 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (wcfg.useRegions) {
RegionQuery query = plugin.getRegionContainer().createQuery();
if (!query.testState(attacker.getLocation(), (Player) attacker, DefaultFlag.PVP)) {
if (!query.testBuild(attacker.getLocation(), (Player) attacker, DefaultFlag.PVP)) {
tryCancelPVPEvent((Player) attacker, player, event, true);
} else if (!query.testState(defender.getLocation(), (Player) defender, DefaultFlag.PVP)) {
} else if (!query.testBuild(defender.getLocation(), (Player) defender, DefaultFlag.PVP)) {
tryCancelPVPEvent((Player) attacker, player, event, false);
}
}
@ -283,7 +283,7 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
}
if (wcfg.useRegions && wcfg.explosionFlagCancellation) {
RegionQuery query = plugin.getRegionContainer().createQuery();
if (!query.testState(defender.getLocation(), (Player) defender, DefaultFlag.TNT)) {
if (!query.testBuild(defender.getLocation(), (Player) defender, DefaultFlag.TNT)) {
event.setCancelled(true);
return;
}
@ -307,13 +307,13 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
RegionQuery query = plugin.getRegionContainer().createQuery();
if (fireball.getShooter() instanceof Player) {
Location pt2 = ((Player) fireball.getShooter()).getLocation();
if (!query.testState(pt2, (Player) fireball.getShooter(), DefaultFlag.PVP)) {
if (!query.testBuild(pt2, (Player) fireball.getShooter(), DefaultFlag.PVP)) {
tryCancelPVPEvent((Player) fireball.getShooter(), player, event, true);
} else if (!query.testState(defender.getLocation(), (Player) defender, DefaultFlag.PVP)) {
} else if (!query.testBuild(defender.getLocation(), (Player) defender, DefaultFlag.PVP)) {
tryCancelPVPEvent((Player) fireball.getShooter(), player, event, false);
}
} else {
if (!query.testState(defender.getLocation(), (Player) defender, DefaultFlag.GHAST_FIREBALL) && wcfg.explosionFlagCancellation) {
if (!query.testBuild(defender.getLocation(), (Player) defender, DefaultFlag.GHAST_FIREBALL) && wcfg.explosionFlagCancellation) {
event.setCancelled(true);
return;
}
@ -335,7 +335,7 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (wcfg.useRegions) {
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().queryContains(defender.getLocation());
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(defender.getLocation());
if (!set.allows(DefaultFlag.MOB_DAMAGE, localPlayer) && !(attacker instanceof Tameable)) {
event.setCancelled(true);
@ -359,7 +359,7 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
return;
}
Player beastMaster = (Player) ((Tameable) attacker).getOwner();
if (!plugin.getRegionContainer().createQuery().queryContains(attacker.getLocation()).allows(DefaultFlag.PVP, plugin.wrapPlayer(beastMaster))) {
if (!plugin.getRegionContainer().createQuery().getApplicableRegions(attacker.getLocation()).allows(DefaultFlag.PVP, plugin.wrapPlayer(beastMaster))) {
tryCancelPVPEvent(beastMaster, player, event, true);
} else if (!set.allows(DefaultFlag.PVP, localPlayer)) {
tryCancelPVPEvent(beastMaster, player, event, false);
@ -401,7 +401,7 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
return;
}
if (wcfg.useRegions) {
if (!plugin.getRegionContainer().createQuery().queryContains(defender.getLocation()).allows(DefaultFlag.MOB_DAMAGE, localPlayer)) {
if (!plugin.getRegionContainer().createQuery().getApplicableRegions(defender.getLocation()).allows(DefaultFlag.MOB_DAMAGE, localPlayer)) {
event.setCancelled(true);
return;
}
@ -413,9 +413,9 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
if (attacker != null && attacker instanceof Player) {
if (event.getDamager() instanceof EnderPearl && attacker == player) return;
if (wcfg.useRegions) {
if (!plugin.getRegionContainer().createQuery().queryContains(attacker.getLocation()).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
if (!plugin.getRegionContainer().createQuery().getApplicableRegions(attacker.getLocation()).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
tryCancelPVPEvent((Player) attacker, player, event, true);
} else if (!plugin.getRegionContainer().createQuery().queryContains(defender.getLocation()).allows(DefaultFlag.PVP, localPlayer)) {
} else if (!plugin.getRegionContainer().createQuery().getApplicableRegions(defender.getLocation()).allows(DefaultFlag.PVP, localPlayer)) {
tryCancelPVPEvent((Player) attacker, player, event, false);
}
}
@ -468,7 +468,7 @@ public void onEntityDamage(EntityDamageEvent event) {
}
if (wcfg.useRegions) {
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().queryContains(defender.getLocation());
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(defender.getLocation());
if (!set.allows(DefaultFlag.MOB_DAMAGE, plugin.wrapPlayer(player))) {
event.setCancelled(true);
@ -608,7 +608,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
for (Block block : event.blockList()) {
if (!plugin.getRegionContainer().createQuery().queryContains(block.getLocation()).allows(DefaultFlag.GHAST_FIREBALL)) {
if (!plugin.getRegionContainer().createQuery().getApplicableRegions(block.getLocation()).allows(DefaultFlag.GHAST_FIREBALL)) {
event.blockList().clear();
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
return;
@ -633,7 +633,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
if (wcfg.useRegions) {
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
for (Block block : event.blockList()) {
if (!plugin.getRegionContainer().createQuery().queryContains(block.getLocation()).allows(DefaultFlag.OTHER_EXPLOSION)) {
if (!plugin.getRegionContainer().createQuery().getApplicableRegions(block.getLocation()).allows(DefaultFlag.OTHER_EXPLOSION)) {
event.blockList().clear();
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
return;
@ -730,7 +730,7 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
Location eventLoc = event.getLocation();
if (wcfg.useRegions && cfg.useRegionsCreatureSpawnEvent) {
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().queryContains(eventLoc);
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(eventLoc);
if (!set.allows(DefaultFlag.MOB_SPAWNING)) {
event.setCancelled(true);

View File

@ -180,7 +180,7 @@ public static boolean checkMove(WorldGuardPlugin plugin, Player player, Location
// Have to set this state
if (state.lastExitAllowed == null) {
state.lastExitAllowed = plugin.getRegionContainer().createQuery().queryContains(from)
state.lastExitAllowed = plugin.getRegionContainer().createQuery().getApplicableRegions(from)
.allows(DefaultFlag.EXIT, localPlayer);
}
@ -300,7 +300,7 @@ public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
Player player = event.getPlayer();
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(player.getWorld());
if (wcfg.useRegions && !plugin.getGlobalRegionManager().hasBypass(player, player.getWorld())) {
GameMode gameMode = plugin.getRegionContainer().createQuery().queryContains(player.getLocation()).getFlag(DefaultFlag.GAME_MODE);
GameMode gameMode = plugin.getRegionContainer().createQuery().getApplicableRegions(player.getLocation()).getFlag(DefaultFlag.GAME_MODE);
if (plugin.getFlagStateManager().getState(player).lastGameMode != null
&& gameMode != null && event.getNewGameMode() != gameMode) {
event.setCancelled(true);
@ -430,7 +430,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
if (state.lastWorld != null && !hasBypass) {
LocalPlayer localPlayer = plugin.wrapPlayer(player);
Location loc = player.getLocation();
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().queryContains(loc);
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(loc);
if (state.lastExitAllowed == null) {
state.lastExitAllowed = set.allows(DefaultFlag.EXIT, localPlayer);
@ -516,8 +516,8 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
if (wcfg.useRegions) {
Block placedIn = block.getRelative(event.getBlockFace());
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().queryContains(block.getLocation());
ApplicableRegionSet placedInSet = plugin.getRegionContainer().createQuery().queryContains(placedIn.getLocation());
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
ApplicableRegionSet placedInSet = plugin.getRegionContainer().createQuery().getApplicableRegions(placedIn.getLocation());
LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (item.getTypeId() == wcfg.regionWand && plugin.hasPermission(player, "worldguard.region.wand")) {
@ -599,7 +599,7 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
WorldConfiguration wcfg = cfg.get(player.getWorld());
if (wcfg.useRegions) {
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().queryContains(location);
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(location);
LocalPlayer localPlayer = plugin.wrapPlayer(player);
com.sk89q.worldedit.Location spawn = set.getFlag(DefaultFlag.SPAWN_LOC, localPlayer);
@ -635,8 +635,8 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.useRegions) {
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().queryContains(event.getTo());
ApplicableRegionSet setFrom = plugin.getRegionContainer().createQuery().queryContains(event.getFrom());
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(event.getTo());
ApplicableRegionSet setFrom = plugin.getRegionContainer().createQuery().getApplicableRegions(event.getFrom());
LocalPlayer localPlayer = plugin.wrapPlayer(event.getPlayer());
if (cfg.usePlayerTeleports) {
@ -668,7 +668,7 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
WorldConfiguration wcfg = cfg.get(world);
if (wcfg.useRegions && !plugin.getGlobalRegionManager().hasBypass(player, world)) {
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().queryContains(player.getLocation());
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
Set<String> allowedCommands = set.getFlag(DefaultFlag.ALLOWED_CMDS, localPlayer);
Set<String> blockedCommands = set.getFlag(DefaultFlag.BLOCKED_CMDS, localPlayer);

View File

@ -98,7 +98,7 @@ public void onLightningStrike(LightningStrikeEvent event) {
Location loc = event.getLightning().getLocation();
if (wcfg.useRegions) {
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().queryContains(loc);
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(loc);
if (!set.allows(DefaultFlag.LIGHTNING)) {
event.setCancelled(true);

View File

@ -19,13 +19,14 @@
package com.sk89q.worldguard.protection;
import com.google.common.base.Predicate;
import com.google.common.collect.ObjectArrays;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.RegionGroup;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
@ -54,8 +55,6 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
private static final ApplicableRegionSet EMPTY = new ApplicableRegionSet(Collections.<ProtectedRegion>emptyList(), null);
private final SortedSet<ProtectedRegion> applicable;
@Nullable
private final ProtectedRegion globalRegion;
private final FlagValueCalculator flagValueCalculator;
/**
@ -79,19 +78,154 @@ public ApplicableRegionSet(Collection<ProtectedRegion> applicable, @Nullable Pro
public ApplicableRegionSet(SortedSet<ProtectedRegion> applicable, @Nullable ProtectedRegion globalRegion) {
checkNotNull(applicable);
this.applicable = applicable;
this.globalRegion = globalRegion;
this.flagValueCalculator = new FlagValueCalculator(applicable, globalRegion);
}
/**
* Test whether a player can build in an area.
* Tests whether the {@link DefaultFlag#BUILD} flag or membership
* requirements permit the given player.
*
* @param player The player to check
* @return build ability
* <p>If there are several relevant flags (i.e. in addition to
* {@code BUILD}, such as {@link DefaultFlag#SLEEP} when the target
* object is a bed), then
* {@link #testBuild(LocalPlayer, StateFlag...)} should be used.</p>
*
* @param player the player to check
* @return true if permitted
* @deprecated use {@link #testBuild(LocalPlayer, StateFlag...)}
*/
@Deprecated
public boolean canBuild(LocalPlayer player) {
checkNotNull(player);
return test(flagValueCalculator.testPermission(player, DefaultFlag.BUILD));
return test(flagValueCalculator.queryPermission(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.
*
* @param player the player
* @param flags zero or more flags
* @return true if permission is granted
*/
public boolean testBuild(LocalPlayer player, StateFlag... flags) {
return test(flagValueCalculator.queryPermission(player, ObjectArrays.concat(flags, DefaultFlag.BUILD)));
}
/**
* 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}.
*
* <p>This method does <strong>not</strong> 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.</p>
*
* <p>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.</p>
*
* <p>This method does <strong>not</strong> use a {@link StateFlag}'s
* default value ({@link StateFlag#getDefault()}).</p>
*
* @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 a state
*/
@Nullable
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}.
*
* <p>This method is the same as
* {@link #queryState(LocalPlayer, StateFlag...)} except that it returns
* a boolean when the return value is {@code ALLOW}.</p>
*
* @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.
*
* <p>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
* {@link StateFlag}.</p>
*
* <p>This method does <strong>not</strong> properly process build
* permissions. Instead, use {@link #testBuild(LocalPlayer, StateFlag...)}
* for that purpose.</p>
*
* <p>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.</p>
*
* <p>This method does <strong>not</strong> use a {@link StateFlag}'s
* default value ({@link StateFlag#getDefault()}) if the provided flag is
* a {@code StateFlag}.</p>
*
* @param player an optional player, which would be used to determine the region group to apply
* @param flag the flag
* @return a value, which could be {@code null}
*/
@Nullable
public <V> V queryValue(@Nullable LocalPlayer player, Flag<V> flag) {
return flagValueCalculator.queryValue(player, flag);
}
/**
* Get the effective values for a flag, returning a collection of all
* values. It is up to the caller to determine which value, if any,
* from the collection will be used.
*
* <p>This method does <strong>not</strong> properly process build
* permissions. Instead, use {@link #testBuild(LocalPlayer, StateFlag...)}
* for that purpose.</p>
*
* <p>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.</p>
*
* <p>This method does <strong>not</strong> include a {@link StateFlag}'s
* default value ({@link StateFlag#getDefault()}) if the provided flag is
* a {@code StateFlag}.</p>
*
* @param player an optional player, which would be used to determine the region group to apply
* @param flag the flag
* @return a collection of values
*/
public <V> Collection<V> queryAllValues(@Nullable LocalPlayer player, Flag<V> flag) {
return flagValueCalculator.queryAllValues(player, flag);
}
/**
@ -99,7 +233,10 @@ public boolean canBuild(LocalPlayer player) {
*
* @param player the player
* @return true if true
* @deprecated The {@code CONSTRUCT} flag is being removed and is no longer
* needed because flags now support groups assigned to them.
*/
@Deprecated
public boolean canConstruct(LocalPlayer player) {
checkNotNull(player);
final RegionGroup flag = getFlag(DefaultFlag.CONSTRUCT, player);
@ -112,7 +249,14 @@ 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 <strong>not</strong>
* 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
public boolean allows(StateFlag flag) {
checkNotNull(flag);
@ -130,7 +274,14 @@ 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 <strong>not</strong>
* 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
public boolean allows(StateFlag flag, @Nullable LocalPlayer player) {
checkNotNull(flag);
@ -183,7 +334,10 @@ public boolean isMemberOfAll(LocalPlayer player) {
*
* @param flag the flag to check
* @return value of the flag, which may be null
* @deprecated Use {@link #queryValue(LocalPlayer, Flag)} instead. There
* is no difference in functionality.
*/
@Deprecated
@Nullable
public <T extends Flag<V>, V> V getFlag(T flag) {
return getFlag(flag, null);
@ -197,7 +351,10 @@ public <T extends Flag<V>, V> V getFlag(T flag) {
* @param groupPlayer player to check {@link RegionGroup}s against
* @return value of the flag, which may be null
* @throws IllegalArgumentException if a StateFlag is given
* @deprecated Use {@link #queryValue(LocalPlayer, Flag)} instead. There
* is no difference in functionality.
*/
@Deprecated
@Nullable
public <T extends Flag<V>, V> V getFlag(T flag, @Nullable LocalPlayer groupPlayer) {
return flagValueCalculator.queryValue(groupPlayer, flag);
@ -224,20 +381,4 @@ public static ApplicableRegionSet getEmpty() {
return EMPTY;
}
/**
* Returns true if a player is a member (or owner) of a region.
*/
private static class RegionMemberTest implements Predicate<ProtectedRegion> {
private final LocalPlayer player;
private RegionMemberTest(LocalPlayer player) {
this.player = checkNotNull(player);
}
@Override
public boolean apply(ProtectedRegion region) {
return region.isMember(player);
}
}
}

View File

@ -185,13 +185,13 @@ public Result getMembership(LocalPlayer player) {
* <p>This method handles that example perfectly. To use the method for
* the example, the call would look like this:</p>
*
* <pre>testPermission(player, DefaultFlag.BUILD, DefaultFlag.CHEST_ACCESS)</pre>
* <pre>queryPermission(player, DefaultFlag.BUILD, DefaultFlag.CHEST_ACCESS)</pre>
*
* @param player the player
* @param flags zero or more flags
* @return true if permission is granted
*/
public State testPermission(LocalPlayer player, StateFlag... flags) {
public State queryPermission(LocalPlayer player, StateFlag... flags) {
checkNotNull(player);
checkNotNull(flags);
@ -233,7 +233,7 @@ public State testPermission(LocalPlayer player, StateFlag... flags) {
* and {@code ALLOW} overrides {@code NONE}.
*
* <p>This method does <strong>not</strong> properly process build
* permissions. Instead, use {@link #testPermission(LocalPlayer, StateFlag...)}
* 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.</p>
@ -278,7 +278,7 @@ public State queryState(@Nullable LocalPlayer player, StateFlag... flags) {
* {@link StateFlag}.</p>
*
* <p>This method does <strong>not</strong> properly process build
* permissions. Instead, use {@link #testPermission(LocalPlayer, StateFlag...)}
* permissions. Instead, use {@link #queryPermission(LocalPlayer, StateFlag...)}
* for that purpose.</p>
*
* <p>A player can be provided that is used to determine whether the value
@ -305,7 +305,7 @@ public <V> V queryValue(@Nullable LocalPlayer player, Flag<V> flag) {
* from the collection will be used.
*
* <p>This method does <strong>not</strong> properly process build
* permissions. Instead, use {@link #testPermission(LocalPlayer, StateFlag...)}
* permissions. Instead, use {@link #queryPermission(LocalPlayer, StateFlag...)}
* for that purpose.</p>
*
* <p>A player can be provided that is used to determine whether the value
@ -315,6 +315,10 @@ public <V> V queryValue(@Nullable LocalPlayer player, Flag<V> flag) {
* 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.</p>
*
* @param player an optional player, which would be used to determine the region group to apply
* @param flag the flag
* @return a collection of values
*/
public <V> Collection<V> queryAllValues(@Nullable LocalPlayer player, Flag<V> flag) {
checkNotNull(flag);

View File

@ -158,7 +158,7 @@ public boolean canBuild(Player player, Block block) {
*/
@Deprecated
public boolean canBuild(Player player, Location location) {
return createQuery().testPermission(location, player);
return createQuery().testBuild(location, player);
}
/**
@ -215,10 +215,10 @@ public boolean allows(StateFlag flag, Location location) {
@Deprecated
public boolean allows(StateFlag flag, Location location, @Nullable LocalPlayer player) {
if (player == null) {
return createQuery().testState(location, null, flag);
return StateFlag.test(createQuery().queryState(location, null, flag));
} else if (player instanceof BukkitPlayer) {
Player p = ((BukkitPlayer) player).getPlayer();
return createQuery().testState(location, p, flag);
return StateFlag.test(createQuery().queryState(location, p, flag));
} else {
throw new IllegalArgumentException("Can't take a non-Bukkit player");
}

View File

@ -278,7 +278,7 @@ public void testGetMembershipThirdPriorityLower() throws Exception {
// ========================================================================
@Test
public void testTestPermissionWildernessDefaults() throws Exception {
public void testQueryPermissionWildernessDefaults() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -287,12 +287,12 @@ public void testTestPermissionWildernessDefaults() throws Exception {
LocalPlayer player = mock.createPlayer();
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(player, flag1), is((State) null));
assertThat(result.testPermission(player, flag2), is(State.ALLOW));
assertThat(result.queryPermission(player, flag1), is((State) null));
assertThat(result.queryPermission(player, flag2), is(State.ALLOW));
}
@Test
public void testTestPermissionWildernessDefaultsWithGlobalRegion() throws Exception {
public void testQueryPermissionWildernessDefaultsWithGlobalRegion() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -303,12 +303,12 @@ public void testTestPermissionWildernessDefaultsWithGlobalRegion() throws Except
ProtectedRegion global = mock.global();
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(player, flag1), is((State) null));
assertThat(result.testPermission(player, flag2), is(State.ALLOW));
assertThat(result.queryPermission(player, flag1), is((State) null));
assertThat(result.queryPermission(player, flag2), is(State.ALLOW));
}
@Test
public void testTestPermissionWildernessDefaultsWithGlobalRegionOverride() throws Exception {
public void testQueryPermissionWildernessDefaultsWithGlobalRegionOverride() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -321,13 +321,13 @@ public void testTestPermissionWildernessDefaultsWithGlobalRegionOverride() throw
global.setFlag(flag2, State.DENY);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(player, flag1), is(State.ALLOW));
assertThat(result.testPermission(player, flag2), is(State.DENY));
assertThat(result.testPermission(player, flag1, flag2), is(State.DENY));
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 testTestPermissionWildernessWithGlobalRegion() throws Exception {
public void testQueryPermissionWildernessWithGlobalRegion() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -340,18 +340,18 @@ public void testTestPermissionWildernessWithGlobalRegion() throws Exception {
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(member), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1), is((State) null));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is((State) null));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWildernessWithGlobalRegionOverride() throws Exception {
public void testQueryPermissionWildernessWithGlobalRegionOverride() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -365,18 +365,18 @@ public void testTestPermissionWildernessWithGlobalRegionOverride() throws Except
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(member), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1), is((State) null));
assertThat(result.testPermission(nonMember, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithPassthroughRegion() throws Exception {
public void testQueryPermissionWithPassthroughRegion() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -390,18 +390,18 @@ public void testTestPermissionWithPassthroughRegion() throws Exception {
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is((State) null));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(member), is((State) null));
assertThat(result.testPermission(nonMember, flag1), is((State) null));
assertThat(result.testPermission(nonMember, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithPassthroughRegionAndFlagAllow() throws Exception {
public void testQueryPermissionWithPassthroughRegionAndFlagAllow() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -416,18 +416,18 @@ public void testTestPermissionWithPassthroughRegionAndFlagAllow() throws Excepti
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(member), is((State) null));
assertThat(result.testPermission(nonMember, flag1), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithPassthroughRegionAndFlagDeny() throws Exception {
public void testQueryPermissionWithPassthroughRegionAndFlagDeny() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -442,18 +442,18 @@ public void testTestPermissionWithPassthroughRegionAndFlagDeny() throws Exceptio
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.DENY));
assertThat(result.testPermission(member, flag2), is((State) null));
assertThat(result.testPermission(member, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(member), is((State) null));
assertThat(result.testPermission(nonMember, flag1), is(State.DENY));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithPassthroughRegionAndFlagDenyAndRegionGroups() throws Exception {
public void testQueryPermissionWithPassthroughRegionAndFlagDenyAndRegionGroups() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -469,18 +469,18 @@ public void testTestPermissionWithPassthroughRegionAndFlagDenyAndRegionGroups()
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.DENY));
assertThat(result.testPermission(member, flag2), is((State) null));
assertThat(result.testPermission(member, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(member), is((State) null));
assertThat(result.testPermission(nonMember, flag1), is((State) null));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is((State) null));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithRegion() throws Exception {
public void testQueryPermissionWithRegion() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -493,18 +493,18 @@ public void testTestPermissionWithRegion() throws Exception {
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(member), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1), is((State) null));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is((State) null));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithRegionAndFlagAllow() throws Exception {
public void testQueryPermissionWithRegionAndFlagAllow() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -518,18 +518,18 @@ public void testTestPermissionWithRegionAndFlagAllow() throws Exception {
region.setFlag(flag1, State.ALLOW);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(member), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithRegionAndFlagDeny() throws Exception {
public void testQueryPermissionWithRegionAndFlagDeny() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -543,18 +543,18 @@ public void testTestPermissionWithRegionAndFlagDeny() throws Exception {
region.setFlag(flag1, State.DENY);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.DENY));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(member), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1), is(State.DENY));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithRegionAndFlagDenyAndRegionGroup() throws Exception {
public void testQueryPermissionWithRegionAndFlagDenyAndRegionGroup() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -569,16 +569,16 @@ public void testTestPermissionWithRegionAndFlagDenyAndRegionGroup() throws Excep
region.setFlag(flag1.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1), is(State.DENY));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.DENY));
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 testTestPermissionWithRegionAndGlobalRegion() throws Exception {
public void testQueryPermissionWithRegionAndGlobalRegion() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -593,18 +593,18 @@ public void testTestPermissionWithRegionAndGlobalRegion() throws Exception {
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(member), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1), is((State) null));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is((State) null));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithRegionAndGlobalRegionDeny() throws Exception {
public void testQueryPermissionWithRegionAndGlobalRegionDeny() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -620,16 +620,16 @@ public void testTestPermissionWithRegionAndGlobalRegionDeny() throws Exception {
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.DENY));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(nonMember, flag1), is(State.DENY));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.DENY));
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 testTestPermissionWithRegionAndGlobalRegionAllow() throws Exception {
public void testQueryPermissionWithRegionAndGlobalRegionAllow() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -645,17 +645,17 @@ public void testTestPermissionWithRegionAndGlobalRegionAllow() throws Exception
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(member), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithRegionAllowAndGlobalRegionDeny() throws Exception {
public void testQueryPermissionWithRegionAllowAndGlobalRegionDeny() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -672,16 +672,16 @@ public void testTestPermissionWithRegionAllowAndGlobalRegionDeny() throws Except
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.ALLOW));
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 testTestPermissionWithRegionAllowAndGlobalRegionDenyDifferentFlags() throws Exception {
public void testQueryPermissionWithRegionAllowAndGlobalRegionDenyDifferentFlags() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -698,16 +698,16 @@ public void testTestPermissionWithRegionAllowAndGlobalRegionDenyDifferentFlags()
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.DENY));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(nonMember, flag1), is(State.DENY));
assertThat(result.testPermission(nonMember, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.DENY));
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 testTestPermissionWithPassthroughRegionAllowAndGlobalRegionDenyWithRegionGroup() throws Exception {
public void testQueryPermissionWithPassthroughRegionAllowAndGlobalRegionDenyWithRegionGroup() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -726,16 +726,16 @@ public void testTestPermissionWithPassthroughRegionAllowAndGlobalRegionDenyWithR
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.DENY));
assertThat(result.testPermission(member, flag2), is((State) null));
assertThat(result.testPermission(member, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(nonMember, flag1), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.ALLOW));
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 testTestPermissionWithRegionAllowAndGlobalRegionDenyWithRegionGroup() throws Exception {
public void testQueryPermissionWithRegionAllowAndGlobalRegionDenyWithRegionGroup() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -753,16 +753,16 @@ public void testTestPermissionWithRegionAllowAndGlobalRegionDenyWithRegionGroup(
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.DENY));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(nonMember, flag1), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.ALLOW));
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 testTestPermissionWithRegionAllowAndGlobalRegionDenyDifferentFlagsWithRegionGroup() throws Exception {
public void testQueryPermissionWithRegionAllowAndGlobalRegionDenyDifferentFlagsWithRegionGroup() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -780,16 +780,16 @@ public void testTestPermissionWithRegionAllowAndGlobalRegionDenyDifferentFlagsWi
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.DENY));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(nonMember, flag1), is(State.DENY));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.DENY));
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 testTestPermissionWithGlobalRegionMembership() throws Exception {
public void testQueryPermissionWithGlobalRegionMembership() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -802,18 +802,18 @@ public void testTestPermissionWithGlobalRegionMembership() throws Exception {
global.getMembers().addPlayer(globalMember);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(globalMember, flag1), is(State.ALLOW));
assertThat(result.testPermission(globalMember, flag2), is(State.ALLOW));
assertThat(result.testPermission(globalMember, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(globalMember), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1), is((State) null));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is((State) null));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithGlobalRegionMembershipAndRegion() throws Exception {
public void testQueryPermissionWithGlobalRegionMembershipAndRegion() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -830,22 +830,22 @@ public void testTestPermissionWithGlobalRegionMembershipAndRegion() throws Excep
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(member), is(State.ALLOW));
assertThat(result.testPermission(globalMember, flag1), is((State) null));
assertThat(result.testPermission(globalMember, flag2), is((State) null));
assertThat(result.testPermission(globalMember, flag1, flag2), is((State) null));
assertThat(result.testPermission(globalMember), is((State) null));
assertThat(result.testPermission(nonMember, flag1), is((State) null));
assertThat(result.testPermission(nonMember, flag2), is((State) null));
assertThat(result.testPermission(nonMember, flag1, flag2), is((State) null));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithGlobalRegionMembershipAndRegionGlobalFlag() throws Exception {
public void testQueryPermissionWithGlobalRegionMembershipAndRegionGlobalFlag() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -863,22 +863,22 @@ public void testTestPermissionWithGlobalRegionMembershipAndRegionGlobalFlag() th
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.DENY));
assertThat(result.testPermission(member, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(member), is(State.ALLOW));
assertThat(result.testPermission(globalMember, flag1), is((State) null));
assertThat(result.testPermission(globalMember, flag2), is(State.DENY));
assertThat(result.testPermission(globalMember, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(globalMember), is((State) null));
assertThat(result.testPermission(nonMember, flag1), is((State) null));
assertThat(result.testPermission(nonMember, flag2), is(State.DENY));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithGlobalRegionMembershipAndRegionGlobalFlagRegionOverride() throws Exception {
public void testQueryPermissionWithGlobalRegionMembershipAndRegionGlobalFlagRegionOverride() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -897,22 +897,22 @@ public void testTestPermissionWithGlobalRegionMembershipAndRegionGlobalFlagRegio
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(member), is(State.ALLOW));
assertThat(result.testPermission(globalMember, flag1), is((State) null));
assertThat(result.testPermission(globalMember, flag2), is(State.ALLOW));
assertThat(result.testPermission(globalMember, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(globalMember), is((State) null));
assertThat(result.testPermission(nonMember, flag1), is((State) null));
assertThat(result.testPermission(nonMember, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(nonMember), is((State) null));
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 testTestPermissionWithGlobalRegionMembershipAndRegionGlobalFlagRegionOverrideAndRegionGroups() throws Exception {
public void testQueryPermissionWithGlobalRegionMembershipAndRegionGlobalFlagRegionOverrideAndRegionGroups() throws Exception {
MockApplicableRegionSet mock = new MockApplicableRegionSet();
StateFlag flag1 = new StateFlag("test1", false);
@ -932,18 +932,18 @@ public void testTestPermissionWithGlobalRegionMembershipAndRegionGlobalFlagRegio
region.getMembers().addPlayer(member);
FlagValueCalculator result = mock.getFlagCalculator();
assertThat(result.testPermission(member, flag1), is(State.ALLOW));
assertThat(result.testPermission(member, flag2), is(State.ALLOW));
assertThat(result.testPermission(member, flag1, flag2), is(State.ALLOW));
assertThat(result.testPermission(member), is(State.ALLOW));
assertThat(result.testPermission(globalMember, flag1), is((State) null));
assertThat(result.testPermission(globalMember, flag2), is(State.DENY));
assertThat(result.testPermission(globalMember, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(globalMember), is((State) null));
assertThat(result.testPermission(nonMember, flag1), is((State) null));
assertThat(result.testPermission(nonMember, flag2), is(State.DENY));
assertThat(result.testPermission(nonMember, flag1, flag2), is(State.DENY));
assertThat(result.testPermission(nonMember), is((State) null));
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));
}
// ========================================================================