summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-03-02 16:54:12 +0000
committerKHobbits <rob@khobbits.co.uk>2012-03-05 08:35:47 +0000
commit8450734cf115aa8ee11910705118799424791e40 (patch)
treed22d679242b7b2d31c65ea6fed917e754351959f
parent016299a1ddf7dd3bd5cf5fe26a96ad9909e8b8e5 (diff)
downloadEssentials-8450734cf115aa8ee11910705118799424791e40.tar
Essentials-8450734cf115aa8ee11910705118799424791e40.tar.gz
Essentials-8450734cf115aa8ee11910705118799424791e40.tar.lz
Essentials-8450734cf115aa8ee11910705118799424791e40.tar.xz
Essentials-8450734cf115aa8ee11910705118799424791e40.zip
Entity event cleanup
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java89
1 files 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<String> 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<String> 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())