Assign custom data to player?

I’m looking for a way to assign a string to a player to retrieve later in the chat portion of the plugin, I was looking at the Unified Data API but I didn’t see any way to create a custom DataContainer(I think that’s what I need?), is it possible to do that in sponge’s current state? If not, will it be possible in the future?

Why not just store the information in a map?

Map<UUID, String> chatMap = new HashMap<UUID, String>();

As far as your question goes, @gabizou could probably give a better answer than I.

I was told Custom Data isnt implemented yet, so I’d assume not.

When implementation supports it, it will be possible to store plugin transient data on to DataHolders. What you’ll likely need to do is create your own DataManipulator, of which be used to store your custom data as you please.

1 Like

can I poke at you on irc later to pitch implementation ideas? sorta wanna try helping since this feature is something my plugin’s also dependent on

If I’ve got this correctly, you’d want to use the data API if you have data that you want to share with other plugins easily (much like Bukkit’s metadata API), and if you have no need to share it then just store it, yes?

not necessarily.

the data api stores everything pertaining to an object; if you look at the code there’s health data for living entities, block data for things like banners or wool, etc.

I get that, but the idea is to make it easily accessible through Sponge rather than an external API your plugin exposes. So if my plugin needs to know if a player is “ready” I can just have a Map<Player, Boolean>, but if my plugin and possibly other plugins might want to know, then I should go with the data API, right?

Stop me if I’m wrong or off track please.

you can use whatever form of storage you want; the data API is there just to help find a better place to store it. i think it also helps when data needs to persist over restarts, which means data in dataapi might get saved if told to. with the data api, the data is stored directly onto the owning instance, so you can grab it from there instead of some arbitrary manager you’ve conjured.

though, in that use case, its better to have your plugin throw an event whenever the ready state is toggled.

1 Like

What about persistent data?

thanks @FerusGrim, a map will work for now so I can continue working on the plugin. @gabizou I’m not exactly sure what I need as of yet, but that sounds about right? The plugin is going to be the server side portion of a mod, for stuff like chat formatting and permissions, and it needs to be able to share this variable with the mod but the plugin will retrieve the player’s original selection from a config file and provide that to the mod so transient is fine.