summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-11-04 17:31:57 +0000
committerKHobbits <rob@khobbits.co.uk>2012-11-04 17:31:57 +0000
commit10244d5f90a5fdc8f90327c40ff37b0803677372 (patch)
tree5927b107c76042475e6b04f4ca7b307128045b2b
parent6f1a70dc8bc4fca8098c972c2c9ff10bad711826 (diff)
downloadEssentials-10244d5f90a5fdc8f90327c40ff37b0803677372.tar
Essentials-10244d5f90a5fdc8f90327c40ff37b0803677372.tar.gz
Essentials-10244d5f90a5fdc8f90327c40ff37b0803677372.tar.lz
Essentials-10244d5f90a5fdc8f90327c40ff37b0803677372.tar.xz
Essentials-10244d5f90a5fdc8f90327c40ff37b0803677372.zip
Fix godmode pvp protection not blocking thrown pots and arrows.
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java113
1 files changed, 65 insertions, 48 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
index 0c4d7b9e1..e93c61952 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
@@ -5,10 +5,7 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Material;
-import org.bukkit.entity.Ageable;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.LivingEntity;
-import org.bukkit.entity.Player;
+import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -37,51 +34,18 @@ public class EssentialsEntityListener implements Listener
{
final User defender = ess.getUser(eDefend);
final User attacker = ess.getUser(eAttack);
-
- if (ess.getSettings().getLoginAttackDelay() > 0 && !attacker.isAuthorized("essentials.pvpdelay.exempt")
- && (System.currentTimeMillis() < (attacker.getLastLogin() + ess.getSettings().getLoginAttackDelay())))
- {
- event.setCancelled(true);
- }
-
- if (attacker.hasInvulnerabilityAfterTeleport() || defender.hasInvulnerabilityAfterTeleport())
- {
- event.setCancelled(true);
- }
-
- if (attacker.isGodModeEnabled() && !attacker.isAuthorized("essentials.god.pvp"))
- {
- event.setCancelled(true);
- }
-
- if (attacker.isHidden() && !attacker.isAuthorized("essentials.vanish.pvp"))
- {
- event.setCancelled(true);
- }
-
- attacker.updateActivity(true);
- final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
- if (commandList != null && !commandList.isEmpty())
+ 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)
{
- for (final String command : commandList)
- {
- if (command != null && !command.isEmpty())
- {
- ess.scheduleSyncDelayedTask(
- new Runnable()
- {
- @Override
- public void run()
- {
- attacker.getServer().dispatchCommand(attacker.getBase(), command.replaceAll("\\{player\\}", defender.getName()));
- LOGGER.log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command));
- }
- });
-
- event.setCancelled(true);
- return;
- }
- }
+ final User defender = ess.getUser(eDefend);
+ final User attacker = ess.getUser(shooter);
+ onPlayerVsPlayerDamage(event, defender, attacker);
+ onPlayerVsPlayerPowertool(event, defender, attacker);
}
}
else if (eAttack instanceof Player)
@@ -103,6 +67,59 @@ public class EssentialsEntityListener implements Listener
}
}
+ private void onPlayerVsPlayerDamage(final EntityDamageByEntityEvent event, final User defender, final User attacker)
+ {
+ if (ess.getSettings().getLoginAttackDelay() > 0 && !attacker.isAuthorized("essentials.pvpdelay.exempt")
+ && (System.currentTimeMillis() < (attacker.getLastLogin() + ess.getSettings().getLoginAttackDelay())))
+ {
+ event.setCancelled(true);
+ }
+
+ if (attacker.hasInvulnerabilityAfterTeleport() || defender.hasInvulnerabilityAfterTeleport())
+ {
+ event.setCancelled(true);
+ }
+
+ if (attacker.isGodModeEnabled() && !attacker.isAuthorized("essentials.god.pvp"))
+ {
+ event.setCancelled(true);
+ }
+
+ if (attacker.isHidden() && !attacker.isAuthorized("essentials.vanish.pvp"))
+ {
+ event.setCancelled(true);
+ }
+
+ attacker.updateActivity(true);
+ }
+
+ private void onPlayerVsPlayerPowertool(final EntityDamageByEntityEvent event, final User defender, final User attacker)
+ {
+ final List<String> commandList = attacker.getPowertool(attacker.getItemInHand());
+ if (commandList != null && !commandList.isEmpty())
+ {
+ for (final String command : commandList)
+ {
+ if (command != null && !command.isEmpty())
+ {
+ ess.scheduleSyncDelayedTask(
+ new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ attacker.getServer().dispatchCommand(attacker.getBase(), command.replaceAll("\\{player\\}", defender.getName()));
+ LOGGER.log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command));
+ }
+ });
+
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+ }
+
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageEvent event)
{