// get the string with the information
String sItemStackName = storage.getString (args[0]);
String sMaterial = storage.getString (args[2]);
String sEnchantments = storage.getString (args[3]);
String sNBTItemStack = storage.getString (args[4]);
Storage storNBT = storage.getStorage(args[5]);
// the version where the information is in the ItemStackName?
if (sItemStackName != null) {
String splitted[] = sItemStackName.split(splitItemParams);
int id = Integer.parseInt(splitted[0]);
// has durability?
if (splitted.length > 1) {
itemStack = new ItemStack(id, Properties.DEFAULT_STACK_AMOUNT, Short.parseShort(splitted[1]));
} else {
itemStack = new ItemStack(id, Properties.DEFAULT_STACK_AMOUNT);
}
// the version when the information was in the Material?
} else if (sMaterial != null) {
String splitted[] = sMaterial.split(splitItemParams);
Material material = Material.getMaterial(splitted[0].toUpperCase());
// has durability?
if (splitted.length > 1) {
itemStack = new ItemStack(material, Properties.DEFAULT_STACK_AMOUNT, Short.parseShort(splitted[1]));
} else {
itemStack = new ItemStack(material, Properties.DEFAULT_STACK_AMOUNT);
}
}
// couldn't load the ItemStack?
if (itemStack == null) {
throw new NullPointerException("ItemStack is null");
}
// any additional information in the NBT String?
if (sNBTItemStack != null) {
byte[] bytes = new HexBinaryAdapter().unmarshal(sNBTItemStack);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
DataInputStream dis = new DataInputStream(bais);
// MC 1.4.6
if (version.contains("1.4.6")) {
net.minecraft.server.v1_4_R1.NBTBase tag = net.minecraft.server.v1_4_R1.NBTBase.b(dis);
net.minecraft.server.v1_4_R1.ItemStack stack = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asNMSCopy(itemStack);
stack.setTag((net.minecraft.server.v1_4_R1.NBTTagCompound)tag);
itemStack = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asBukkitCopy(stack);
ShowCaseStandalone.slog(Level.INFO, "Loaded NBT from DIS - MC 1.4.6");
// MC 1.4.5
} else if (version.contains("1.4.5")) {
net.minecraft.server.v1_4_5.NBTBase tag = net.minecraft.server.v1_4_5.NBTBase.b(dis);
net.minecraft.server.v1_4_5.ItemStack stack = org.bukkit.craftbukkit.v1_4_5.inventory.CraftItemStack.asNMSCopy(itemStack);
stack.setTag((net.minecraft.server.v1_4_5.NBTTagCompound)tag);
itemStack = org.bukkit.craftbukkit.v1_4_5.inventory.CraftItemStack.asBukkitCopy(stack);
ShowCaseStandalone.slog(Level.INFO, "Loaded NBT from DIS - MC 1.4.5");
}
}
// any additional information in the NBTStorage?
if (storNBT != null) {
// MC 1.4.5
if (version.contains("1.4.5")) {
net.minecraft.server.v1_4_R1.ItemStack stack = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asNMSCopy(itemStack);
stack.setTag(new com.kellerkindt.scs.internals.NBTStorage(storNBT).getNBTTagCompound());
itemStack = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asBukkitCopy(stack);
ShowCaseStandalone.slog(Level.INFO, "Loaded NBT from NBTStorage - MC 1.4.5");
// MC 1.4.6
} else if (version.contains("1.4.6")) {
String tagStringAuthor = "author";
String tagStringTitle = "title";
String tagStringPages = "pages";
String tagStringPagePref = "page-";
String tagIntegerPagesSize = "pages";
String author = storNBT.getString (tagStringAuthor);
String title = storNBT.getString (tagStringTitle);
Integer pSize = storNBT.getInteger(tagIntegerPagesSize);
net.minecraft.server.v1_4_R1.NBTTagCompound compound = new net.minecraft.server.v1_4_R1.NBTTagCompound();
if (pSize != null) {
net.minecraft.server.v1_4_R1.NBTTagList list = new net.minecraft.server.v1_4_R1.NBTTagList();
for (int i = 0; i < pSize; i++) {
String page = storNBT.getString(tagStringPagePref+i);
if (page != null) {
net.minecraft.server.v1_4_R1.NBTTagString tag = new net.minecraft.server.v1_4_R1.NBTTagString(page);
tag.data = page;
list.add(tag);
}
}
compound.set(tagStringPages, list);
}
if (title != null)
compound.setString(tagStringTitle, title);
if (author != null)
compound.setString(tagStringAuthor, author);
net.minecraft.server.v1_4_R1.ItemStack stack = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asNMSCopy(itemStack);
stack.setTag(compound);
itemStack = org.bukkit.craftbukkit.v1_4_R1.inventory.CraftItemStack.asBukkitCopy(stack);
ShowCaseStandalone.slog(Level.INFO, "Loaded NBT from NBTStorage - MC 1.4.6");
}
}
// enchantments available?
Map<Enchantment, Integer> enchantments = null;
if (sEnchantments != null) {
enchantments = new HashMap<Enchantment, Integer>();
String ench[] = sEnchantments.split(",");
for (String string : ench) {
Enchantment enchantment = Utilities.getEnchantmentFromString (string);
int level = Utilities.getEnchantmentLevelFromString (string);
if (enchantment != null) {
enchantments.put(enchantment, level);
}
}
}
// add the enchantments if there are set some
if (enchantments != null) {
for (Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
if (Properties.allowUnsafeEnchantments) {
itemStack.addUnsafeEnchantment(entry.getKey(), entry.getValue());
} else {
itemStack.addEnchantment(entry.getKey(), entry.getValue());
}
}
}
}
// storage version 4
else if (interpretationVersion == 4) {
// load binary array
String hexString = storage.getString(args[0]);
byte[] array = new HexBinaryAdapter().unmarshal(hexString);
// init streams
ByteArrayInputStream bais = new ByteArrayInputStream(array);
ObjectInputStream ois = new ObjectInputStream(bais);
// get the map and the ItemStack
@SuppressWarnings("unchecked")
HashMap<String, Object> map = (HashMap<String, Object>)ois.readObject();
itemStack = ItemStack.deserialize(map);
}
// storage version 5
else if (interpretationVersion == 5) {
// load it from the hex String
itemStack = Utilities.toItemStack(storage.getString(args[0]), Properties.DEFAULT_STACK_AMOUNT);
Validate.notNull(itemStack);
if (storage.getStorage(args[1]) != null) {
itemStack.setItemMeta( Utilities.toItemMeta(storage.getString(args[1])) );
}
}
// storage version 6
else if (interpretationVersion >= 6) {
Storage itemStorage = storage.getStorage(args[6]);
if (itemStorage != null) {
itemStack = new ItemStorage(itemStorage).getItemStack();
Validate.notNull(itemStack);