public class ItemBuilder {
private final ItemStack itemStack;
private ItemMeta itemMeta;
public ItemStack getItemStack() {
return this.itemStack;
}
public ItemMeta getItemMeta() {
return this.itemMeta;
}
public ItemBuilder(ItemStack itemStack) {
this.itemStack = itemStack;
this.itemMeta = this.itemStack.getItemMeta();
}
public ItemBuilder(Material material) {
this.itemStack = new ItemStack(material);
this.itemMeta = this.itemStack.getItemMeta();
}
public ItemBuilder(Material material, int amount) {
this.itemStack = new ItemStack(material, 1, (short) 0);
this.itemMeta = this.itemStack.getItemMeta();
setAmount(Integer.valueOf(amount));
}
public ItemBuilder(Material material, short itemData) {
this.itemStack = new ItemStack(material, 1, itemData);
this.itemMeta = this.itemStack.getItemMeta();
}
public ItemBuilder(Material material, int amount, short itemData) {
this.itemStack = new ItemStack(material, 1, itemData);
this.itemMeta = this.itemStack.getItemMeta();
}
public ItemBuilder setDisplayName(String displayName) {
this.itemMeta.setDisplayName(displayName);
return this;
}
public ItemBuilder setAmount(Integer amount) {
this.itemStack.setAmount(amount.intValue());
return this;
}
public ItemBuilder setLore(String... lore) {
this.itemMeta.setLore(Arrays.asList(lore));
return this;
}
public ItemBuilder setLore(List<String> lore) {
this.itemMeta.setLore(lore);
return this;
}
public ItemBuilder setEnchantment(Enchantment enchantment, Integer level) {
this.itemMeta.addEnchant(enchantment, level.intValue(), true);
return this;
}
public ItemBuilder addEnchantments(Map<Enchantment, Integer> enchantments) {
this.itemStack.addUnsafeEnchantments(enchantments);
return this;
}
public ItemBuilder setItemFlag(ItemFlag itemFlag) {
this.itemMeta.addItemFlags(new ItemFlag[] { itemFlag });
return this;
}
public ItemBuilder setDurability(Short amount) {
this.itemStack.setDurability(amount);
return this;
}
public ItemBuilder setColor(Color color) {
LeatherArmorMeta meta = (LeatherArmorMeta) this.itemMeta;
meta.setColor(color);
return this;
}
public ItemStack build() {
this.itemStack.setItemMeta(this.itemMeta);
return this.itemStack;
}
}