Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.event.block;
2
3import org.bukkit.block.Block;
4import org.bukkit.block.BlockState;
5import org.bukkit.entity.Player;
6import org.bukkit.event.Cancellable;
7import org.bukkit.inventory.ItemStack;
8
9/**
10 * Called when a block is placed by a player.
11 * <p/>
12 * If a Block Place event is cancelled, the block will not be placed.
13 */
14public class BlockPlaceEvent extends BlockEvent implements Cancellable {
15 protected boolean cancel;
16 protected boolean canBuild;
17 protected Block placedAgainst;
18 protected BlockState replacedBlockState;
19 protected ItemStack itemInHand;
20 protected Player player;
21
22 public BlockPlaceEvent(Block placedBlock, BlockState replacedBlockState, Block placedAgainst, ItemStack itemInHand, Player thePlayer, boolean canBuild) {
23 super(Type.BLOCK_PLACE, placedBlock);
24 this.placedAgainst = placedAgainst;
25 this.itemInHand = itemInHand;
26 this.player = thePlayer;
27 this.replacedBlockState = replacedBlockState;
28 this.canBuild = canBuild;
29 cancel = false;
30 }
31
32 public boolean isCancelled() {
33 return cancel;
34 }
35
36 public void setCancelled(boolean cancel) {
37 this.cancel = cancel;
38 }
39
40 /**
41 * Gets the player who placed the block involved in this event.
42 *
43 * @return The Player who placed the block involved in this event
44 */
45 public Player getPlayer() {
46 return player;
47 }
48
49 /**
50 * Clarity method for getting the placed block. Not really needed
51 * except for reasons of clarity.
52 *
53 * @return The Block that was placed
54 */
55 public Block getBlockPlaced() {
56 return getBlock();
57 }
58
59 /**
60 * Gets the BlockState for the block which was replaced. Material type air mostly.
61 *
62 * @return The BlockState for the block which was replaced.
63 */
64 public BlockState getBlockReplacedState() {
65 return this.replacedBlockState;
66 }
67
68 /**
69 * Gets the block that this block was placed against
70 *
71 * @return Block the block that the new block was placed against
72 */
73 public Block getBlockAgainst() {
74 return placedAgainst;
75 }
76
77 /**
78 * Gets the item in the player's hand when they placed the block.
79 *
80 * @return The ItemStack for the item in the player's hand when they placed the block
81 */
82 public ItemStack getItemInHand() {
83 return itemInHand;
84 }
85
86 /**
87 * Gets the value whether the player would be allowed to build here.
88 * Defaults to spawn if the server was going to stop them (such as, the
89 * player is in Spawn). Note that this is an entirely different check
90 * than BLOCK_CANBUILD, as this refers to a player, not universe-physics
91 * rule like cactus on dirt.
92 *
93 * @return boolean whether the server would allow a player to build here
94 */
95 public boolean canBuild() {
96 return this.canBuild;
97 }
98
99 /**
100 * Sets the canBuild state of this event. Set to true if you want the
101 * player to be able to build.
102 *
103 * @param canBuild true if you want the player to be able to build
104 */
105 public void setBuild(boolean canBuild) {
106 this.canBuild = canBuild;
107 }
108}