Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.event.block;
2
3import org.bukkit.Material;
4import org.bukkit.block.Block;
5
6/**
7 * Called when we try to place a block, to see if we can build it here or not.
8 * <p/>
9 * Note:
10 * <ul>
11 * <li>The Block returned by getBlock() is the block we are trying to place on, not the block we are trying to place.</li>
12 * <li>If you want to figure out what is being placed, use {@link #getMaterial()} or {@link #getMaterialId()} instead.</li>
13 * </ul>
14 */
15public class BlockCanBuildEvent extends BlockEvent {
16 protected boolean buildable;
17 protected int material;
18
19 public BlockCanBuildEvent(Block block, int id, boolean canBuild) {
20 super(Type.BLOCK_CANBUILD, block);
21 buildable = canBuild;
22 material = id;
23 }
24
25 /**
26 * Gets whether or not the block can be built here.
27 * By default, returns Minecraft's answer on whether the block can be built here or not.
28 *
29 * @return boolean whether or not the block can be built
30 */
31 public boolean isBuildable() {
32 return buildable;
33 }
34
35 /**
36 * Sets whether the block can be built here or not.
37 *
38 * @param cancel true if you want to allow the block to be built here despite Minecraft's default behaviour
39 */
40 public void setBuildable(boolean cancel) {
41 this.buildable = cancel;
42 }
43
44 /**
45 * Gets the Material that we are trying to place.
46 *
47 * @return The Material that we are trying to place
48 */
49 public Material getMaterial() {
50 return Material.getMaterial(material);
51 }
52
53 /**
54 * Gets the Material ID for the Material that we are trying to place.
55 *
56 * @return The Material ID for the Material that we are trying to place
57 */
58 public int getMaterialId() {
59 return material;
60 }
61}