From 4316469ec15f629c7ad77386af9d4ee3f281cd37 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sun, 13 Feb 2011 09:33:42 +0100 Subject: [PATCH] Arrow attacks are now included in the friendly fire filter --- plugin.yml | 2 +- src/com/bukkit/mcteam/factions/Commands.java | 1 - src/com/bukkit/mcteam/factions/Factions.java | 3 +- .../listeners/FactionsEntityListener.java | 54 +++++++++++-------- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/plugin.yml b/plugin.yml index 375a8f38..2fefe410 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,3 +1,3 @@ name: Factions -version: 1.0 beta3 +version: 1.0 beta4 main: com.bukkit.mcteam.factions.Factions \ No newline at end of file diff --git a/src/com/bukkit/mcteam/factions/Commands.java b/src/com/bukkit/mcteam/factions/Commands.java index 028b74c8..748c51c2 100644 --- a/src/com/bukkit/mcteam/factions/Commands.java +++ b/src/com/bukkit/mcteam/factions/Commands.java @@ -1,7 +1,6 @@ package com.bukkit.mcteam.factions; import java.util.*; -import java.util.logging.Logger; import org.bukkit.ChatColor; diff --git a/src/com/bukkit/mcteam/factions/Factions.java b/src/com/bukkit/mcteam/factions/Factions.java index 72823380..58fd812d 100644 --- a/src/com/bukkit/mcteam/factions/Factions.java +++ b/src/com/bukkit/mcteam/factions/Factions.java @@ -52,9 +52,10 @@ public class Factions extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, this.entityListener, Event.Priority.Normal, this); + pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_PROJECTILE, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_DAMAGED, this.blockListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_PLACED, this.blockListener, Event.Priority.Normal, this); - pm.registerEvent(Event.Type.BLOCK_INTERACT, this.blockListener, Event.Priority.Normal, this); + pm.registerEvent(Event.Type.BLOCK_INTERACT, this.blockListener, Event.Priority.Normal, this); Log.info("=== INIT DONE (Took "+(System.currentTimeMillis()-timeInitStart)+"ms) ==="); Log.threshold = Conf.logThreshold; diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java index 26a78472..21246f35 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java @@ -42,50 +42,66 @@ public class FactionsEntityListener extends EntityListener { */ @Override public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { - if (event.isCancelled()) { + if ( event.isCancelled()) { return; // Some other plugin decided. Alright then. } - Entity entity = event.getEntity(); - if ( ! (entity instanceof Player)) { - return; + if ( ! this.canDamagerHurtDamagee(event.getDamager(), event.getEntity(), event.getDamage())) { + event.setCancelled(true); + } + } + + @Override + public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) { + //DamageCause dc = event.getCause(); + //Log.debug("dc.toString(): "+dc.toString()); + //Log.debug("event.getDamager().getClass(): "+event.getDamager().getClass()); + //Log.debug("event.getEntity().getClass(): "+event.getEntity().getClass()); + + if ( event.isCancelled()) { + return; // Some other plugin decided. Alright then. } - Entity damager = event.getDamager(); + if ( ! this.canDamagerHurtDamagee(event.getDamager(), event.getEntity(), event.getDamage())) { + event.setCancelled(true); + } + } + + public boolean canDamagerHurtDamagee(Entity damager, Entity damagee, int damage) { if ( ! (damager instanceof Player)) { - return; + return true; } - Log.debug(((Player)entity).getName()+ " is the defender"); - Log.debug(((Player)damager).getName()+ " is the damager"); + if ( ! (damagee instanceof Player)) { + return true; + } - Follower defender = Follower.get((Player)entity); + Follower defender = Follower.get((Player)damagee); Follower attacker = Follower.get((Player)damager); Relation relation = defender.getRelation(attacker); + Log.debug(attacker.getName() + " attacked " + defender.getName()); + // Players without faction may be hurt anywhere if (defender.factionId == 0) { - return; + return true; } // You can never hurt faction members or allies if (relation == Relation.MEMBER || relation == Relation.ALLY) { attacker.sendMessage(Conf.colorSystem+"You can't hurt "+defender.getNameAndRelevant(attacker)); - event.setCancelled(true); - return; + return false; } // You can not hurt neutrals in their own territory. if (relation == Relation.NEUTRAL && defender.isInOwnTerritory()) { attacker.sendMessage(Conf.colorSystem+"You can't hurt "+relation.getColor()+defender.getNameAndRelevant(attacker)+" in their own territory."); defender.sendMessage(attacker.getNameAndRelevant(defender)+Conf.colorSystem+" tried to hurt you."); - event.setCancelled(true); - return; + return false; } // Damage will be dealt. However check if the damage should be reduced. - if (defender.isInOwnTerritory()) { - int damage = event.getDamage(); + if (defender.isInOwnTerritory() && Conf.territoryShieldFactor > 0) { int toHeal = (int)(damage * Conf.territoryShieldFactor); defender.heal(toHeal); @@ -95,10 +111,6 @@ public class FactionsEntityListener extends EntityListener { defender.sendMessage(Conf.colorSystem+"Enemy damage reduced by "+ChatColor.RED+hearts+Conf.colorSystem+" hearts."); } + return true; } - - /*@Override - public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) { - event. - }*/ }