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