package team.unstudio.udpl.api.item;

import java.util.ArrayList;
import java.util.Collections;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class ItemBuilder {

	private final ItemStack itemStack;
	
	public ItemBuilder(){
		this(new ItemStack(Material.AIR));
	}
	
	public ItemBuilder(ItemStack itemStack) {
		this.itemStack = itemStack;
	}
	
	public ItemBuilder setType(Material type){
		itemStack.setType(type);
		return this;
	}
	
	public ItemBuilder setDurability(short durability){
		itemStack.setDurability(durability);
		return this;
	}
	
	public ItemBuilder setAmount(int amount){
		itemStack.setAmount(amount);
		return this;
	}
	
	public ItemBuilder setDisplayName(String name){
		ItemMeta meta = itemStack.getItemMeta();
		meta.setDisplayName(name);
		itemStack.setItemMeta(meta);
		return this;
	}
	
	public ItemBuilder addLore(String ...lore){
		ItemMeta meta = itemStack.getItemMeta();
		ArrayList<String> lores = new ArrayList<>(meta.getLore());
		Collections.addAll(lores, lore);
		meta.setLore(lores);
		itemStack.setItemMeta(meta);
		return this;
	}
	
	public ItemBuilder removeLore(int index){
		ItemMeta meta = itemStack.getItemMeta();
		ArrayList<String> lores = new ArrayList<>(meta.getLore());
		lores.remove(index);
		meta.setLore(lores);
		itemStack.setItemMeta(meta);
		return this;
	}
	
	public ItemBuilder addEnchantment(Enchantment ench,int level){
		itemStack.addUnsafeEnchantment(ench, level);
		return this;
	}
	
	public ItemBuilder removeEnchantment(Enchantment ench){
		itemStack.removeEnchantment(ench);
		return this;
	}
	
	public ItemStack getItemStack(){
		return itemStack;
	}
}

@@ -162,16 +162,54 @@
 ntment;%0A
+import org.bukkit.inventory.ItemFlag;%0A
 import o
@@ -239,16 +239,16 @@
 mStack;%0A
-
 import o
@@ -953,32 +953,208 @@
 turn this;%0A%09%7D%0A%09%0A
+%09public ItemBuilder setLocalizedName(String name)%7B%0A%09%09ItemMeta meta = itemStack.getItemMeta();%0A%09%09meta.setLocalizedName(name);%0A%09%09itemStack.setItemMeta(meta);%0A%09%09return this;%0A%09%7D%0A%09%0A
 %09public ItemBuil
@@ -1900,26 +1900,365 @@
 Item
-Stack getItemStack
+Builder addFlag(ItemFlag... flags) %7B%0A%09%09ItemMeta meta = itemStack.getItemMeta();%0A%09%09meta.addItemFlags(flags);%0A%09%09itemStack.setItemMeta(meta);%0A%09%09return this;%0A%09%7D%0A%09%0A%09public ItemBuilder setUnbreakable(boolean value)%7B%0A%09%09ItemMeta meta = itemStack.getItemMeta();%0A%09%09meta.setUnbreakable(value);%0A%09%09itemStack.setItemMeta(meta);%0A%09%09return this;%0A%09%7D%0A%09%0A%09public ItemStack build
 ()%7B%0A
@@ -2271,19 +2271,27 @@
 rn itemStack
+.clone()
 ;%0A%09%7D%0A%7D%0A

Update ItemBuilder