summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit/ItemStack.java
blob: b2a4c6f4bb7d26d7a92d8cd5a80b161f3005e072 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

package org.bukkit;

/**
 * Represents a stack of items
 */
public class ItemStack {
    private int type;
    private int amount = 0;
    private byte damage = 0;

    public ItemStack(final int type) {
        this.type = type;
    }

    public ItemStack(final Material type) {
        this(type.getID());
    }

    public ItemStack(final int type, final int amount) {
        this.type = type;
        this.amount = amount;
    }

    public ItemStack(final Material type, final int amount) {
        this(type.getID(), amount);
    }

    public ItemStack(final int type, final int amount, final byte damage) {
        this.type = type;
        this.amount = amount;
        this.damage = damage;
    }

    public ItemStack(final Material type, final int amount, final byte damage) {
        this(type.getID(), amount, damage);
    }

    /**
     * Gets the type of this item
     *
     * @return Type of the items in this stack
     */
    public Material getType() {
        return Material.getMaterial(type);
    }

    /**
     * Sets the type of this item
     *
     * @param type New type to set the items in this stack to
     */
    public void setType(Material type) {
        setTypeID(type.getID());
    }

    /**
     * Gets the type ID of this item
     *
     * @return Type ID of the items in this stack
     */
    public int getTypeID() {
        return type;
    }

    /**
     * Sets the type ID of this item
     *
     * @param type New type ID to set the items in this stack to
     */
    public void setTypeID(int type) {
        this.type = type;
    }

    /**
     * Gets the amount of items in this stack
     *
     * @return Amount of items in this stick
     */
    public int getAmount() {
        return amount;
    }

    /**
     * Sets the amount of items in this stack
     *
     * @param amount New amount of items in this stack
     */
    public void setAmount(int amount) {
        this.amount = amount;
    }

    /**
     * Sets the damage of this item<br /><br />
     *
     * 0x00 represents an item which cannot be damaged<br />
     * 0x01 represents an item at maximum health<br />
     * 0x32 represents an item with no health left
     *
     * @param damage Damage of this item
     */
    public void setDamage(final byte damage) {
        this.damage = damage;
    }

    /**
     * Gets the damage of this item<br /><br />
     *
     * 0x00 represents an item which cannot be damaged<br />
     * 0x01 represents an item at maximum health<br />
     * 0x32 represents an item with no health left
     *
     * @return Damage of this item
     */
    public byte getDamage() {
        return damage;
    }

    /**
     * Get the maximum stacksize for the material hold in this ItemStack
     * Returns -1 if it has no idea.
     * 
     * @return The maximum you can stack this material to.
     */
    public int getMaxStackSize() {
        return -1;
    }

    @Override
    public String toString() {
        return "ItemStack{"+getType().name()+" x "+getAmount()+"}";
    }

    @Override
    public boolean equals(Object object) {
        return false;
    }

    public boolean equals(ItemStack item) {
        return item.getAmount() == getAmount() && item.getTypeID() == getTypeID();
    }
}