001/* This file is part of Vault.
002
003    Vault is free software: you can redistribute it and/or modify
004    it under the terms of the GNU Lesser General Public License as published by
005    the Free Software Foundation, either version 3 of the License, or
006    (at your option) any later version.
007
008    Vault is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU Lesser General Public License for more details.
012
013    You should have received a copy of the GNU Lesser General Public License
014    along with Vault.  If not, see <http://www.gnu.org/licenses/>.
015 */
016package net.milkbowl.vault.item;
017
018import org.bukkit.Material;
019import org.bukkit.inventory.ItemStack;
020
021public class ItemInfo {
022
023    public final Material material;
024    public final short subTypeId;
025    public final String name;
026    public final String[][] search;
027    
028    public ItemInfo(String name, String[][] search, Material material) {
029        this.material = material;
030        this.name = name;
031        this.subTypeId = 0;
032        this.search = search.clone();
033    }
034
035    public ItemInfo(String name, String[][] search, Material material, short subTypeId) {
036        this.name = name;
037        this.material = material;
038        this.subTypeId = subTypeId;
039        this.search = search.clone();
040    }
041
042    public Material getType() {
043        return material;
044    }
045
046    public short getSubTypeId() {
047        return subTypeId;
048    }
049
050    public int getStackSize() {
051        return material.getMaxStackSize();
052    }
053
054    @Deprecated
055    public int getId() {
056        return material.getId();
057    }
058
059    public boolean isEdible() {
060        return material.isEdible();
061    }
062    
063    public boolean isBlock() {
064        return material.isBlock();
065    }
066    
067    public String getName() {
068        return name;
069    }
070
071    @Override
072    public int hashCode() {
073        int hash = 7;
074        hash = 17 * hash + this.getId();
075        hash = 17 * hash + this.subTypeId;
076        return hash;
077    }
078
079    public boolean isDurable() {
080        return (material.getMaxDurability() > 0);
081    }
082
083    public ItemStack toStack() {
084        return new ItemStack(this.material, 1, subTypeId);
085    }
086
087    @SuppressWarnings("deprecation")
088    @Override
089    public String toString() {
090        return String.format("%s[%d:%d]", name, material.getId(), subTypeId);
091    }
092    
093    @Override
094    public boolean equals(Object obj) {
095        if (obj == null) {
096            return false;
097        } else if (this == obj) {
098            return true;
099        } else if (!(obj instanceof ItemInfo)) {
100            return false;
101        } else {
102            return ((ItemInfo) obj).material == this.material && ((ItemInfo) obj).subTypeId == this.subTypeId;
103        }
104    }
105}