Entity event cleanup

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

View File

@ -24,48 +24,47 @@ public class EssentialsEntityListener implements Listener
} }
@EventHandler(priority = EventPriority.LOWEST) @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; final User defender = ess.getUser(eDefend);
Entity eAttack = edEvent.getDamager(); final User attacker = ess.getUser(eAttack);
Entity eDefend = edEvent.getEntity(); attacker.updateActivity(true);
if (eDefend instanceof Player && eAttack instanceof Player) final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
if (commandList != null && !commandList.isEmpty())
{ {
User defender = ess.getUser(eDefend); for (String command : commandList)
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) if (command != null && !command.isEmpty())
{ {
attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
if (command != null && !command.isEmpty()) 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); ((Animals)eDefend).setAge(-24000);
ItemStack hand = player.getItemInHand(); hand.setType(Material.BUCKET);
if (hand != null && hand.getType() == Material.MILK_BUCKET) player.setItemInHand(hand);
{ player.updateInventory();
((Animals)eDefend).setAge(-24000); event.setCancelled(true);
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()) if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
{ {
final Player player = (Player)event.getEntity(); final Player player = (Player)event.getEntity();
@ -76,7 +75,7 @@ public class EssentialsEntityListener implements Listener
} }
@EventHandler(priority = EventPriority.LOWEST) @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()) if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
{ {
@ -85,26 +84,22 @@ public class EssentialsEntityListener implements Listener
} }
@EventHandler(priority = EventPriority.LOWEST) @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; user.setLastLocation();
final User user = ess.getUser(pdevent.getEntity()); user.sendMessage(_("backAfterDeath"));
if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back")) }
{ if (!ess.getSettings().areDeathMessagesEnabled())
user.setLastLocation(); {
user.sendMessage(_("backAfterDeath")); event.setDeathMessage("");
}
if (!ess.getSettings().areDeathMessagesEnabled())
{
pdevent.setDeathMessage("");
}
} }
} }
@EventHandler(priority = EventPriority.LOWEST) @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()) if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
{ {
@ -113,7 +108,7 @@ public class EssentialsEntityListener implements Listener
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onEntityRegainHealth(EntityRegainHealthEvent event) public void onEntityRegainHealth(final EntityRegainHealthEvent event)
{ {
if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player
&& ess.getUser(event.getEntity()).isAfk() && ess.getSettings().getFreezeAfkPlayers()) && ess.getUser(event.getEntity()).isAfk() && ess.getSettings().getFreezeAfkPlayers())