Search in sources :

Example 66 with NBTTagCompound

use of net.minecraft.server.v1_13_R2.NBTTagCompound in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_8_R3 method deserialize.

private InventoryHolder deserialize(NBTTagCompound tagCompound) {
    InventoryHolder inventory = new InventoryHolder(tagCompound.getInt("Size"), "Chest");
    NBTTagList itemsList = tagCompound.getList("Items", 10);
    for (int i = 0; i < itemsList.size(); i++) {
        NBTTagCompound nbtTagCompound = itemsList.get(i);
        inventory.setItem(nbtTagCompound.getByte("Slot"), CraftItemStack.asBukkitCopy(ItemStack.createStack(nbtTagCompound)));
    }
    return inventory;
}
Also used : NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder)

Example 67 with NBTTagCompound

use of net.minecraft.server.v1_13_R2.NBTTagCompound in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_8_R3 method getChestName.

@Override
public String getChestName(org.bukkit.inventory.ItemStack itemStack) {
    ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound tagCompound = nmsItem.getTag();
    return tagCompound == null || !tagCompound.hasKey("chest-name") ? null : tagCompound.getString("chest-name");
}
Also used : NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)

Example 68 with NBTTagCompound

use of net.minecraft.server.v1_13_R2.NBTTagCompound in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_12_R1 method getChestName.

@Override
public String getChestName(org.bukkit.inventory.ItemStack itemStack) {
    ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound tagCompound = nmsItem.getTag();
    return tagCompound == null || !tagCompound.hasKey("chest-name") ? null : tagCompound.getString("chest-name");
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_12_R1.ItemStack)

Example 69 with NBTTagCompound

use of net.minecraft.server.v1_13_R2.NBTTagCompound in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_12_R1 method deserialzeItem.

@Override
public org.bukkit.inventory.ItemStack deserialzeItem(String serialized) {
    if (serialized.isEmpty())
        return new org.bukkit.inventory.ItemStack(Material.AIR);
    byte[] buff;
    if (serialized.toCharArray()[0] == '*') {
        buff = Base64.getDecoder().decode(serialized.substring(1));
    } else {
        buff = new BigInteger(serialized, 32).toByteArray();
    }
    ByteArrayInputStream inputStream = new ByteArrayInputStream(buff);
    try {
        NBTTagCompound nbtTagCompoundRoot = NBTCompressedStreamTools.a(new DataInputStream(inputStream));
        ItemStack nmsItem = new ItemStack(nbtTagCompoundRoot);
        return CraftItemStack.asBukkitCopy(nmsItem);
    } catch (Exception ex) {
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) BigInteger(java.math.BigInteger) DataInputStream(java.io.DataInputStream) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_12_R1.ItemStack)

Example 70 with NBTTagCompound

use of net.minecraft.server.v1_13_R2.NBTTagCompound in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_12_R1 method deserialze.

@Override
public InventoryHolder[] deserialze(String serialized) {
    byte[] buff;
    if (serialized.toCharArray()[0] == '*') {
        buff = Base64.getDecoder().decode(serialized.substring(1));
    } else {
        buff = new BigInteger(serialized, 32).toByteArray();
    }
    ByteArrayInputStream inputStream = new ByteArrayInputStream(buff);
    InventoryHolder[] inventories = new InventoryHolder[0];
    try {
        NBTTagCompound tagCompound = NBTCompressedStreamTools.a(new DataInputStream(inputStream));
        int length = tagCompound.getInt("Length");
        inventories = new InventoryHolder[length];
        for (int i = 0; i < length; i++) {
            if (tagCompound.hasKey(i + "")) {
                NBTTagCompound nbtTagCompound = tagCompound.getCompound(i + "");
                inventories[i] = deserialize(nbtTagCompound);
            }
        }
    } catch (Exception ignored) {
    }
    return inventories;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) BigInteger(java.math.BigInteger) DataInputStream(java.io.DataInputStream) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder)

Aggregations

NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)70 ItemStack (org.bukkit.inventory.ItemStack)61 Map (java.util.Map)42 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)39 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)38 ArrayList (java.util.ArrayList)37 ItemMeta (org.bukkit.inventory.meta.ItemMeta)35 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)34 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)30 ListTag (com.wasteofplastic.org.jnbt.ListTag)30 StringTag (com.wasteofplastic.org.jnbt.StringTag)30 Tag (com.wasteofplastic.org.jnbt.Tag)30 NBTTagCompound (net.minecraft.server.v1_16_R2.NBTTagCompound)24 Nullable (javax.annotation.Nullable)21 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)21 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)20 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)20 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)20 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)19 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)18