From 9040a2a2e3ffe606849d8725f7a36c5b08be2802 Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 18 Jun 2012 08:50:14 -0400 Subject: [PATCH] Optimizations to Combat.java --- .../java/com/gmail/nossr50/util/Combat.java | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/Combat.java b/src/main/java/com/gmail/nossr50/util/Combat.java index a057d870f..7d59969d9 100644 --- a/src/main/java/com/gmail/nossr50/util/Combat.java +++ b/src/main/java/com/gmail/nossr50/util/Combat.java @@ -33,7 +33,7 @@ import com.gmail.nossr50.runnables.GainXp; import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.archery.ArcheryManager; import com.gmail.nossr50.skills.combat.Axes; -import com.gmail.nossr50.skills.combat.Swords; +import com.gmail.nossr50.skills.swords.Swords; import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.unarmed.UnarmedManager; @@ -362,9 +362,6 @@ public class Combat { break; } - PlayerAnimationEvent armswing = new PlayerAnimationEvent(attacker); - mcMMO.p.getServer().getPluginManager().callEvent(armswing); - if (entity instanceof Player) { Player defender = (Player) entity; @@ -386,16 +383,13 @@ public class Combat { continue; } } - else if (entity instanceof Tameable) { - AnimalTamer tamer = ((Tameable) entity).getOwner(); - - if (tamer instanceof Player) { - if (tamer.equals(attacker) || PartyManager.getInstance().inSameParty(attacker, (Player) tamer)) { - continue; - } - } + else if (!shouldBeAffected(attacker, target)) { + continue; } + PlayerAnimationEvent armswing = new PlayerAnimationEvent(attacker); + mcMMO.p.getServer().getPluginManager().callEvent(armswing); + switch (type) { case SWORDS: if (entity instanceof Player) { @@ -523,4 +517,33 @@ public class Combat { mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GainXp(attacker, PP, skillType, baseXP, target), 0); } } + + /** + * Check to see if the given LivingEntity should be affected by a combat ability. + * + * @param player The attacking Player + * @param livingEntity The defending LivingEntity + * @return true if the LivingEntity should be damaged, false otherwise. + */ + public static boolean shouldBeAffected(Player player, LivingEntity livingEntity) { + boolean isAffected = true; + + if (livingEntity instanceof Tameable) { + Tameable pet = (Tameable) livingEntity; + + if (pet.isTamed()) { + AnimalTamer tamer = pet.getOwner(); + + if (tamer instanceof Player) { + Player owner = (Player) tamer; + + if (owner == player || PartyManager.getInstance().inSameParty(player, owner)) { + isAffected = false; + } + } + } + } + + return isAffected; + } }