Cleanup unnecessary in-house Cancellable#isCancelled checks.

Use the ignoreCancelled EventHandler annotation parameter instead.
This commit is contained in:
mrlolethan 2015-02-23 16:03:23 -03:30
parent 1daf79c6c3
commit c7d9e6b92c
5 changed files with 27 additions and 99 deletions

View File

@ -22,11 +22,8 @@ public class FactionsBlockListener implements Listener {
this.p = p; this.p = p;
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled()) {
return;
}
if (!event.canBuild()) { if (!event.canBuild()) {
return; return;
} }
@ -41,33 +38,22 @@ public class FactionsBlockListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) {
return;
}
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) { if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockDamage(BlockDamageEvent event) { public void onBlockDamage(BlockDamageEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getInstaBreak() && !playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) { if (event.getInstaBreak() && !playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockPistonExtend(BlockPistonExtendEvent event) { public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if (event.isCancelled()) {
return;
}
if (!Conf.pistonProtectionThroughDenyBuild) { if (!Conf.pistonProtectionThroughDenyBuild) {
return; return;
} }
@ -90,10 +76,10 @@ public class FactionsBlockListener implements Listener {
*/ */
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockPistonRetract(BlockPistonRetractEvent event) { public void onBlockPistonRetract(BlockPistonRetractEvent event) {
// if not a sticky piston, retraction should be fine // if not a sticky piston, retraction should be fine
if (event.isCancelled() || !event.isSticky() || !Conf.pistonProtectionThroughDenyBuild) { if (!event.isSticky() || !Conf.pistonProtectionThroughDenyBuild) {
return; return;
} }

View File

@ -24,12 +24,8 @@ public class FactionsChatListener implements Listener {
} }
// this is for handling slashless command usage and faction/alliance chat, set at lowest priority so Factions gets to them first // this is for handling slashless command usage and faction/alliance chat, set at lowest priority so Factions gets to them first
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerEarlyChat(AsyncPlayerChatEvent event) { public void onPlayerEarlyChat(AsyncPlayerChatEvent event) {
if (event.isCancelled()) {
return;
}
Player talkingPlayer = event.getPlayer(); Player talkingPlayer = event.getPlayer();
String msg = event.getMessage(); String msg = event.getMessage();
FPlayer me = FPlayers.getInstance().getByPlayer(talkingPlayer); FPlayer me = FPlayers.getInstance().getByPlayer(talkingPlayer);
@ -101,12 +97,8 @@ public class FactionsChatListener implements Listener {
} }
// this is for handling insertion of the player's faction tag, set at highest priority to give other plugins a chance to modify chat first // this is for handling insertion of the player's faction tag, set at highest priority to give other plugins a chance to modify chat first
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerChat(AsyncPlayerChatEvent event) { public void onPlayerChat(AsyncPlayerChatEvent event) {
if (event.isCancelled()) {
return;
}
// Are we to insert the Faction tag into the format? // Are we to insert the Faction tag into the format?
// If we are not to insert it - we are done. // If we are not to insert it - we are done.
if (!Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin) { if (!Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin) {

View File

@ -89,12 +89,8 @@ public class FactionsEntityListener implements Listener {
* Who can I hurt? I can never hurt members or allies. I can always hurt enemies. I can hurt neutrals as long as * Who can I hurt? I can never hurt members or allies. I can always hurt enemies. I can hurt neutrals as long as
* they are outside their own territory. * they are outside their own territory.
*/ */
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) { public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled()) {
return;
}
if (event instanceof EntityDamageByEntityEvent) { if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event; EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
if (!this.canDamagerHurtDamagee(sub, true)) { if (!this.canDamagerHurtDamagee(sub, true)) {
@ -106,12 +102,8 @@ public class FactionsEntityListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
if (event.isCancelled()) {
return;
}
Location loc = event.getLocation(); Location loc = event.getLocation();
Entity boomer = event.getEntity(); Entity boomer = event.getEntity();
Faction faction = Board.getInstance().getFactionAt(new FLocation(loc)); Faction faction = Board.getInstance().getFactionAt(new FLocation(loc));
@ -171,12 +163,8 @@ public class FactionsEntityListener implements Listener {
} }
// mainly for flaming arrows; don't want allies or people in safe zones to be ignited even after damage event is cancelled // mainly for flaming arrows; don't want allies or people in safe zones to be ignited even after damage event is cancelled
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) { public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
if (event.isCancelled()) {
return;
}
EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE, 0); EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE, 0);
if (!this.canDamagerHurtDamagee(sub, false)) { if (!this.canDamagerHurtDamagee(sub, false)) {
event.setCancelled(true); event.setCancelled(true);
@ -186,12 +174,8 @@ public class FactionsEntityListener implements Listener {
private static final Set<PotionEffectType> badPotionEffects = new LinkedHashSet<PotionEffectType>(Arrays.asList(PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, PotionEffectType.HARM, PotionEffectType.HUNGER, PotionEffectType.POISON, PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING, PotionEffectType.WEAKNESS, PotionEffectType.WITHER)); private static final Set<PotionEffectType> badPotionEffects = new LinkedHashSet<PotionEffectType>(Arrays.asList(PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, PotionEffectType.HARM, PotionEffectType.HUNGER, PotionEffectType.POISON, PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING, PotionEffectType.WEAKNESS, PotionEffectType.WITHER));
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPotionSplashEvent(PotionSplashEvent event) { public void onPotionSplashEvent(PotionSplashEvent event) {
if (event.isCancelled()) {
return;
}
// see if the potion has a harmful effect // see if the potion has a harmful effect
boolean badjuju = false; boolean badjuju = false;
for (PotionEffect effect : event.getPotion().getEffects()) { for (PotionEffect effect : event.getPotion().getEffects()) {
@ -411,9 +395,9 @@ public class FactionsEntityListener implements Listener {
return true; return true;
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) { public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.isCancelled() || event.getLocation() == null) { if (event.getLocation() == null) {
return; return;
} }
@ -422,12 +406,8 @@ public class FactionsEntityListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityTarget(EntityTargetEvent event) { public void onEntityTarget(EntityTargetEvent event) {
if (event.isCancelled()) {
return;
}
// if there is a target // if there is a target
Entity target = event.getTarget(); Entity target = event.getTarget();
if (target == null) { if (target == null) {
@ -445,11 +425,8 @@ public class FactionsEntityListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPaintingBreak(HangingBreakEvent event) { public void onPaintingBreak(HangingBreakEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getCause() == RemoveCause.EXPLOSION) { if (event.getCause() == RemoveCause.EXPLOSION) {
Location loc = event.getEntity().getLocation(); Location loc = event.getEntity().getLocation();
Faction faction = Board.getInstance().getFactionAt(new FLocation(loc)); Faction faction = Board.getInstance().getFactionAt(new FLocation(loc));
@ -484,23 +461,15 @@ public class FactionsEntityListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPaintingPlace(HangingPlaceEvent event) { public void onPaintingPlace(HangingPlaceEvent event) {
if (event.isCancelled()) {
return;
}
if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "place paintings", false)) { if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "place paintings", false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityChangeBlock(EntityChangeBlockEvent event) { public void onEntityChangeBlock(EntityChangeBlockEvent event) {
if (event.isCancelled()) {
return;
}
Entity entity = event.getEntity(); Entity entity = event.getEntity();
// for now, only interested in Enderman and Wither boss tomfoolery // for now, only interested in Enderman and Wither boss tomfoolery

View File

@ -13,9 +13,9 @@ import org.bukkit.event.player.PlayerTeleportEvent;
public class FactionsExploitListener implements Listener { public class FactionsExploitListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void obsidianGenerator(BlockFromToEvent event) { public void obsidianGenerator(BlockFromToEvent event) {
if (event.isCancelled() || !Conf.handleExploitObsidianGenerators) { if (!Conf.handleExploitObsidianGenerators) {
return; return;
} }
@ -29,9 +29,9 @@ public class FactionsExploitListener implements Listener {
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void enderPearlTeleport(PlayerTeleportEvent event) { public void enderPearlTeleport(PlayerTeleportEvent event) {
if (event.isCancelled() || !Conf.handleExploitEnderPearlClipping) { if (!Conf.handleExploitEnderPearlClipping) {
return; return;
} }
if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) { if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) {

View File

@ -113,12 +113,8 @@ public class FactionsPlayerListener implements Listener {
// Holds the next time a player can have a map shown. // Holds the next time a player can have a map shown.
private HashMap<UUID, Long> showTimes = new HashMap<UUID, Long>(); private HashMap<UUID, Long> showTimes = new HashMap<UUID, Long>();
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
if (event.isCancelled()) {
return;
}
// clear visualization // clear visualization
if (event.getFrom().getBlockX() != event.getTo().getBlockX() || event.getFrom().getBlockY() != event.getTo().getBlockY() || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) { if (event.getFrom().getBlockX() != event.getTo().getBlockX() || event.getFrom().getBlockY() != event.getTo().getBlockY() || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
VisualizeUtil.clear(event.getPlayer()); VisualizeUtil.clear(event.getPlayer());
@ -202,11 +198,8 @@ public class FactionsPlayerListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.isCancelled()) {
return;
}
// only need to check right-clicks and physical as of MC 1.4+; good performance boost // only need to check right-clicks and physical as of MC 1.4+; good performance boost
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) {
return; return;
@ -442,12 +435,8 @@ public class FactionsPlayerListener implements Listener {
// For some reason onPlayerInteract() sometimes misses bucket events depending on distance (something like 2-3 blocks away isn't detected), // For some reason onPlayerInteract() sometimes misses bucket events depending on distance (something like 2-3 blocks away isn't detected),
// but these separate bucket events below always fire without fail // but these separate bucket events below always fire without fail
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) { public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
if (event.isCancelled()) {
return;
}
Block block = event.getBlockClicked(); Block block = event.getBlockClicked();
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -457,12 +446,8 @@ public class FactionsPlayerListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerBucketFill(PlayerBucketFillEvent event) { public void onPlayerBucketFill(PlayerBucketFillEvent event) {
if (event.isCancelled()) {
return;
}
Block block = event.getBlockClicked(); Block block = event.getBlockClicked();
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -542,12 +527,8 @@ public class FactionsPlayerListener implements Listener {
return false; return false;
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerKick(PlayerKickEvent event) { public void onPlayerKick(PlayerKickEvent event) {
if (event.isCancelled()) {
return;
}
FPlayer badGuy = FPlayers.getInstance().getByPlayer(event.getPlayer()); FPlayer badGuy = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (badGuy == null) { if (badGuy == null) {
return; return;