When we added the new API in EntityDamageEvent to give control over the various things that modify the final damage done we caused a change in behavior for users of the old #setDamage(double) method. Before changing the damage would happen before the modifiers were calculated so they would be based on the final damage value from the event. Now they are calculated at the beginning so changing the damage does not change the modifiers. To allow the old style and the new to coexist we now expose the vanilla modifer calculations to the event in the form of Function objects. These are used in #setDamage(double) to calculate the difference in the modifier between the old damage and the new and apply this difference to the current modifier. The difference is between the vanilla values for both damage values and is applied on top of the event's modifier value as this should make old and new API usage work together in a way that isn't surprising.
40 lines
1.2 KiB
Java
40 lines
1.2 KiB
Java
package org.bukkit.event.entity;
|
|
|
|
import java.util.Map;
|
|
|
|
import com.google.common.base.Function;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.entity.Entity;
|
|
|
|
/**
|
|
* Called when an entity is damaged by a block
|
|
*/
|
|
public class EntityDamageByBlockEvent extends EntityDamageEvent {
|
|
private final Block damager;
|
|
|
|
@Deprecated
|
|
public EntityDamageByBlockEvent(final Block damager, final Entity damagee, final DamageCause cause, final int damage) {
|
|
this(damager, damagee, cause, (double) damage);
|
|
}
|
|
|
|
@Deprecated
|
|
public EntityDamageByBlockEvent(final Block damager, final Entity damagee, final DamageCause cause, final double damage) {
|
|
super(damagee, cause, damage);
|
|
this.damager = damager;
|
|
}
|
|
|
|
public EntityDamageByBlockEvent(final Block damager, final Entity damagee, final DamageCause cause, final Map<DamageModifier, Double> modifiers, final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
|
super(damagee, cause, modifiers, modifierFunctions);
|
|
this.damager = damager;
|
|
}
|
|
|
|
/**
|
|
* Returns the block that damaged the player.
|
|
*
|
|
* @return Block that damaged the player
|
|
*/
|
|
public Block getDamager() {
|
|
return damager;
|
|
}
|
|
}
|