Player holograms
Player holograms are bound to a specific player and can therefore be used to display data that is unique to a single player.
This type of hologram can be used to display stats, kills, and also translated text or other data.
If you don't need to show player-specific data or even translated text, check out global holograms.
Create a player hologram
Creating a player hologram requires Vital to execute some more logic, so to create your hologram, you must use the VitalHologramService.
Use VitalHologramService.createPlayerHologram(Player, List<VitalHologram.Line>, Location) to create a player hologram.
vitalHologramService.createPlayerHologram(
myPlayer,
myPlayer.getLocation(),
(player) -> new VitalHologram.Line("Line 1"),
(player) -> new VitalHologram.Line("Line 2"),
(player) -> new VitalHologram.Line("Line 3")
);
Note that all lines are lambda functions that return a VitalHologram.Line.
Everytime you update your hologram, these functions will be called to produce your actual hologram lines.
This method will essentially spawn an invisible marker armor stand that will display all of your lines at the given location for the given player only.
This hologram will only be visible for the player you provided, all other players on the server will not be able to see it. If you want to update a hologram, simply delete it and recreate it.
Note that when you create your player hologram, Vital will automatically store it in VitalHologramRepository.
This is done so that Vital can easily track all of your holograms to hide them from others, etc.
To retrieve your hologram at a later time, e.g., in a scheduled task or in an event, you can use this method:
final var myVitalPlayerHologram = vitalHologramRepository.find(VitalPlayerHologram.class, hologram -> hologram.getPlayerUniqueId().equals(myPlayer.getUniqueId()));
To update your hologram, use the VitalHologramService.update(VitalHologram) method.
vitalHologramService.updateHologram(myVitalPlayerHologram);
Deleting a player hologram
To delete a player hologram, simply use the VitalHologramService.deleteHologram(VitalHologram) method.
This will destroy the marker armor stand and all of its components, this cannot be undone!
After your hologram has been destroyed, it is removed from VitalHologramRepository.