From 89ddf8c4fa4320ffd09129ff45c48399dc3dbf79 Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 9 Sep 2013 12:44:03 -0400 Subject: [PATCH] Fixed issues with dealing damage to Entities --- .../java/com/gmail/nossr50/listeners/EntityListener.java | 9 +++++++-- src/main/java/com/gmail/nossr50/mcMMO.java | 1 + .../java/com/gmail/nossr50/util/skills/CombatUtils.java | 9 ++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 8f6d11b1a..65df4e463 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -134,6 +134,11 @@ public class EntityListener implements Listener { Entity defender = event.getEntity(); + if (defender.hasMetadata(mcMMO.customDamageKey)) { + defender.removeMetadata(mcMMO.customDamageKey, plugin); + return; + } + if (Misc.isNPCEntity(defender) || !defender.isValid() || !(defender instanceof LivingEntity)) { return; } @@ -344,12 +349,12 @@ public class EntityListener implements Listener { if (entity.hasMetadata(mcMMO.customNameKey)) { entity.setCustomName(entity.getMetadata(mcMMO.customNameKey).get(0).asString()); - entity.removeMetadata(mcMMO.customNameKey, mcMMO.p); + entity.removeMetadata(mcMMO.customNameKey, plugin); } if (entity.hasMetadata(mcMMO.customVisibleKey)) { entity.setCustomNameVisible(entity.getMetadata(mcMMO.customVisibleKey).get(0).asBoolean()); - entity.removeMetadata(mcMMO.customVisibleKey, mcMMO.p); + entity.removeMetadata(mcMMO.customVisibleKey, plugin); } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 4cfda8537..f240eed15 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -97,6 +97,7 @@ public class mcMMO extends JavaPlugin { public final static String infiniteArrowKey = "mcMMO: Infinite Arrow"; public final static String bowForceKey = "mcMMO: Bow Force"; public final static String arrowDistanceKey = "mcMMO: Arrow Distance"; + public final static String customDamageKey = "mcMMO: Custom Damage"; public static FixedMetadataValue metadataValue; diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index dc9395a5a..5f343a356 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -389,7 +389,14 @@ public final class CombatUtils { startGainXp(mcMMOPlayer, target, skill); } - target.damage(damage); + int damageTicks = target.getNoDamageTicks(); + double lastDamage = target.getLastDamage(); + + target.setMetadata(mcMMO.customDamageKey, mcMMO.metadataValue); + target.damage(damage, attacker); + + target.setNoDamageTicks(damageTicks); + target.setLastDamage(lastDamage); } /**