Commits
Doc authored and md_5 committed 237bb37bb31
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 | forRemoval = true) | (
19 21 | public EntityDamageByBlockEvent( final Block damager, final Entity damagee, 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( final Block damager, final Entity damagee, final DamageCause cause, final DamageSource damageSource, final double damage) { |
25 + | public EntityDamageByBlockEvent( final Block damager, final BlockState damagerState, final Entity damagee, final DamageCause cause, 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 | forRemoval = true) | (
29 32 | 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) { |
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( final Block damager, final Entity damagee, final DamageCause cause, final DamageSource damageSource, final Map<DamageModifier, Double> modifiers, final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) { |
36 + | public EntityDamageByBlockEvent( final Block damager, final BlockState damagerState, final Entity damagee, final DamageCause cause, final DamageSource damageSource, final Map<DamageModifier, Double> modifiers, 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 | |
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 + | |
58 + | public BlockState getDamagerBlockState() { |
59 + | return damagerState; |
60 + | } |
47 61 | } |