Use ignoreCancelled for event cancelled checking

This commit is contained in:
zml2008 2012-03-08 19:29:53 -08:00
parent 1463547af4
commit 3d6d774b17
4 changed files with 52 additions and 175 deletions

View File

@ -24,7 +24,6 @@
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -106,12 +105,8 @@ protected WorldConfiguration getWorldConfig(Player player) {
/*
* Called when a block is damaged.
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockDamage(BlockDamageEvent event) {
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
Block blockDamaged = event.getBlock();
@ -129,12 +124,8 @@ public void onBlockDamage(BlockDamageEvent event) {
/*
* Called when a block is broken.
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
WorldConfiguration wcfg = getWorldConfig(player);
@ -183,12 +174,8 @@ public void onBlockBreak(BlockBreakEvent event) {
/*
* Called when fluids flow.
*/
@EventHandler
@EventHandler(ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent event) {
if (event.isCancelled()) {
return;
}
World world = event.getBlock().getWorld();
Block blockFrom = event.getBlock();
Block blockTo = event.getToBlock();
@ -280,12 +267,8 @@ public void onBlockFromTo(BlockFromToEvent event) {
/*
* Called when a block gets ignited.
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockIgnite(BlockIgniteEvent event) {
if (event.isCancelled()) {
return;
}
IgniteCause cause = event.getCause();
Block block = event.getBlock();
World world = block.getWorld();
@ -381,13 +364,8 @@ public void onBlockIgnite(BlockIgniteEvent event) {
/*
* Called when a block is destroyed from burning.
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBurn(BlockBurnEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
@ -459,13 +437,8 @@ private void checkAndDestroy(World world, int x, int y, int z, int required) {
/*
* Called when block physics occurs.
*/
@EventHandler
@EventHandler(ignoreCancelled = true)
public void onBlockPhysics(BlockPhysicsEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
@ -495,13 +468,8 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
/*
* Called when a player places a block.
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
if (event.isCancelled()) {
return;
}
Block blockPlaced = event.getBlock();
Player player = event.getPlayer();
World world = blockPlaced.getWorld();
@ -554,7 +522,6 @@ public void onBlockPlace(BlockPlaceEvent event) {
*/
@EventHandler(priority = EventPriority.HIGH)
public void onBlockRedstoneChange(BlockRedstoneEvent event) {
Block blockTo = event.getBlock();
World world = blockTo.getWorld();
@ -588,9 +555,8 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
/*
* Called when a sign is changed.
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
WorldConfiguration wcfg = getWorldConfig(player);
@ -655,12 +621,8 @@ public void onSignChange(SignChangeEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onLeavesDecay(LeavesDecayEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
@ -685,12 +647,8 @@ public void onLeavesDecay(LeavesDecayEvent event) {
/*
* Called when a block is formed based on world conditions.
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockForm(BlockFormEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
@ -729,12 +687,8 @@ public void onBlockForm(BlockFormEvent event) {
/*
* Called when a block spreads based on world conditions.
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockSpread(BlockSpreadEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
@ -773,11 +727,8 @@ public void onBlockSpread(BlockSpreadEvent event) {
/*
* Called when a block fades.
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockFade(BlockFadeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
@ -812,12 +763,8 @@ public void onBlockFade(BlockFadeEvent event) {
/*
* Called when a piston extends
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
@ -838,12 +785,8 @@ public void onBlockPistonExtend(BlockPistonExtendEvent event) {
/*
* Called when a piston retracts
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

View File

@ -75,7 +75,7 @@
/**
* Listener for entity related events.
*
*
* @author sk89q
*/
public class WorldGuardEntityListener implements Listener {
@ -84,7 +84,7 @@ public class WorldGuardEntityListener implements Listener {
/**
* Construct the object;
*
*
* @param plugin The plugin instance
*/
public WorldGuardEntityListener(WorldGuardPlugin plugin) {
@ -98,7 +98,7 @@ public void registerEvents() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityInteract(EntityInteractEvent event) {
Entity entity = event.getEntity();
Block block = event.getBlock();
@ -184,7 +184,7 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity attacker = event.getDamager();
Entity defender = event.getEntity();
if (attacker instanceof Player) {
Player player = (Player) attacker;
@ -192,7 +192,7 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
WorldConfiguration wcfg = cfg.get(player.getWorld());
ItemStack held = player.getInventory().getItemInHand();
if (held != null) {
if (wcfg.getBlacklist() != null) {
if (!wcfg.getBlacklist().check(
@ -239,7 +239,7 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Vector pt2 = toVector(attacker.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)
|| !mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
event.setCancelled(true);
@ -336,7 +336,7 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(player.getWorld());
if (isInvincible(player)) {
event.setCancelled(true);
return;
@ -348,7 +348,7 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
Vector pt2 = toVector(attacker.getLocation());
RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)
if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer)
|| !mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) {
((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
event.setCancelled(true);
@ -375,11 +375,8 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled()) {
return;
}
if (event instanceof EntityDamageByEntityEvent) {
this.onEntityDamageByEntity((EntityDamageByEntityEvent) event);
@ -414,7 +411,7 @@ public void onEntityDamage(EntityDamageEvent event) {
event.setCancelled(true);
return;
}
ItemStack helmet = player.getInventory().getHelmet();
if (type == DamageCause.DROWNING && wcfg.pumpkinScuba
@ -456,12 +453,8 @@ public void onEntityDamage(EntityDamageEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityCombust(EntityCombustEvent event) {
if (event.isCancelled()) {
return;
}
Entity entity = event.getEntity();
ConfigurationManager cfg = plugin.getGlobalStateManager();
@ -480,12 +473,8 @@ public void onEntityCombust(EntityCombustEvent event) {
/*
* Called on entity explode.
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
Location l = event.getLocation();
World world = l.getWorld();
@ -503,7 +492,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
event.blockList().clear();
return;
}
if (wcfg.blockCreeperExplosions) {
event.setCancelled(true);
return;
@ -544,7 +533,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
event.blockList().clear();
return;
}
if (wcfg.blockTNTExplosions) {
event.setCancelled(true);
return;
@ -565,7 +554,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
event.blockList().clear();
return;
}
if (wcfg.blockFireballExplosions) {
event.setCancelled(true);
return;
@ -597,12 +586,8 @@ public void onEntityExplode(EntityExplodeEvent event) {
/*
* Called on explosion prime
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onExplosionPrime(ExplosionPrimeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
Entity ent = event.getEntity();
@ -614,12 +599,8 @@ public void onExplosionPrime(ExplosionPrimeEvent event) {
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
if (cfg.activityHaltToggle) {
@ -634,9 +615,9 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
event.setCancelled(true);
return;
}
Location eventLoc = event.getLocation();
if (wcfg.useRegions) {
Vector pt = toVector(eventLoc);
RegionManager mgr = plugin.getGlobalRegionManager().get(eventLoc.getWorld());
@ -657,12 +638,8 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPigZap(PigZapEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
@ -671,12 +648,8 @@ public void onPigZap(PigZapEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCreeperPower(CreeperPowerEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getEntity().getWorld());
@ -685,21 +658,17 @@ public void onCreeperPower(CreeperPowerEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPaintingBreak(PaintingBreakEvent breakEvent) {
if (breakEvent.isCancelled()) {
return;
}
if (!(breakEvent instanceof PaintingBreakByEntityEvent)) {
return;
}
PaintingBreakByEntityEvent event = (PaintingBreakByEntityEvent) breakEvent;
if (!(event.getRemover() instanceof Player)) {
return;
}
Painting painting= event.getPainting();
Player player = (Player) event.getRemover();
World world = painting.getWorld();
@ -725,12 +694,8 @@ public void onPaintingBreak(PaintingBreakEvent breakEvent) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPaintingPlace(PaintingPlaceEvent event) {
if (event.isCancelled()) {
return;
}
Block placedOn = event.getBlock();
Player player = event.getPlayer();
World world = placedOn.getWorld();
@ -756,11 +721,8 @@ public void onPaintingPlace(PaintingPlaceEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
if (event.isCancelled()) {
return;
}
Entity ent = event.getEntity();
World world = ent.getWorld();
@ -779,12 +741,8 @@ public void onEntityRegainHealth(EntityRegainHealthEvent event) {
*
* @param event Relevant event details
*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEndermanPickup(EntityChangeBlockEvent event) {
if (event.isCancelled()) {
return;
}
Entity ent = event.getEntity();
Block block = event.getBlock();
Location location = block.getLocation();
@ -826,7 +784,7 @@ public void onEndermanPickup(EntityChangeBlockEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
@ -840,7 +798,7 @@ public void onFoodLevelChange(FoodLevelChangeEvent event) {
* Check if a player is invincible, via either god mode or region flag. If
* the region denies invincibility, the player must have an extra permission
* to override it. (worldguard.god.override-regions)
*
*
* @param player The player to check
* @return Whether {@code player} is invincible
*/

View File

@ -212,7 +212,6 @@ public void onPlayerMove(PlayerMoveEvent event) {
}
}
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
@ -822,12 +821,8 @@ public void onPlayerItem(PlayerItemEvent event) {
}
}*/
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerDropItem(PlayerDropItemEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getPlayer().getWorld());
@ -843,12 +838,8 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getPlayer().getWorld());
@ -865,7 +856,7 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) {
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
@ -890,7 +881,7 @@ public void onPlayerBucketFill(PlayerBucketFillEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
@ -955,12 +946,8 @@ public void onItemHeldChange(PlayerItemHeldEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
Location location = player.getLocation();
@ -981,7 +968,7 @@ public void onPlayerBedEnter(PlayerBedEnterEvent event) {
}
}
@EventHandler(priority = EventPriority.LOWEST)
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
LocalPlayer localPlayer = plugin.wrapPlayer(player);

View File

@ -52,11 +52,8 @@ public void registerEvents() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onWeatherChange(WeatherChangeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getWorld());
@ -71,12 +68,8 @@ public void onWeatherChange(WeatherChangeEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onThunderChange(ThunderChangeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getWorld());
@ -91,12 +84,8 @@ public void onThunderChange(ThunderChangeEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onLightningStrike(LightningStrikeEvent event) {
if (event.isCancelled()) {
return;
}
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(event.getWorld());