29 Individual holograms
filoghost edited this page 2023-05-01 14:13:59 +02:00

This tutorial will teach you how to make individual holograms, and show/hide them to players dynamically.

The primary class to use for individual holograms is the VisibilitySettings of a hologram. You can retrieve it with this code:

// Suppose to have a player obtained before
HolographicDisplaysAPI api = HolographicDisplaysAPI.get(plugin);
Hologram hologram = api.createHologram(player.getLocation());
VisibilitySettings visibilitySettings = hologram.getVisibilitySettings();

With the VisibilitySettings you can choose if all the players should see or not a hologram by default, and also set rules for individual players. By default a hologram will be visible by default to everyone. Let's try to completely hide a hologram, for everyone:

// Hide the hologram to everyone
visibilitySettings.setGlobalVisibility(Visibility.HIDDEN);

Let's show it back:

// Show the hologram to everyone
visibilitySettings.setGlobalVisibility(Visibility.VISIBLE);

To hide a hologram to everyone except a player:

visibilitySettings.setGlobalVisibility(Visibility.HIDDEN);
visibilitySettings.setIndividualVisibility(player, Visibility.VISIBLE);

Now, let's bring everything back to the default values:

visibilitySettings.setGlobalVisibility(Visibility.VISIBLE);
visibilitySettings.clearIndividualVisibilities();
// The second line clears all the player specific settings