Commits

Parker Hawke authored and md_5 committed 6bfe91ae212
SPIGOT-7617: Add BlockExplodeEvent#getExplodedBlockState()
No tags

src/main/java/org/bukkit/event/block/BlockExplodeEvent.java

Modified
1 1 package org.bukkit.event.block;
2 2
3 3 import java.util.List;
4 4 import org.bukkit.block.Block;
5 +import org.bukkit.block.BlockState;
5 6 import org.bukkit.event.Cancellable;
6 7 import org.bukkit.event.HandlerList;
7 8 import org.jetbrains.annotations.NotNull;
8 9
9 10 /**
10 - * Called when a block explodes
11 + * Called when a block explodes.
12 + * <p>
13 + * Note that due to the nature of explosions, {@link #getBlock()} will always be
14 + * an air block. {@link #getExplodedBlockState()} should be used to get
15 + * information about the block state that exploded.
11 16 */
12 17 public class BlockExplodeEvent extends BlockEvent implements Cancellable {
13 18 private static final HandlerList handlers = new HandlerList();
14 19 private boolean cancel;
20 + private final BlockState blockState;
15 21 private final List<Block> blocks;
16 22 private float yield;
17 23
18 - public BlockExplodeEvent(@NotNull final Block what, @NotNull final List<Block> blocks, final float yield) {
24 + public BlockExplodeEvent(@NotNull final Block what, @NotNull final BlockState blockState, @NotNull final List<Block> blocks, final float yield) {
19 25 super(what);
26 + this.blockState = blockState;
20 27 this.blocks = blocks;
21 28 this.yield = yield;
22 29 this.cancel = false;
23 30 }
24 31
32 + @Deprecated(forRemoval = true)
33 + public BlockExplodeEvent(@NotNull final Block what, @NotNull final List<Block> blocks, final float yield) {
34 + this(what, what.getState(), blocks, yield);
35 + }
36 +
25 37 @Override
26 38 public boolean isCancelled() {
27 39 return cancel;
28 40 }
29 41
30 42 @Override
31 43 public void setCancelled(boolean cancel) {
32 44 this.cancel = cancel;
33 45 }
34 46
47 + /**
48 + * Returns the captured BlockState of the block that exploded.
49 + *
50 + * @return the block state
51 + */
52 + @NotNull
53 + public BlockState getExplodedBlockState() {
54 + return blockState;
55 + }
56 +
35 57 /**
36 58 * Returns the list of blocks that would have been removed or were removed
37 59 * from the explosion event.
38 60 *
39 61 * @return All blown-up blocks
40 62 */
41 63 @NotNull
42 64 public List<Block> blockList() {
43 65 return blocks;
44 66 }

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

Add shortcut