mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-16 06:30:46 +01:00
SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent
By: Doc <nachito94@msn.com>
This commit is contained in:
parent
eb7e6bde61
commit
ba1db8acb9
1 changed files with 18 additions and 4 deletions
|
@ -3,6 +3,7 @@ package org.bukkit.event.entity;
|
|||
import com.google.common.base.Function;
|
||||
import java.util.Map;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.damage.DamageSource;
|
||||
import org.bukkit.damage.DamageType;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -14,25 +15,28 @@ import org.jetbrains.annotations.Nullable;
|
|||
*/
|
||||
public class EntityDamageByBlockEvent extends EntityDamageEvent {
|
||||
private final Block damager;
|
||||
private final BlockState damagerState;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, final double damage) {
|
||||
this(damager, damagee, cause, (damager != null) ? DamageSource.builder(DamageType.GENERIC).withDamageLocation(damager.getLocation()).build() : DamageSource.builder(DamageType.GENERIC).build(), damage);
|
||||
this(damager, (damager != null) ? damager.getState() : null, damagee, cause, (damager != null) ? DamageSource.builder(DamageType.GENERIC).withDamageLocation(damager.getLocation()).build() : DamageSource.builder(DamageType.GENERIC).build(), damage);
|
||||
}
|
||||
|
||||
public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, final double damage) {
|
||||
public EntityDamageByBlockEvent(@Nullable final Block damager, @Nullable final BlockState damagerState, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, final double damage) {
|
||||
super(damagee, cause, damageSource, damage);
|
||||
this.damager = damager;
|
||||
this.damagerState = damagerState;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
this(damager, damagee, cause, (damager != null) ? DamageSource.builder(DamageType.GENERIC).withDamageLocation(damager.getLocation()).build() : DamageSource.builder(DamageType.GENERIC).build(), modifiers, modifierFunctions);
|
||||
this(damager, (damager != null) ? damager.getState() : null, damagee, cause, (damager != null) ? DamageSource.builder(DamageType.GENERIC).withDamageLocation(damager.getLocation()).build() : DamageSource.builder(DamageType.GENERIC).build(), modifiers, modifierFunctions);
|
||||
}
|
||||
|
||||
public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
public EntityDamageByBlockEvent(@Nullable final Block damager, @Nullable final BlockState damagerState, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, @NotNull final Map<DamageModifier, Double> modifiers, @NotNull final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
|
||||
super(damagee, cause, damageSource, modifiers, modifierFunctions);
|
||||
this.damager = damager;
|
||||
this.damagerState = damagerState;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,4 +48,14 @@ public class EntityDamageByBlockEvent extends EntityDamageEvent {
|
|||
public Block getDamager() {
|
||||
return damager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the captured BlockState of the block that damaged the player.
|
||||
*
|
||||
* @return the block state
|
||||
*/
|
||||
@Nullable
|
||||
public BlockState getDamagerBlockState() {
|
||||
return damagerState;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue