summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-12-30 03:31:05 +0000
committerKHobbits <rob@khobbits.co.uk>2012-12-30 03:32:32 +0000
commita1b2773bf570e5d262c7bab9162b9baf84f93b5a (patch)
tree1fd9a41f2bf23a496a023acf43d6c3b435e321ab
parent9ecb501e005bbd1d7723d0680b40cd85810af41b (diff)
downloadEssentials-a1b2773bf570e5d262c7bab9162b9baf84f93b5a.tar
Essentials-a1b2773bf570e5d262c7bab9162b9baf84f93b5a.tar.gz
Essentials-a1b2773bf570e5d262c7bab9162b9baf84f93b5a.tar.lz
Essentials-a1b2773bf570e5d262c7bab9162b9baf84f93b5a.tar.xz
Essentials-a1b2773bf570e5d262c7bab9162b9baf84f93b5a.zip
Reorganize entity listener
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java48
1 files changed, 22 insertions, 26 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
index 74a8654a0..a0d3d091f 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
@@ -30,44 +30,40 @@ public class EssentialsEntityListener implements Listener
{
final Entity eAttack = event.getDamager();
final Entity eDefend = event.getEntity();
- if (eDefend instanceof Player && eAttack instanceof Player)
+ if (eAttack instanceof Player)
{
- final User defender = ess.getUser(eDefend);
final User attacker = ess.getUser(eAttack);
- onPlayerVsPlayerDamage(event, defender, attacker);
- onPlayerVsPlayerPowertool(event, defender, attacker);
- }
- else if (eDefend instanceof Player && eAttack instanceof Projectile)
- {
- Entity shooter = ((Projectile)event.getDamager()).getShooter();
- if (shooter instanceof Player)
+ if (eDefend instanceof Player)
{
- final User defender = ess.getUser(eDefend);
- final User attacker = ess.getUser(shooter);
- onPlayerVsPlayerDamage(event, defender, attacker);
- onPlayerVsPlayerPowertool(event, defender, attacker);
+ onPlayerVsPlayerDamage(event, (Player)eDefend, attacker);
}
- }
- else if (eAttack instanceof Player)
- {
- final User player = ess.getUser(eAttack);
- player.updateActivity(true);
- if (eDefend instanceof Ageable)
+ else if (eDefend instanceof Ageable)
{
- final ItemStack hand = player.getItemInHand();
+ final ItemStack hand = attacker.getItemInHand();
if (hand != null && hand.getType() == Material.MILK_BUCKET)
{
((Ageable)eDefend).setBaby();
hand.setType(Material.BUCKET);
- player.setItemInHand(hand);
- player.updateInventory();
+ attacker.setItemInHand(hand);
+ attacker.updateInventory();
event.setCancelled(true);
}
}
+ attacker.updateActivity(true);
+ }
+ else if (eAttack instanceof Projectile && eDefend instanceof Player)
+ {
+ Entity shooter = ((Projectile)event.getDamager()).getShooter();
+ if (shooter instanceof Player)
+ {
+ final User attacker = ess.getUser(shooter);
+ onPlayerVsPlayerDamage(event, (Player)eDefend, attacker);
+ attacker.updateActivity(true);
+ }
}
}
- private void onPlayerVsPlayerDamage(final EntityDamageByEntityEvent event, final User defender, final User attacker)
+ private void onPlayerVsPlayerDamage(final EntityDamageByEntityEvent event, final Player defender, final User attacker)
{
if (ess.getSettings().getLoginAttackDelay() > 0 && !attacker.isAuthorized("essentials.pvpdelay.exempt")
&& (System.currentTimeMillis() < (attacker.getLastLogin() + ess.getSettings().getLoginAttackDelay())))
@@ -75,7 +71,7 @@ public class EssentialsEntityListener implements Listener
event.setCancelled(true);
}
- if (!attacker.equals(defender) && (attacker.hasInvulnerabilityAfterTeleport() || defender.hasInvulnerabilityAfterTeleport()))
+ if (!defender.equals(attacker.getBase()) && (attacker.hasInvulnerabilityAfterTeleport() || ess.getUser(defender).hasInvulnerabilityAfterTeleport()))
{
event.setCancelled(true);
}
@@ -90,10 +86,10 @@ public class EssentialsEntityListener implements Listener
event.setCancelled(true);
}
- attacker.updateActivity(true);
+ onPlayerVsPlayerPowertool(event, defender, attacker);
}
- private void onPlayerVsPlayerPowertool(final EntityDamageByEntityEvent event, final User defender, final User attacker)
+ private void onPlayerVsPlayerPowertool(final EntityDamageByEntityEvent event, final Player defender, final User attacker)
{
final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
if (commandList != null && !commandList.isEmpty())