From 63ab41f93312545764e977e0928ddbafe084ae46 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Fri, 29 Jul 2011 06:39:20 -0500 Subject: [PATCH] New conf.json option "safeZonePreventAllDamageToPlayers" (default false) which will prevent all damage to players while they're in a Safe Zone; note that attack damage from other players and monsters is still prevented regardless --- src/com/massivecraft/factions/Conf.java | 1 + .../listeners/FactionsEntityListener.java | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index e955e427..7de2e83a 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -99,6 +99,7 @@ public class Conf { public static boolean safeZoneDenyBuild = true; public static boolean safeZoneDenyUseage = true; public static boolean safeZoneBlockTNT = true; + public static boolean safeZonePreventAllDamageToPlayers = false; public static boolean warZoneDenyBuild = true; public static boolean warZoneDenyUseage = true; diff --git a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java index a950bbff..b3176fa2 100644 --- a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -73,18 +73,20 @@ public class FactionsEntityListener extends EntityListener { } if (event instanceof EntityDamageByEntityEvent) { - EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent)event; - if ( ! this.canDamagerHurtDamagee(sub)) { + EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent)event; + if ( ! this.canDamagerHurtDamagee(sub)) { event.setCancelled(true); } - } else if (event instanceof EntityDamageByProjectileEvent) { - EntityDamageByProjectileEvent sub = (EntityDamageByProjectileEvent)event; - if ( ! this.canDamagerHurtDamagee(sub)) { + } else if (event instanceof EntityDamageByProjectileEvent) { + EntityDamageByProjectileEvent sub = (EntityDamageByProjectileEvent)event; + if ( ! this.canDamagerHurtDamagee(sub)) { event.setCancelled(true); } - } + } else if (Conf.safeZonePreventAllDamageToPlayers && isPlayerInSafeZone(event.getEntity())) { + // Players can not take any damage in a Safe Zone + event.setCancelled(true); + } } - @Override public void onEntityExplode(EntityExplodeEvent event) @@ -125,7 +127,17 @@ public class FactionsEntityListener extends EntityListener { event.setCancelled(true); } } - + + public boolean isPlayerInSafeZone(Entity damagee) { + if ( ! (damagee instanceof Player)) { + return false; + } + if (Board.getFactionAt(new FLocation(damagee.getLocation())).isSafeZone()) { + return true; + } + return false; + } + public boolean canDamagerHurtDamagee(EntityDamageByEntityEvent sub) { Entity damager = sub.getDamager(); Entity damagee = sub.getEntity();