Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-3206

Serialisation and de-serialisation of book meta results in different item NBT than original

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • None
    • None
    • None

      When de-serialising a serialised written (signed) book meta it will result in a different meta than it originally was. When applied to an item stack it will create two different items. (E.g. when saving into and getting from a config)

      The difference between the two items will be in the pages section of the NBT data. The item that went through the serialisation process will have the book text in an extra tag and not in the text tag like the Vanilla one. (See NBTExplorer screenshot)

      This does not happen with unsigned books.

      I included a plugin with which one can test this, just get and sign a book with text and run the command /metatest while holding the book.

       

      Here is the code I use in the plugin for completion sake, it has to use a CraftClass as ConfigurationSerializable does not define a deserialize method in Bukkit:

      Map<String, Object> serialized = item.getItemMeta().serialize();
      try {
          ItemMeta deserialised = CraftMetaBook.SerializableMeta.deserialize(serialized);
          ItemStack clone = new ItemStack(item);
          clone.setItemMeta(deserialised);
          if (item.isSimilar(clone)) {
              sender.sendMessage("Item is the same after serialisation and deserialisation!");
          } else {
              sender.sendMessage("Item is NOT the same after serialisation and deserialisation! Giving you the item...");
              ((Player) sender).getInventory().addItem(clone);
          }
      } catch (Throwable throwable) {
          sender.sendMessage("Error while deserialising: " + throwable.getMessage());
          throwable.printStackTrace();
      }
      

            Unassigned Unassigned
            Phoenix616 Phoenix616
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: