mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-26 20:45:43 +01:00
Fixed an EntityType bug and removed more deprecated code.
This commit is contained in:
parent
7f47e31686
commit
44e3f720de
@ -19,27 +19,16 @@
|
||||
|
||||
package com.sk89q.worldguard.protection;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import static com.sk89q.worldguard.protection.flags.StateFlag.test;
|
||||
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldguard.protection.flags.StateFlag.test;
|
||||
|
||||
public abstract class AbstractRegionSet implements ApplicableRegionSet {
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean canBuild(LocalPlayer player) {
|
||||
checkNotNull(player);
|
||||
return test(queryState(player, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testState(@Nullable RegionAssociable subject, StateFlag... flags) {
|
||||
return test(queryState(subject, flags));
|
||||
@ -60,42 +49,4 @@ public State queryState(@Nullable RegionAssociable subject, StateFlag... flags)
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean allows(StateFlag flag) {
|
||||
checkNotNull(flag);
|
||||
|
||||
if (flag == Flags.BUILD) {
|
||||
throw new IllegalArgumentException("Can't use build flag with allows()");
|
||||
}
|
||||
|
||||
return test(queryState(null, flag));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean allows(StateFlag flag, @Nullable LocalPlayer player) {
|
||||
checkNotNull(flag);
|
||||
|
||||
if (flag == Flags.BUILD) {
|
||||
throw new IllegalArgumentException("Can't use build flag with allows()");
|
||||
}
|
||||
|
||||
return test(queryState(player, flag));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public <T extends Flag<V>, V> V getFlag(T flag, @Nullable LocalPlayer groupPlayer) {
|
||||
return queryValue(groupPlayer, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public <T extends Flag<V>, V> V getFlag(T flag) {
|
||||
return getFlag(flag, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -60,17 +60,6 @@ public interface ApplicableRegionSet extends Iterable<ProtectedRegion> {
|
||||
*/
|
||||
boolean isVirtual();
|
||||
|
||||
/**
|
||||
* Tests whether the {@link Flags#BUILD} flag or membership
|
||||
* requirements permit the given player.
|
||||
*
|
||||
* @param player the player to check
|
||||
* @return true if permitted
|
||||
* @deprecated use {@link #testState(RegionAssociable, StateFlag...)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean canBuild(LocalPlayer player);
|
||||
|
||||
/**
|
||||
* Test whether the (effective) value for a list of state flags equals
|
||||
* {@code ALLOW}.
|
||||
@ -148,29 +137,6 @@ public interface ApplicableRegionSet extends Iterable<ProtectedRegion> {
|
||||
*/
|
||||
<V> Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag<V> flag);
|
||||
|
||||
/**
|
||||
* Gets the state of a state flag. This cannot be used for the build flag.
|
||||
*
|
||||
* @param flag flag to check
|
||||
* @return whether it is allowed
|
||||
* @throws IllegalArgumentException if the build flag is given
|
||||
* @deprecated use {@link #queryState(RegionAssociable, StateFlag...)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
boolean allows(StateFlag flag);
|
||||
|
||||
/**
|
||||
* Gets the state of a state flag. This cannot be used for the build flag.
|
||||
*
|
||||
* @param flag flag to check
|
||||
* @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(RegionAssociable, StateFlag...)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
boolean allows(StateFlag flag, @Nullable LocalPlayer player);
|
||||
|
||||
/**
|
||||
* Test whether a player is an owner of all regions in this set.
|
||||
*
|
||||
@ -187,34 +153,6 @@ public interface ApplicableRegionSet extends Iterable<ProtectedRegion> {
|
||||
*/
|
||||
boolean isMemberOfAll(LocalPlayer player);
|
||||
|
||||
/**
|
||||
* Gets the value of a flag. Do not use this for state flags
|
||||
* (use {@link #allows(StateFlag, LocalPlayer)} for that).
|
||||
*
|
||||
* @param flag the flag to check
|
||||
* @return value of the flag, which may be null
|
||||
* @deprecated Use {@link #queryValue(RegionAssociable, Flag)} instead. There
|
||||
* is no difference in functionality.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
<T extends Flag<V>, V> V getFlag(T flag);
|
||||
|
||||
/**
|
||||
* Gets the value of a flag. Do not use this for state flags
|
||||
* (use {@link #allows(StateFlag, LocalPlayer)} for that).
|
||||
*
|
||||
* @param flag flag to check
|
||||
* @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(RegionAssociable, Flag)} instead. There
|
||||
* is no difference in functionality.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
<T extends Flag<V>, V> V getFlag(T flag, @Nullable LocalPlayer groupPlayer);
|
||||
|
||||
/**
|
||||
* Get the number of regions that are included.
|
||||
*
|
||||
|
@ -565,17 +565,6 @@ public boolean containsAny(List<BlockVector2D> positions) {
|
||||
*/
|
||||
public abstract RegionType getType();
|
||||
|
||||
/**
|
||||
* Return the type of region as a user-friendly, lowercase name.
|
||||
*
|
||||
* @return type of region
|
||||
* @deprecated use {@link #getType()}
|
||||
*/
|
||||
@Deprecated
|
||||
public final String getTypeName() {
|
||||
return getType().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of regions from the given list of regions that intersect
|
||||
* with this region.
|
||||
|
@ -27,7 +27,6 @@
|
||||
import com.sk89q.worldguard.blacklist.target.Target;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -40,30 +39,11 @@
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitUtil {
|
||||
|
||||
private BukkitUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches one player based on name.
|
||||
*
|
||||
* @param server The server to check
|
||||
* @param name The name to attempt to match
|
||||
* @deprecated see {@link WorldGuardPlugin#matchSinglePlayer(org.bukkit.command.CommandSender, String)}
|
||||
* @return The matched player if any, otherwise null
|
||||
*/
|
||||
@Deprecated
|
||||
public static Player matchSinglePlayer(Server server, String name) {
|
||||
List<Player> players = server.matchPlayer(name);
|
||||
if (players.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return players.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given potion is a vial of water.
|
||||
*
|
||||
|
@ -273,26 +273,26 @@ public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation()));
|
||||
|
||||
if (wcfg.highFreqFlags && isFireSpread
|
||||
&& !set.allows(Flags.FIRE_SPREAD)) {
|
||||
&& !set.testState(null, Flags.FIRE_SPREAD)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wcfg.highFreqFlags && cause == IgniteCause.LAVA
|
||||
&& !set.allows(Flags.LAVA_FIRE)) {
|
||||
&& !set.testState(null, Flags.LAVA_FIRE)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cause == IgniteCause.FIREBALL && event.getPlayer() == null) {
|
||||
// wtf bukkit, FIREBALL is supposed to be reserved to players
|
||||
if (!set.allows(Flags.GHAST_FIREBALL)) {
|
||||
if (!set.testState(null, Flags.GHAST_FIREBALL)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (cause == IgniteCause.LIGHTNING && !set.allows(Flags.LIGHTNING)) {
|
||||
if (cause == IgniteCause.LIGHTNING && !set.testState(null, Flags.LIGHTNING)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -347,7 +347,7 @@ public void onBlockBurn(BlockBurnEvent event) {
|
||||
ApplicableRegionSet set =
|
||||
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation()));
|
||||
|
||||
if (!set.allows(Flags.FIRE_SPREAD)) {
|
||||
if (!set.testState(null, Flags.FIRE_SPREAD)) {
|
||||
checkAndDestroyAround(block.getWorld(), x, y, z, Material.FIRE);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -71,7 +72,7 @@ public void onPlayerWhois(InfoComponent.PlayerWhoisEvent event) {
|
||||
if (regions.size() > 0) {
|
||||
event.addWhoisInformation("Current Regions", regionStr);
|
||||
}
|
||||
event.addWhoisInformation("Can build", regions.canBuild(localPlayer));
|
||||
event.addWhoisInformation("Can build", regions.testState(localPlayer, Flags.BUILD));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -267,13 +267,13 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (wcfg.useRegions) {
|
||||
ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
|
||||
|
||||
if (!set.allows(Flags.MOB_DAMAGE, localPlayer) && !(attacker instanceof Tameable)) {
|
||||
if (!set.testState(localPlayer, Flags.MOB_DAMAGE) && !(attacker instanceof Tameable)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attacker instanceof Creeper) {
|
||||
if (!set.allows(Flags.CREEPER_EXPLOSION, localPlayer) && wcfg.explosionFlagCancellation) {
|
||||
if (!set.testState(localPlayer, Flags.CREEPER_EXPLOSION) && wcfg.explosionFlagCancellation) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -308,7 +308,7 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
|
||||
return;
|
||||
}
|
||||
if (wcfg.useRegions) {
|
||||
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation()).allows(Flags.MOB_DAMAGE, localPlayer)) {
|
||||
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation()).testState(localPlayer, Flags.MOB_DAMAGE)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -385,7 +385,7 @@ public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (wcfg.useRegions) {
|
||||
ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
|
||||
|
||||
if (!set.allows(Flags.MOB_DAMAGE, plugin.wrapPlayer(player))) {
|
||||
if (!set.testState(plugin.wrapPlayer(player), Flags.MOB_DAMAGE)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -504,7 +504,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
||||
// allow wither skull blocking since there is no dedicated flag atm
|
||||
if (wcfg.useRegions) {
|
||||
for (Block block : event.blockList()) {
|
||||
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).allows(Flags.GHAST_FIREBALL)) {
|
||||
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.GHAST_FIREBALL)) {
|
||||
event.blockList().clear();
|
||||
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
|
||||
return;
|
||||
@ -538,7 +538,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
|
||||
}
|
||||
if (wcfg.useRegions) {
|
||||
for (Block block : event.blockList()) {
|
||||
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).allows(Flags.OTHER_EXPLOSION)) {
|
||||
if (!WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation())).testState(null, Flags.OTHER_EXPLOSION)) {
|
||||
event.blockList().clear();
|
||||
if (wcfg.explosionFlagCancellation) event.setCancelled(true);
|
||||
return;
|
||||
@ -643,13 +643,14 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
ApplicableRegionSet set =
|
||||
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(eventLoc));
|
||||
|
||||
if (!set.allows(Flags.MOB_SPAWNING)) {
|
||||
if (!set.testState(null, Flags.MOB_SPAWNING)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Set<com.sk89q.worldedit.world.entity.EntityType> entityTypes = set.getFlag(Flags.DENY_SPAWN);
|
||||
if (entityTypes != null && entityTypes.contains(entityType)) {
|
||||
Set<com.sk89q.worldedit.world.entity.EntityType> entityTypes = set.queryValue(null, Flags.DENY_SPAWN);
|
||||
com.sk89q.worldedit.world.entity.EntityType weEntityType = BukkitAdapter.adapt(entityType);
|
||||
if (entityTypes != null && weEntityType != null && entityTypes.contains(weEntityType)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -288,8 +288,7 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
|
||||
|
||||
if (item != null && item.getType().getKey().toString().equals(wcfg.regionWand) && plugin.hasPermission(player, "worldguard.region.wand")) {
|
||||
if (set.size() > 0) {
|
||||
player.sendMessage(ChatColor.YELLOW + "Can you build? "
|
||||
+ (set.canBuild(localPlayer) ? "Yes" : "No"));
|
||||
player.sendMessage(ChatColor.YELLOW + "Can you build? " + (set.testState(localPlayer, Flags.BUILD) ? "Yes" : "No"));
|
||||
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (Iterator<ProtectedRegion> it = set.iterator(); it.hasNext();) {
|
||||
@ -299,9 +298,9 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString());
|
||||
localPlayer.print("Applicable regions: " + str.toString());
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!");
|
||||
localPlayer.print("WorldGuard: No defined regions here!");
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
@ -334,17 +333,16 @@ private void handlePhysicalInteract(PlayerInteractEvent event) {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Location location = player.getLocation();
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
||||
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(BukkitAdapter.adapt(player.getWorld()));
|
||||
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) cfg.get(localPlayer.getWorld());
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
ApplicableRegionSet set =
|
||||
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(location));
|
||||
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
|
||||
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
com.sk89q.worldedit.util.Location spawn = set.getFlag(Flags.SPAWN_LOC, localPlayer);
|
||||
com.sk89q.worldedit.util.Location spawn = set.queryValue(localPlayer, Flags.SPAWN_LOC);
|
||||
|
||||
if (spawn != null) {
|
||||
event.setRespawnLocation(BukkitAdapter.adapt(spawn));
|
||||
@ -395,8 +393,8 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
|
||||
if (event.getCause() == TeleportCause.ENDER_PEARL) {
|
||||
if (!WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())
|
||||
&& !(set.allows(Flags.ENDERPEARL, localPlayer)
|
||||
&& setFrom.allows(Flags.ENDERPEARL, localPlayer))) {
|
||||
&& !(set.testState(localPlayer, Flags.ENDERPEARL)
|
||||
&& setFrom.testState(localPlayer, Flags.ENDERPEARL))) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to go there.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@ -405,8 +403,8 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
try {
|
||||
if (event.getCause() == TeleportCause.CHORUS_FRUIT) {
|
||||
if (!WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
|
||||
boolean allowFrom = setFrom.allows(Flags.CHORUS_TELEPORT, localPlayer);
|
||||
boolean allowTo = set.allows(Flags.CHORUS_TELEPORT, localPlayer);
|
||||
boolean allowFrom = setFrom.testState(localPlayer, Flags.CHORUS_TELEPORT);
|
||||
boolean allowTo = set.testState(localPlayer, Flags.CHORUS_TELEPORT);
|
||||
if (!allowFrom || !allowTo) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to teleport " +
|
||||
(!allowFrom ? "from here." : "there."));
|
||||
|
@ -163,9 +163,9 @@ public void testStateFlagPriorityFallThrough() {
|
||||
region.setFlag(state3, StateFlag.State.ALLOW);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.allows(state1));
|
||||
assertFalse(set.allows(state2));
|
||||
assertTrue(set.allows(state3));
|
||||
assertFalse(set.testState(null, state1));
|
||||
assertFalse(set.testState(null, state2));
|
||||
assertTrue(set.testState(null, state3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -187,10 +187,10 @@ public void testNonStateFlagPriorityFallThrough() {
|
||||
region.setFlag(string3, "Bananas");
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertEquals(set.getFlag(string1), "Cats");
|
||||
assertEquals(set.getFlag(string2), "Apples");
|
||||
assertEquals(set.getFlag(string3), "Bananas");
|
||||
assertEquals(set.getFlag(string4), null);
|
||||
assertEquals(set.queryValue(null, string1), "Cats");
|
||||
assertEquals(set.queryValue(null, string2), "Apples");
|
||||
assertEquals(set.queryValue(null, string3), "Bananas");
|
||||
assertNull(set.queryValue(null, string4));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -216,10 +216,10 @@ public void testStateFlagMultiplePriorityFallThrough() {
|
||||
region.setFlag(string3, "Strings");
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertEquals(set.getFlag(string1), "Cats");
|
||||
assertEquals(set.getFlag(string2), "Apples");
|
||||
assertEquals(set.getFlag(string3), "Strings");
|
||||
assertEquals(set.getFlag(string4), null);
|
||||
assertEquals(set.queryValue(null, string1), "Cats");
|
||||
assertEquals(set.queryValue(null, string2), "Apples");
|
||||
assertEquals(set.queryValue(null, string3), "Strings");
|
||||
assertNull(set.queryValue(null, string4));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -241,12 +241,12 @@ public void testStateGlobalDefault() {
|
||||
region.setFlag(state5, StateFlag.State.DENY);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.allows(state1));
|
||||
assertFalse(set.allows(state2));
|
||||
assertFalse(set.allows(state3));
|
||||
assertTrue(set.allows(state4));
|
||||
assertFalse(set.allows(state5));
|
||||
assertTrue(set.allows(state6));
|
||||
assertTrue(set.testState(null, state1));
|
||||
assertFalse(set.testState(null, state2));
|
||||
assertFalse(set.testState(null, state3));
|
||||
assertTrue(set.testState(null, state4));
|
||||
assertFalse(set.testState(null, state5));
|
||||
assertTrue(set.testState(null, state6));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -277,12 +277,12 @@ public void testStateGlobalWithRegionsDefault() {
|
||||
region.setFlag(state5, StateFlag.State.ALLOW);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.allows(state1));
|
||||
assertFalse(set.allows(state2));
|
||||
assertFalse(set.allows(state3));
|
||||
assertFalse(set.allows(state4));
|
||||
assertTrue(set.allows(state5));
|
||||
assertTrue(set.allows(state6));
|
||||
assertFalse(set.testState(null, state1));
|
||||
assertFalse(set.testState(null, state2));
|
||||
assertFalse(set.testState(null, state3));
|
||||
assertFalse(set.testState(null, state4));
|
||||
assertTrue(set.testState(null, state5));
|
||||
assertTrue(set.testState(null, state6));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -297,8 +297,8 @@ public void testBuildAccess() {
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -317,9 +317,9 @@ public void testBuildRegionPriorities() {
|
||||
region.getOwners().addPlayer(upperMember);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(upperMember));
|
||||
assertFalse(set.canBuild(lowerMember));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(upperMember, Flags.BUILD));
|
||||
assertFalse(set.testState(lowerMember, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -335,8 +335,8 @@ public void testBuildDenyFlag() {
|
||||
region.setFlag(Flags.BUILD, StateFlag.State.DENY);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertFalse(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -352,8 +352,8 @@ public void testBuildAllowFlag() {
|
||||
region.setFlag(Flags.BUILD, StateFlag.State.ALLOW);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertTrue(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(member, Flags.BUILD));
|
||||
assertTrue(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -372,8 +372,8 @@ public void testHigherPriorityOverrideBuildDenyFlag() {
|
||||
region.setFlag(Flags.BUILD, StateFlag.State.ALLOW);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertTrue(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(member, Flags.BUILD));
|
||||
assertTrue(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -391,8 +391,8 @@ public void testHigherPriorityUnsetBuildDenyFlag() {
|
||||
region = mock.add(1);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertFalse(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -410,8 +410,8 @@ public void testPriorityDisjointBuildDenyFlagAndMembership() {
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -428,8 +428,8 @@ public void testPriorityDisjointBuildDenyFlagAndRegion() {
|
||||
region = mock.add(1);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertFalse(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -447,8 +447,8 @@ public void testPriorityDisjointMembershipAndBuildDenyFlag() {
|
||||
region.setFlag(Flags.BUILD, StateFlag.State.DENY);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertFalse(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -459,8 +459,8 @@ public void testNoGlobalRegionDefaultBuild() {
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertTrue(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(member, Flags.BUILD));
|
||||
assertTrue(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -473,8 +473,8 @@ public void testGlobalRegionDefaultBuild() {
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertTrue(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(member, Flags.BUILD));
|
||||
assertTrue(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -489,8 +489,8 @@ public void testGlobalRegionBuildFlagAllow() {
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertTrue(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(member, Flags.BUILD));
|
||||
assertTrue(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -505,8 +505,8 @@ public void testGlobalRegionBuildFlagDeny() {
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertFalse(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -524,8 +524,8 @@ public void testGlobalRegionBuildFlagAllowWithRegion() {
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -543,8 +543,8 @@ public void testGlobalRegionBuildFlagDenyWithRegion() {
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -559,8 +559,8 @@ public void testGlobalRegionHavingOwnershipBuildFlagUnset() {
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -576,8 +576,8 @@ public void testGlobalRegionHavingOwnershipBuildFlagAllow() {
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertTrue(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -593,8 +593,8 @@ public void testGlobalRegionHavingOwnershipBuildFlagDeny() {
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
assertFalse(set.testState(member, Flags.BUILD));
|
||||
assertFalse(set.testState(nonMember, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -605,13 +605,13 @@ public void testGlobalRegionCommandBlacklistWithRegionWhitelist() {
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.global();
|
||||
Set<String> blocked = new HashSet<String>();
|
||||
Set<String> blocked = new HashSet<>();
|
||||
blocked.add("/deny");
|
||||
blocked.add("/strange");
|
||||
region.setFlag(Flags.BLOCKED_CMDS, blocked);
|
||||
|
||||
region = mock.add(0);
|
||||
Set<String> allowed = new HashSet<String>();
|
||||
Set<String> allowed = new HashSet<>();
|
||||
allowed.add("/permit");
|
||||
allowed.add("/strange");
|
||||
region.setFlag(Flags.ALLOWED_CMDS, allowed);
|
||||
@ -621,8 +621,8 @@ public void testGlobalRegionCommandBlacklistWithRegionWhitelist() {
|
||||
|
||||
set = mock.getApplicableSet();
|
||||
test = new CommandFilter(
|
||||
set.getFlag(Flags.ALLOWED_CMDS, nonMember),
|
||||
set.getFlag(Flags.BLOCKED_CMDS, nonMember));
|
||||
set.queryValue(nonMember, Flags.ALLOWED_CMDS),
|
||||
set.queryValue(nonMember, Flags.BLOCKED_CMDS));
|
||||
assertThat(test.apply("/permit"), is(true));
|
||||
assertThat(test.apply("/strange"), is(true));
|
||||
assertThat(test.apply("/other"), is(false));
|
||||
@ -630,8 +630,8 @@ public void testGlobalRegionCommandBlacklistWithRegionWhitelist() {
|
||||
|
||||
set = mock.getApplicableSetInWilderness();
|
||||
test = new CommandFilter(
|
||||
set.getFlag(Flags.ALLOWED_CMDS, nonMember),
|
||||
set.getFlag(Flags.BLOCKED_CMDS, nonMember));
|
||||
set.queryValue(nonMember, Flags.ALLOWED_CMDS),
|
||||
set.queryValue(nonMember, Flags.BLOCKED_CMDS));
|
||||
assertThat(test.apply("/permit"), is(true));
|
||||
assertThat(test.apply("/strange"), is(false));
|
||||
assertThat(test.apply("/other"), is(true));
|
||||
|
@ -131,8 +131,8 @@ public void testEntry() throws Exception {
|
||||
// System.out.println("flag " + appl.getFlag(Flags.ENTRY));
|
||||
// System.out.println("grp " + appl.getFlag(Flags.ENTRY.getRegionGroupFlag()));
|
||||
// System.out.println("===");
|
||||
assertTrue("Allowed Entry", appl.allows(Flags.ENTRY, vipPlayer));
|
||||
assertFalse("Forbidden Entry", appl.allows(Flags.ENTRY, builderPlayer));
|
||||
assertTrue("Allowed Entry", appl.testState(vipPlayer, Flags.ENTRY));
|
||||
assertFalse("Forbidden Entry", appl.testState(builderPlayer, Flags.ENTRY));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -146,8 +146,8 @@ public void testExit() throws Exception {
|
||||
// System.out.println("flag " + appl.getFlag(Flags.EXIT));
|
||||
// System.out.println("grp " + appl.getFlag(Flags.EXIT.getRegionGroupFlag()));
|
||||
// System.out.println("===");
|
||||
assertTrue("Allowed Exit", appl.allows(Flags.EXIT, builderPlayer));
|
||||
assertFalse("Forbidden Exit", appl.allows(Flags.EXIT, vipPlayer));
|
||||
assertTrue("Allowed Exit", appl.testState(builderPlayer, Flags.EXIT));
|
||||
assertFalse("Forbidden Exit", appl.testState(vipPlayer, Flags.EXIT));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -138,17 +138,17 @@ public void testNonBuildFlag() {
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.allows(Flags.FIRE_SPREAD));
|
||||
assertTrue(appl.testState(null, Flags.FIRE_SPREAD));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.allows(Flags.FIRE_SPREAD));
|
||||
assertTrue(appl.testState(null, Flags.FIRE_SPREAD));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertFalse(appl.allows(Flags.FIRE_SPREAD));
|
||||
assertFalse(appl.testState(null, Flags.FIRE_SPREAD));
|
||||
|
||||
// Inside no fire zone
|
||||
appl = manager.getApplicableRegions(inNoFire);
|
||||
assertFalse(appl.allows(Flags.FIRE_SPREAD));
|
||||
assertFalse(appl.testState(null, Flags.FIRE_SPREAD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -157,31 +157,31 @@ public void testPlayer1BuildAccess() {
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.canBuild(player1));
|
||||
assertTrue(appl.testState(player1, Flags.BUILD));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.canBuild(player1));
|
||||
assertTrue(appl.testState(player1, Flags.BUILD));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.canBuild(player1));
|
||||
assertTrue(appl.testState(player1, Flags.BUILD));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayer2BuildAccess() {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
HashSet<ProtectedRegion> test = new HashSet<ProtectedRegion>();
|
||||
HashSet<ProtectedRegion> test = new HashSet<>();
|
||||
test.add(courtyard);
|
||||
test.add(fountain);
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.canBuild(player2));
|
||||
assertTrue(appl.testState(player2, Flags.BUILD));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertFalse(appl.canBuild(player2));
|
||||
assertFalse(appl.testState(player2, Flags.BUILD));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.canBuild(player2));
|
||||
assertTrue(appl.testState(player2, Flags.BUILD));
|
||||
}
|
||||
}
|
||||
|
@ -132,11 +132,11 @@ public void testNoPriorities() throws Exception {
|
||||
fountain.setPriority(0);
|
||||
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.allows(Flags.FIRE_SPREAD));
|
||||
assertFalse(appl.allows(Flags.MOB_SPAWNING));
|
||||
assertTrue(appl.testState(null, Flags.FIRE_SPREAD));
|
||||
assertFalse(appl.testState(null, Flags.MOB_SPAWNING));
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertFalse(appl.allows(Flags.FIRE_SPREAD));
|
||||
assertTrue(appl.allows(Flags.MOB_SPAWNING));
|
||||
assertFalse(appl.testState(null, Flags.FIRE_SPREAD));
|
||||
assertTrue(appl.testState(null, Flags.MOB_SPAWNING));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -147,9 +147,9 @@ public void testPriorities() throws Exception {
|
||||
fountain.setPriority(0);
|
||||
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.allows(Flags.FIRE_SPREAD));
|
||||
assertTrue(appl.testState(null, Flags.FIRE_SPREAD));
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertFalse(appl.allows(Flags.FIRE_SPREAD));
|
||||
assertFalse(appl.testState(null, Flags.FIRE_SPREAD));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -160,8 +160,8 @@ public void testPriorities2() throws Exception {
|
||||
fountain.setPriority(5);
|
||||
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertFalse(appl.allows(Flags.MOB_SPAWNING));
|
||||
assertFalse(appl.testState(null, Flags.MOB_SPAWNING));
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.allows(Flags.MOB_SPAWNING));
|
||||
assertTrue(appl.testState(null, Flags.MOB_SPAWNING));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user