Entity event cleanup

This commit is contained in:
KHobbits 2012-03-02 16:54:12 +00:00
parent 016299a1dd
commit 8450734cf1

View file

@ -24,25 +24,20 @@ public class EssentialsEntityListener implements Listener
}
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamage(EntityDamageEvent event)
public void onEntityDamage(final EntityDamageByEntityEvent event)
{
if (event instanceof EntityDamageByEntityEvent)
{
EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event;
Entity eAttack = edEvent.getDamager();
Entity eDefend = edEvent.getEntity();
final Entity eAttack = event.getDamager();
final Entity eDefend = event.getEntity();
if (eDefend instanceof Player && eAttack instanceof Player)
{
User defender = ess.getUser(eDefend);
User attacker = ess.getUser(eAttack);
final User defender = ess.getUser(eDefend);
final User attacker = ess.getUser(eAttack);
attacker.updateActivity(true);
ItemStack is = attacker.getItemInHand();
List<String> commandList = attacker.getPowertool(is);
final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
if (commandList != null && !commandList.isEmpty())
{
for (String command : commandList)
{
if (command != null && !command.isEmpty())
{
attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
@ -52,10 +47,10 @@ public class EssentialsEntityListener implements Listener
}
}
}
if (eDefend instanceof Animals && eAttack instanceof Player)
else if (eDefend instanceof Animals && eAttack instanceof Player)
{
User player = ess.getUser(eAttack);
ItemStack hand = player.getItemInHand();
final User player = ess.getUser(eAttack);
final ItemStack hand = player.getItemInHand();
if (hand != null && hand.getType() == Material.MILK_BUCKET)
{
((Animals)eDefend).setAge(-24000);
@ -66,6 +61,10 @@ public class EssentialsEntityListener implements Listener
}
}
}
@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,12 +84,9 @@ 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 PlayerDeathEvent pdevent = (PlayerDeathEvent)event;
final User user = ess.getUser(pdevent.getEntity());
final User user = ess.getUser(event.getEntity());
if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back"))
{
user.setLastLocation();
@ -98,13 +94,12 @@ public class EssentialsEntityListener implements Listener
}
if (!ess.getSettings().areDeathMessagesEnabled())
{
pdevent.setDeathMessage("");
}
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())