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

This commit is contained in:
Brettflan 2011-07-29 06:39:20 -05:00
parent e3cb829e6b
commit 63ab41f933
2 changed files with 21 additions and 8 deletions

View File

@ -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;

View File

@ -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();