Commits

Nate Mortensen authored f94692bbe3d
Add BlockMultiPlaceEvent. Adds BUKKIT-5558

Some blocks, such as beds, doors, or flowers, are actually composed of multiple blocks when they are placed. Currently, to detect how many blocks are actually modified a plugin has to perform various calculations to determine the directions of relative blocks, many of which are difficult to perform and can easily return false positives. This commit adds in a BlockMultiPlaceEvent, which adds in easy support for accessing all blocks modified by the placement of a block.
No tags

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

Added
1 +package org.bukkit.event.block;
2 +
3 +import com.google.common.collect.ImmutableList;
4 +import org.bukkit.block.Block;
5 +import org.bukkit.block.BlockState;
6 +import org.bukkit.entity.Player;
7 +import org.bukkit.inventory.ItemStack;
8 +
9 +import java.util.List;
10 +
11 +/**
12 + * Fired when a single block placement action of a player triggers the
13 + * creation of multiple blocks(e.g. placing a bed block). The block returned
14 + * by {@link #getBlockPlaced()} and its related methods is the block where
15 + * the placed block would exist if the placement only affected a single
16 + * block.
17 + */
18 +public class BlockMultiPlaceEvent extends BlockPlaceEvent {
19 + private final List<BlockState> states;
20 +
21 + public BlockMultiPlaceEvent(List<BlockState> states, Block clicked, ItemStack itemInHand, Player thePlayer, boolean canBuild) {
22 + super(states.get(0).getBlock(), states.get(0), clicked, itemInHand, thePlayer, canBuild);
23 + this.states = ImmutableList.copyOf(states);
24 + }
25 +
26 + /**
27 + * Gets a list of blockstates for all blocks which were replaced by the
28 + * placement of the new blocks. Most of these blocks will just have a
29 + * Material type of AIR.
30 + *
31 + * @return immutable list of replaced BlockStates
32 + */
33 + public List<BlockState> getReplacedBlockStates() {
34 + return states;
35 + }
36 +}

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

Add shortcut