Esempio n. 1
0
  @Override
  public byte[] getBytes(Inventory inv) {
    // Blank NBT tag
    net.minecraft.server.v1_5_R3.NBTTagCompound c =
        new net.minecraft.server.v1_5_R3.NBTTagCompound();
    // Blank NBT list
    net.minecraft.server.v1_5_R3.NBTTagList list = new net.minecraft.server.v1_5_R3.NBTTagList();

    // Iterate over the inventory contents
    for (int index = 0; index < inv.getContents().length; index++) {
      // Convert it to a craftitem stack
      org.bukkit.craftbukkit.v1_5_R3.inventory.CraftItemStack cis =
          (org.bukkit.craftbukkit.v1_5_R3.inventory.CraftItemStack) inv.getItem(index);
      if (cis != null) { // If cis == null, no item is there, ignore it.
        // Convert it to a NMS itemstack
        net.minecraft.server.v1_5_R3.ItemStack is =
            org.bukkit.craftbukkit.v1_5_R3.inventory.CraftItemStack.asNMSCopy(cis);
        // Save the NMS itemstack to a new NBT tag
        net.minecraft.server.v1_5_R3.NBTTagCompound itemCompound =
            new net.minecraft.server.v1_5_R3.NBTTagCompound();
        itemCompound = is.save(itemCompound);

        // Set the position of the item in the chest under "index"
        itemCompound.set("index", new net.minecraft.server.v1_5_R3.NBTTagInt("index", index));
        // Add the item to the NBT list of items
        list.add(itemCompound);
      }
    }
    // Put the list in the blank tag
    c.set("inventory", list);

    // Convert the NBT tag to a byte[]
    byte[] bytes = net.minecraft.server.v1_5_R3.NBTCompressedStreamTools.a(c);
    // Convert & escape the byte[] to a string
    return bytes;
  }