Use deprecated events for damage dealing for now

This commit is contained in:
TfT_02 2014-07-11 21:33:35 +02:00
parent d2d70089ca
commit 8e3e1d5f11
3 changed files with 23 additions and 6 deletions

View File

@ -1,18 +1,23 @@
package com.gmail.nossr50.events.fake; package com.gmail.nossr50.events.fake;
import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.google.common.base.Function; 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. * Called when mcMMO applies damage from an entity due to special abilities.
*/ */
public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent { public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent {
public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, final Map<DamageModifier, Double> modifiers, final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) { private static final Function<? super Double, Double> ZERO = Functions.constant(-0.0);
super(damager, damagee, cause, modifiers, modifierFunctions);
public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, final Map<DamageModifier, Double> modifiers) {
super(damager, damagee, cause, modifiers, new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, ZERO)));
} }
@Deprecated @Deprecated

View File

@ -1,18 +1,23 @@
package com.gmail.nossr50.events.fake; package com.gmail.nossr50.events.fake;
import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import com.google.common.base.Function; 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. * Called when mcMMO applies damage due to special abilities.
*/ */
public class FakeEntityDamageEvent extends EntityDamageEvent { public class FakeEntityDamageEvent extends EntityDamageEvent {
public FakeEntityDamageEvent(Entity damagee, DamageCause cause, final Map<DamageModifier, Double> modifiers, final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) { private static final Function<? super Double, Double> ZERO = Functions.constant(-0.0);
super(damagee, cause, modifiers, modifierFunctions);
public FakeEntityDamageEvent(Entity damagee, DamageCause cause, final Map<DamageModifier, Double> modifiers) {
super(damagee, cause, modifiers, new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, ZERO)));
} }
@Deprecated @Deprecated

View File

@ -602,7 +602,14 @@ public final class CombatUtils {
@Deprecated @Deprecated
public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause damageCause, double damage) { public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause damageCause, double damage) {
return callFakeDamageEvent(attacker, target, damageCause, new EnumMap<DamageModifier, Double>(ImmutableMap.of(DamageModifier.BASE, damage))); EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, damageCause, damage) : new FakeEntityDamageByEntityEvent(attacker, target, damageCause, damage);
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
if (damageEvent.isCancelled()) {
return 0;
}
return damageEvent.getFinalDamage();
} }
public static double callFakeDamageEvent(Entity attacker, Entity target, Map<DamageModifier, Double> modifiers) { public static double callFakeDamageEvent(Entity attacker, Entity target, Map<DamageModifier, Double> modifiers) {
@ -614,7 +621,7 @@ public final class CombatUtils {
} }
public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause cause, Map<DamageModifier, Double> modifiers) { public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause cause, Map<DamageModifier, Double> modifiers) {
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, cause, modifiers, null) : new FakeEntityDamageByEntityEvent(attacker, target, cause, modifiers, null); EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, cause, modifiers) : new FakeEntityDamageByEntityEvent(attacker, target, cause, modifiers);
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent); mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
if (damageEvent.isCancelled()) { if (damageEvent.isCancelled()) {