Skip to content

Commit

Permalink
Fixed an EntityType bug and removed more deprecated code.
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Aug 13, 2018
1 parent 7f47e31 commit 44e3f72
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 44e3f72

Please sign in to comment.