Solved Storing a custom Java object

catslicer41

New member
Sep 4, 2024
4
0
1
I'm writing a plugin that runs a minigame. In this plugin, I have a class (I'll call it MinigamePlayer) that stores information about the Player. This class then stores other custom objects that store more information about the player.

How would it be best to store the connections between actual players and the MinigamePlayer that stores their data? I don't want to do this through Metadata or Persistent Data Containers, as that would require converting my custom objects to Strings and then back again later, and I don't really want to do that.
 
Last edited:

stefvanschie

Moderator
Staff member
Dec 17, 2021
121
7
21
18
Do you need this data to persist across server sessions? If not, there isn't really a reason to use PDC. You can simply store a reference to the Player object in your MinigamePlayer class. Be sure to remove the reference to the player when they leave the server, however, or use a WeakReference so it doesn't prevent garbage collection. If you need this information to persist across player sessions, then you can also store the UUID of the player and look the player up with it.
 
  • Like
Reactions: catslicer41

catslicer41

New member
Sep 4, 2024
4
0
1
Do you need this data to persist across server sessions? If not, there isn't really a reason to use PDC. You can simply store a reference to the Player object in your MinigamePlayer class. Be sure to remove the reference to the player when they leave the server, however, or use a WeakReference so it doesn't prevent garbage collection. If you need this information to persist across player sessions, then you can also store the UUID of the player and look the player up with it.
Thanks for the reply! I don't need the reference to persist across player sessions. I could store a reference to the Player in the MinigamePlayer, but then I still need to store a list of MinigamePlayers somewhere. Where would it be best do that?
 
Last edited:

stefvanschie

Moderator
Staff member
Dec 17, 2021
121
7
21
18
If you have some kind of Minigame object, then I'd store them in there. Otherwise, you can use or create some kind of MinigameManager object to store them.
 
  • Like
Reactions: catslicer41

catslicer41

New member
Sep 4, 2024
4
0
1
If you have some kind of Minigame object, then I'd store them in there. Otherwise, you can use or create some kind of MinigameManager object to store them.
I do have a Minigame object, but now I need to store that somewhere. Could it just be stored as a variable in my Plugin class (the one that extends JavaPlugin)?
 
Last edited: