From 9e7ec98789a25283ceda9f7b383f1467ee0bfd6b Mon Sep 17 00:00:00 2001 From: TimWolla Date: Sun, 22 May 2011 22:34:18 +0200 Subject: [PATCH] Finished regain-health-prevention --- war/src/main/java/bukkit/tommytony/war/War.java | 1 + .../bukkit/tommytony/war/WarEntityListener.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index c4b86e0..7e49912 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -156,6 +156,7 @@ public class War extends JavaPlugin { pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Priority.Normal, this); + pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this); diff --git a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java index 53b67d8..acd4fc3 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java @@ -208,8 +208,18 @@ public class WarEntityListener extends EntityListener { } public void onEntityRegainHealth(EntityRegainHealthEvent event) { - if(!war.isLoaded()) return; - if (((org.bukkit.craftbukkit.entity.CraftPlayer) event.getEntity()).getHandle().ticksLived % 20 * 12 == 0) - event.setCancelled(true); + if(war.isLoaded()) { + Entity entity = event.getEntity(); + if(entity instanceof Player) { + Player player = (Player) entity; + Location location = player.getLocation(); + Warzone zone = war.warzone(location); + if(zone != null) { + if (((CraftPlayer) player).getHandle().ticksLived % 20 * 12 == 0) { + event.setCancelled(true); + } + } + } + } } }