Commits

Doc authored and md_5 committed 237bb37bb31
SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent
No tags

src/main/java/org/bukkit/event/entity/EntityDamageByBlockEvent.java

Modified
1 1 package org.bukkit.event.entity;
2 2
3 3 import com.google.common.base.Function;
4 4 import java.util.Map;
5 5 import org.bukkit.block.Block;
6 +import org.bukkit.block.BlockState;
6 7 import org.bukkit.damage.DamageSource;
7 8 import org.bukkit.damage.DamageType;
8 9 import org.bukkit.entity.Entity;
9 10 import org.jetbrains.annotations.NotNull;
10 11 import org.jetbrains.annotations.Nullable;
11 12
12 13 /**
13 14 * Called when an entity is damaged by a block
14 15 */
15 16 public class EntityDamageByBlockEvent extends EntityDamageEvent {
16 17 private final Block damager;
18 + private final BlockState damagerState;
17 19
18 20 @Deprecated(forRemoval = true)
19 21 public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, final double damage) {
20 - this(damager, damagee, cause, (damager != null) ? DamageSource.builder(DamageType.GENERIC).withDamageLocation(damager.getLocation()).build() : DamageSource.builder(DamageType.GENERIC).build(), damage);
22 + 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);
21 23 }
22 24
23 - public EntityDamageByBlockEvent(@Nullable final Block damager, @NotNull final Entity damagee, @NotNull final DamageCause cause, @NotNull final DamageSource damageSource, final double damage) {
25 + 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) {
24 26 super(damagee, cause, damageSource, damage);
25 27 this.damager = damager;
28 + this.damagerState = damagerState;
26 29 }
27 30
28 31 @Deprecated(forRemoval = true)
29 32 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) {
30 - this(damager, damagee, cause, (damager != null) ? DamageSource.builder(DamageType.GENERIC).withDamageLocation(damager.getLocation()).build() : DamageSource.builder(DamageType.GENERIC).build(), modifiers, modifierFunctions);
33 + 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);
31 34 }
32 35
33 - 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) {
36 + 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) {
34 37 super(damagee, cause, damageSource, modifiers, modifierFunctions);
35 38 this.damager = damager;
39 + this.damagerState = damagerState;
36 40 }
37 41
38 42 /**
39 43 * Returns the block that damaged the player.
40 44 *
41 45 * @return Block that damaged the player
42 46 */
43 47 @Nullable
44 48 public Block getDamager() {
45 49 return damager;
46 50 }
51 +
52 + /**
53 + * Returns the captured BlockState of the block that damaged the player.
54 + *
55 + * @return the block state
56 + */
57 + @Nullable
58 + public BlockState getDamagerBlockState() {
59 + return damagerState;
60 + }
47 61 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut