From 25ebe68389a74ae5b5faa9780e76afff75a5a963 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Fri, 2 Mar 2012 16:54:12 +0000 Subject: Entity event cleanup --- .../essentials/EssentialsEntityListener.java | 89 ++++++++++------------ 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java index e4879186d..45d78ebeb 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java @@ -24,48 +24,47 @@ public class EssentialsEntityListener implements Listener } @EventHandler(priority = EventPriority.LOWEST) - public void onEntityDamage(EntityDamageEvent event) + public void onEntityDamage(final EntityDamageByEntityEvent event) { - if (event instanceof EntityDamageByEntityEvent) + final Entity eAttack = event.getDamager(); + final Entity eDefend = event.getEntity(); + if (eDefend instanceof Player && eAttack instanceof Player) { - EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event; - Entity eAttack = edEvent.getDamager(); - Entity eDefend = edEvent.getEntity(); - if (eDefend instanceof Player && eAttack instanceof Player) + final User defender = ess.getUser(eDefend); + final User attacker = ess.getUser(eAttack); + attacker.updateActivity(true); + final List commandList = attacker.getPowertool(attacker.getItemInHand()); + if (commandList != null && !commandList.isEmpty()) { - User defender = ess.getUser(eDefend); - User attacker = ess.getUser(eAttack); - attacker.updateActivity(true); - ItemStack is = attacker.getItemInHand(); - List commandList = attacker.getPowertool(is); - if (commandList != null && !commandList.isEmpty()) + for (String command : commandList) { - for (String command : commandList) + if (command != null && !command.isEmpty()) { - - if (command != null && !command.isEmpty()) - { - attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName())); - event.setCancelled(true); - return; - } + attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName())); + event.setCancelled(true); + return; } } } - if (eDefend instanceof Animals && eAttack instanceof Player) + } + else if (eDefend instanceof Animals && eAttack instanceof Player) + { + final User player = ess.getUser(eAttack); + final ItemStack hand = player.getItemInHand(); + if (hand != null && hand.getType() == Material.MILK_BUCKET) { - User player = ess.getUser(eAttack); - ItemStack hand = player.getItemInHand(); - if (hand != null && hand.getType() == Material.MILK_BUCKET) - { - ((Animals)eDefend).setAge(-24000); - hand.setType(Material.BUCKET); - player.setItemInHand(hand); - player.updateInventory(); - event.setCancelled(true); - } + ((Animals)eDefend).setAge(-24000); + hand.setType(Material.BUCKET); + player.setItemInHand(hand); + player.updateInventory(); + event.setCancelled(true); } } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onEntityDamage(final EntityDamageEvent event) + { if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) { final Player player = (Player)event.getEntity(); @@ -76,7 +75,7 @@ public class EssentialsEntityListener implements Listener } @EventHandler(priority = EventPriority.LOWEST) - public void onEntityCombust(EntityCombustEvent event) + public void onEntityCombust(final EntityCombustEvent event) { if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) { @@ -85,26 +84,22 @@ public class EssentialsEntityListener implements Listener } @EventHandler(priority = EventPriority.LOWEST) - public void onEntityDeath(final EntityDeathEvent event) + public void onPlayerDeathEvent(final PlayerDeathEvent event) { - if (event instanceof PlayerDeathEvent) + final User user = ess.getUser(event.getEntity()); + if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back")) { - final PlayerDeathEvent pdevent = (PlayerDeathEvent)event; - final User user = ess.getUser(pdevent.getEntity()); - if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back")) - { - user.setLastLocation(); - user.sendMessage(_("backAfterDeath")); - } - if (!ess.getSettings().areDeathMessagesEnabled()) - { - pdevent.setDeathMessage(""); - } + user.setLastLocation(); + user.sendMessage(_("backAfterDeath")); + } + if (!ess.getSettings().areDeathMessagesEnabled()) + { + event.setDeathMessage(""); } } @EventHandler(priority = EventPriority.LOWEST) - public void onFoodLevelChange(FoodLevelChangeEvent event) + public void onFoodLevelChange(final FoodLevelChangeEvent event) { if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) { @@ -113,7 +108,7 @@ public class EssentialsEntityListener implements Listener } @EventHandler(priority = EventPriority.LOWEST) - public void onEntityRegainHealth(EntityRegainHealthEvent event) + public void onEntityRegainHealth(final EntityRegainHealthEvent event) { if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isAfk() && ess.getSettings().getFreezeAfkPlayers()) -- cgit v1.2.3