Hello!
I’ve encountered a problem where I doesn’t know how to continue.
I’m listening to the event ClientConnectionEvent.Login
, and is it possible to save a property or object inside that user object somehow, to be used later somewhere else? Or do I need to save every user in a list just to keep that value and use it just once?
Inside org.spongepowered.api.profile.GameProfile
I’ve found a property map, but doesn’t understand what it is for or how to use it properly. Could someone who knows explain?
Help is appreciated, thanks!
Yrlish
First off, a Multimap is where multiple keys can have the same value, and one key can have multiple values. Call getPropertyMap()
on your GameProfile, and add new ProfileProperties using the static of()
method. I don’t know what the significance of the String is in the Multimap, but I would guess that you should use your plugin ID for that.
The user properties is just used for Mojang’s profile information (specifically skins); you shouldn’t touch it. However, I assume you’re just storing temporary data, so you can probably just cache the value. The fastest implementation would probably be a HashMap
, although if a plugin prevents the user from joining after your event handler runs, it could fill up with useless entries.
1 Like
A hashmap was what I were considering, but I hoped I could do it in another way. But this will most likely be how I’ll proceed.
And thanks for the clarification of the property thing.
1 Like
If you need to persist across server restarts, consider implementing a custom DataManipulator.
Unfortunately, User
doesn’t support custom DataManipulator
s at the moment.
I checked the source code on GitHub. I might have missed something, though.