I have a plugin that currently stores some data about players. Currently, the data is stored via a JSON file keyed by UUID, but I’ve left myself some room to implement different data stores such as a database.
I’m not sure if I’m reading the Data API right, but it appears you can extend it to attach your own, custom data to the player to be stored in side the dat files along side the world. This seems a pretty desirable situation. My questions are:
Is this even possible right now?
Are there any good code examples of how to go about doing this?
Am I correct in assuming Sponge would store this data in {world}/playerdata/{UUID}.dat?
Would this break the player data for non-Sponge servers, so if a user migrated away from Sponge they’d lose all player data?
Any other issues or warnings if going about things this way?
Yes, it’s fully implemented currently, though it’s possible the location of data will change sooner or later (basically, custom data might be serialized in a separate file location than the world data so not all data is lost).
There’s a few examples: here, docs, and various other places.
Currently, it’s stored with the player’s data, yes.
Yes, see first reply.[quote=“krinderlin, post:1, topic:11251”]
Any other issues or warnings if going about things this way?
[/quote]
Make sure everything is registered properly and if you need additional help, provide code snippets and hop on IRC
Thanks for the quick response. That example is perfect.
Looks like I’ll hold off on that until custom data isn’t so dangerous to the world save. I don’t think my use case really justifies the restrictions writing custom player data imposes (unlike, say, something along the lines of FTB of MystCraft).
At the very least, I’ll refactor my interface to accept a Player object for the future as opposed to the UUID.
It’s not so much dangerous to the world save, just makes it so that sponge custom data is retained after swapping to forge or vanilla and back to sponge.
I should clarify, it’s not dangerous as it only is saved to player files currently, if Sponge fails to load and the server is loaded without sponge and a player file is re-saved in that time, the custom data is lost. There have been experiments already where sponge specific data is already saved in a different place, if you notice in {world name}/data/sponge/, you’ll find all the same player data files but only storing specific information that sponge knows about (specifically the join dates and such.).
One final question: If I extend the Data API to hold some custom keys on a player, will sponge store those in /data/sponge or do I need to somehow specify that?