summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit/event/block/BlockCanBuildEvent.java
blob: 5efc16d4d19d92913f4fe5ab51194eca9998294c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package org.bukkit.event.block;

import org.bukkit.block.Block;
import org.bukkit.Material;
import org.bukkit.event.HandlerList;

/**
 * Called when we try to place a block, to see if we can build it here or not.
 * <p />
 * Note:
 * <ul>
 * <li>The Block returned by getBlock() is the block we are trying to place on, not the block we are trying to place.</li>
 * <li>If you want to figure out what is being placed, use {@link #getMaterial()} or {@link #getMaterialId()} instead.</li>
 * </ul>
 */
@SuppressWarnings("serial")
public class BlockCanBuildEvent extends BlockEvent {
    private static final HandlerList handlers = new HandlerList();
    protected boolean buildable;
    protected int material;

    public BlockCanBuildEvent(Block block, int id, boolean canBuild) {
        super(Type.BLOCK_CANBUILD, block);
        buildable = canBuild;
        material = id;
    }

    /**
     * Gets whether or not the block can be built here.
     * By default, returns Minecraft's answer on whether the block can be built here or not.
     *
     * @return boolean whether or not the block can be built
     */
    public boolean isBuildable() {
        return buildable;
    }

    /**
     * Sets whether the block can be built here or not.
     *
     * @param cancel true if you want to allow the block to be built here despite Minecraft's default behaviour
     */
    public void setBuildable(boolean cancel) {
        this.buildable = cancel;
    }

    /**
     * Gets the Material that we are trying to place.
     *
     * @return The Material that we are trying to place
     */
    public Material getMaterial() {
        return Material.getMaterial(material);
    }

    /**
     * Gets the Material ID for the Material that we are trying to place.
     *
     * @return The Material ID for the Material that we are trying to place
     */
    public int getMaterialId() {
        return material;
    }

    @Override
    public HandlerList getHandlers() {
        return handlers;
    }

    public static HandlerList getHandlerList() {
        return handlers;
    }
}