Players
Here's how it works.
You create your own custom player class that extends from VitalPlayer.
public class MyPlayer extends VitalPlayer.Spigot {
public MyPlayer(Player player) {
super(player);
}
}
Then in this class you can define whatever custom data you want, e.g.:
public class MyPlayer extends VitalPlayer.Spigot {
private String myCustomString;
private boolean myCustomBoolean;
// ...
public MyPlayer(Player player) {
super(player);
}
// Getters and setters...
}
Then you must tell Vital to use this class in your application configuration (application.yaml, application.properties, etc.) in your project's src/main/resources location.
vital:
players:
player-class-name: fully.qualified.class.name.MyPlayer
Now, when any player joins your server, Vital will automatically create an instance of MyPlayer for each player.
Every instance of those custom players is stored in VitalPlayerRepository.
Use this repository in any of your other Spring beans to retrieve your custom player instance for any of your players.
E.g., when the player joins, you might want to initialize some data:
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
final var myPlayer = vitalPlayerRepository.findById(MyPlayer.class, e.getPlayer().getUniqueId());
myPlayer.setMyCustomString(...);
myPlayer.setMyCustomBoolean(...);
}
When a player leaves, Vital automatically cleans up your custom player instance so you don't have to.
This is especially useful to store typed session-data for your players.
E.g., scores in a minigame, etc.