2 minutes estimated read time

Players

Here's how it works.
You create your own custom player class that extends from VitalPlayer.

MyPlayer.java
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.:

MyPlayer.java
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.

src/main/resources/application.yaml
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:

MyListener.java
@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.

Found an issue?

Help us improve the documentation by reporting typos, missing information, or anything confusing.

Don't worry, we will auto-fill most of the annoying fields.

Create GitHub issue

This site and the Vital framework were built with ❤️ by Mike Neumann