[SPIGOT-3206] Serialisation and de-serialisation of book meta results in different item NBT than original Created: 27/Apr/17 Updated: 12/Apr/20 Resolved: 27/Apr/17 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | Phoenix616 | Assignee: | Unassigned |
Resolution: | Won't Fix | Votes: | 0 |
Labels: | None |
Attachments: |
![]() ![]() |
Description |
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(); } |
Comments |
Comment by Anton [ 12/Apr/20 ] |
Why is it not possible to fix it? Those are really a big problem if we talk about using signed books as part of the gameplay. |
Comment by blablubbabc [ 22/Feb/20 ] |
Wouldn't it be possible to save the pages in their stringified chat component format ("{text: "..", color: "..", ..}") and parse them from that, which should ideally be lossless? The deserialization would also need to be able to parse from the legacy format (for example by using the item's serialized data version to determine whether its using the old or new format). |
Comment by md_5 [ 27/Apr/17 ] |
Unavoidable with the conversion from section signs and backwards |