summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit/event/player/PlayerItemEvent.java
blob: 842a0eb0e50f87b9fb801c8624a16e7088096f46 (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
package org.bukkit.event.player;

import org.bukkit.ItemStack;
import org.bukkit.Material;
import org.bukkit.Player;
import org.bukkit.event.Cancellable;

/**
 * 
 * @author durron597
 *
 */
public class PlayerItemEvent extends PlayerEvent implements Cancellable {
    protected ItemStack item;
    protected boolean cancel;
    
    public PlayerItemEvent(Type type, Player who, ItemStack item) {
        super(type, who);
        this.item = item;
        cancel = false;
    }

    /**
     * Gets the cancellation state of this event. Set to true if you
     * want to prevent buckets from placing water and so forth
     * 
     * @return boolean cancellation state
     */
    public boolean isCancelled() {
        return cancel;
    }

    /**
     * Sets the cancellation state of this event. A cancelled event will not
     * be executed in the server, but will still pass to other plugins
     *
     * Cancelling this event will prevent use of food (player won't lose the
     * food item), prevent bows/snowballs/eggs from firing, etc. (player won't
     * lose the ammo)
     *
     * @param cancel true if you wish to cancel this event
     */
    public void setCancelled(boolean cancel) {
        this.cancel = cancel;
    }
    
    /**
     * Returns the item in hand represented by this event
     * 
     * @return ItemStack the item used
     */
    public ItemStack getItem() {
        return this.item;
    }
    
    /**
     * Convenience method. Returns the material of the item represented by this
     * event
     * 
     * @return Material the material of the item used
     */
    public Material getMaterial() {
        if (this.item == null) return Material.Air;
        
        return item.getType();
    }
}