[SPIGOT-581] ItemMeta loses vanilla attributes when serialized Created: 16/Feb/15  Updated: 16/Apr/15  Resolved: 16/Apr/15

Status: Closed
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Cody Sommer Assignee: Thinkofname
Resolution: Fixed Votes: 1
Labels: None


 Description   

After serializing (to yaml file) and deserializing an ItemStack, any attributes (such as MaxHealth) are lost.



 Comments   
Comment by Cody Sommer [ 16/Apr/15 ]

hmm, I wish the known attributes were separated similar to the other meta so that they could be editable from the file. But I'll look at it as a feature, when users are allowed to edit the files themselves, they usually mess it up.

And yes it is very exciting stuff, more than I hoped for!

Comment by Nathan Wolf [ 16/Apr/15 ]

Sure thing, I couldn't wait to try it! If you haven't looked at the commit, know that the unhandled data goes in a base64-encoded blob. Here's an example:

http://pastebin.com/Y3dpg4ku

Very exciting

Comment by Cody Sommer [ 16/Apr/15 ]

Thank you so much Thinkofdeath for fixing this, I have been wanting it for a couple of years now. And thanks Nathan for testing that out. I was wondering the same and was just about to write something to test it.

Comment by Nathan Wolf [ 16/Apr/15 ]

Thank you for this! It's definitely worth noting that the change that fixed this has also allowed for general serialization of unhandled data.

Tested with a plugin that uses custom NBT tags, and a plugin that serializes items (Shopkeepers), and it worked great.

Comment by Nathan Wolf [ 17/Feb/15 ]

Oops! Sorry for the misinformation!

Thanks for clearing that up, @blahblubbabc, I didn't realize shopkeepers did that.

Comment by blablubbabc [ 17/Feb/15 ]

Note regarding the shopkeepers example above: Shopkeepers is saving and applying the attributes manually. It's not using bukkit's item serialization for that.

Comment by Cody Sommer [ 17/Feb/15 ]

Ok, I haven't tested the vanilla activity in a while. Thanks for all the help/info. I'll try to get my solution to an Attribute API out there and hopefully it will turn into something. I have seen a couple feature requests/bug that it would cover.

Comment by Nathan Wolf [ 17/Feb/15 ]

All the info is here:

http://www.spigotmc.org/threads/bukkit-craftbukkit-spigot-1-8.36598/

I'm sure people would love an attribute API!

Though the situation is not all that bad- items should no longer lose their attributes through any sort of vanilla activity, including creative mode. It's just Bukkit serialization that's lacking, and of course missing the actual API part

Comment by Cody Sommer [ 17/Feb/15 ]

Is there documentation on how to request developer access. I have a whole attribute API that might be worth submitting a PR for. It also fixes attributes being lost in chests or while in creative mode. I'm not sure if anyone is working on that or not.

Comment by Nathan Wolf [ 17/Feb/15 ]

If you have submitted the CLA and have developer access, you can see it in Stash, in the CraftBukkit repo.

Otherwise, no, I don't think there is a way to see it.

Comment by Cody Sommer [ 17/Feb/15 ]

Is there a way to view that PR? I have my own code that I used to support attributes back when CraftBukkit was open source. It might be of some use.

Comment by Nathan Wolf [ 17/Feb/15 ]

Oops.. er, sorry, I forgot I was running my patched build.

Well, in that case, this would be addressed by CraftBukkit PR#85, which serializes custom or unknown data.

This also points out a major flaw in that PR, in that it is not forward-compatible. The proper way to fix this issue would be a real attribute API that supports serialization. The attributes written out as custom data by my patch may or may not be compatible with how the API could choose to right them.

Still, it's very handy to have any and all data work properly with serialization, and that is the main purpose of my PR.

Comment by Nathan Wolf [ 16/Feb/15 ]

I tested this myself using the Shopkeepers plugin, and an item with attributes created using the MythicMobs plugin, and it all seemed to work properly.

Here's the YAML:

item:
          ==: org.bukkit.inventory.ItemStack
          type: DIAMOND_SWORD
          meta:
            ==: ItemMeta
            meta-type: UNSPECIFIC
            display-name: §3Greatsword of the Wraith King
            lore:
            - §6A powerful sword used by
            - §6Wraiths.
            enchants:
              FIRE_ASPECT: 2
              DAMAGE_ALL: 5
              KNOCKBACK: 2
        attributes: MAX_HEALTH,generic.maxHealth,10.0,0,-6754773682018222698,-1121591786282269812;MOVEMENT_SPEED,generic.movementSpeed,0.1,2,-7160506724891231490,-466166689701607073;

After shutting down and starting back up again, I could purchase the item with its attributes in tact.

Generated at Sat Dec 13 13:38:04 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.