From d93c83f77550fe6c070c96d648edb339189456a7 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Fri, 18 Jul 2014 00:16:12 +0200 Subject: [PATCH] Add a modifier function for each DamageModifier Must have a modifier function for each DamageModifier Fixes #2139 --- .../fake/FakeEntityDamageByEntityEvent.java | 16 +++++++++++++--- .../events/fake/FakeEntityDamageEvent.java | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java index 3f66088fe..45af0a0bf 100644 --- a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java @@ -8,20 +8,30 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import com.google.common.base.Function; import com.google.common.base.Functions; -import com.google.common.collect.ImmutableMap; /** * Called when mcMMO applies damage from an entity due to special abilities. */ public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent { - private static final Function ZERO = Functions.constant(-0.0); + private static final EnumMap> functionModifiers = getFunctionModifiers(); public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, final Map modifiers) { - super(damager, damagee, cause, modifiers, new EnumMap>(ImmutableMap.of(DamageModifier.BASE, ZERO))); + super(damager, damagee, cause, modifiers, functionModifiers); } @Deprecated public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, double damage) { super(damager, damagee, cause, damage); } + + public static EnumMap> getFunctionModifiers() { + EnumMap> modifierFunctions = new EnumMap>(DamageModifier.class); + Function ZERO = Functions.constant(-0.0); + + for (DamageModifier modifier : DamageModifier.values()) { + modifierFunctions.put(modifier, ZERO); + } + + return modifierFunctions; + } } diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java index 0c3f89edb..c74afe443 100644 --- a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java @@ -8,20 +8,30 @@ import org.bukkit.event.entity.EntityDamageEvent; import com.google.common.base.Function; import com.google.common.base.Functions; -import com.google.common.collect.ImmutableMap; /** * Called when mcMMO applies damage due to special abilities. */ public class FakeEntityDamageEvent extends EntityDamageEvent { - private static final Function ZERO = Functions.constant(-0.0); + private static final EnumMap> functionModifiers = getFunctionModifiers(); public FakeEntityDamageEvent(Entity damagee, DamageCause cause, final Map modifiers) { - super(damagee, cause, modifiers, new EnumMap>(ImmutableMap.of(DamageModifier.BASE, ZERO))); + super(damagee, cause, modifiers, functionModifiers); } @Deprecated public FakeEntityDamageEvent(Entity damagee, DamageCause cause, double damage) { super(damagee, cause, damage); } + + public static EnumMap> getFunctionModifiers() { + EnumMap> modifierFunctions = new EnumMap>(DamageModifier.class); + Function ZERO = Functions.constant(-0.0); + + for (DamageModifier modifier : DamageModifier.values()) { + modifierFunctions.put(modifier, ZERO); + } + + return modifierFunctions; + } }