package tokarotik.giftapi.NBT.item; import net.minecraft.server.v1_6_R3.NBTTagList; import net.minecraft.server.v1_6_R3.NBTTagString; import org.bukkit.inventory.ItemStack; import net.minecraft.server.v1_6_R3.NBTTagCompound; import org.bukkit.inventory.meta.ItemMeta; import java.util.Arrays; import java.util.List; public class ItemLoad { public static ItemStack getItem(NBTTagCompound tag) { ItemStack item = new ItemStack( getId(tag), getCount(tag), getDurability(tag) ); // тут чехорда. с начало сет айтем, после сет мета, а в самом конце гет мета item.setItemMeta( setMeta( tag, item.getItemMeta() )); return item; } private static int getId(NBTTagCompound tag) { int id = 0; if (tag.hasKey("id")) { id = tag.getInt("id"); } return id; } private static short getCount(NBTTagCompound tag) { short count = 1; if (tag.hasKey("count")) { count = tag.getShort("count"); } return count; } private static short getDurability(NBTTagCompound tag) { short durability = 0; if (tag.hasKey("damage")) { durability = tag.getShort("damage"); } return durability; } private static ItemMeta setMeta(NBTTagCompound tag, ItemMeta meta) { if (tag.hasKey("meta")) { NBTTagCompound metaNBT = tag.getCompound("meta"); if (metaNBT.hasKey("name")) { meta.setDisplayName(metaNBT.getString("name")); } if (metaNBT.hasKey("lore")) { meta.setLore( NBTListToStringList( metaNBT.getList("lore") ) ); } } return meta; } private static List NBTListToStringList(NBTTagList nbt) { String[] list = new String[nbt.size()]; for (int i = 0; i < nbt.size(); i++) { NBTTagString base = (NBTTagString) nbt.get(i); list[i] = base.data; } return Arrays.asList(list); } }