Repository navigation
2. Getting Started
Maxim edited this page Jan 22, 2025
·
5 revisions
This guide covers the fundamental concepts and initial setup required to start using HologramLib in your plugin.
public class YourPlugin extends JavaPlugin {
private HologramManager hologramManager;
@Override
public void onLoad() {
HologramLib.onLoad(this); /* Only needed if you shade HologramLib */
}
@Override
public void onEnable() {
HologramLib.getManager().ifPresentOrElse(
manager -> hologramManager = manager,
() -> getLogger().severe("Failed to initialize HologramLib manager.")
);
}
}It's recommended to store the HologramManager instance in a variable (which can be static, for example) or inject it via Dependency Injection for easy access throughout your plugin.
HologramLib offers different rendering modes to control hologram visibility:
public enum RenderMode {
ALL, // Visible to all online players
VIEWER_LIST, // Only visible to specifically added players
NONE // Not visible to any players
}/* Create a hologram with specific render mode */
TextHologram hologram = new TextHologram("unique_id", RenderMode.NEARBY);Holograms can be displayed in different orientations using Billboard settings:
/* Different billboard options */
hologram.setBillboard(Display.Billboard.CENTER); // Rotates to face players like a nametag (default)
hologram.setBillboard(Display.Billboard.FIXED); // Maintains a fixed rotation
hologram.setBillboard(Display.Billboard.VERTICAL); // Only rotates left/right
hologram.setBillboard(Display.Billboard.HORIZONTAL); // Only rotates up/downCommon properties available for all hologram types:
hologram
.setViewRange(1.0) // Sets viewing distance
.setTranslation(0, 1.5F, 0) // Sets the relative visual location of the hologram (this would move the hologram up by 1.5)
.setScale(1.0F, 1.0F, 1.0F) // Sets size of the hologram (x, y, z)
.setBillboard(Display.Billboard.CENTER) // Sets rotation behavior (explained above)
.setUpdateTaskPeriod(20L * 3) // Update interval in ticks (how often the list of players who should see the hologram should be updated)
.update();HologramLib automatically handles:
- Viewer updates based on render mode
- Entity tracking and visibility
- Position interpolation
You only need to call update() when changing hologram properties (not needed for add/removeViewer()):
hologram
.setText("New Text")
.setScale(2F, 2F, 2F)
.update(); // <--------------------
ID Management
- IDs must be unique for each hologram
- IDs cannot contain spaces
-
Resource Management
- Remove holograms when no longer needed using
HologramManager#remove(id/hologram)
- Remove holograms when no longer needed using
-
Error Handling
hologramManager.getHologram("id").ifPresent(hologram -> { if(hologram instanceof TextHologram textHologram) { /*Safely modify hologram*/ textHologram.setText("Another text").update(); } });
- Learn about Creating Holograms in more detail
- Explore Animation Features
- Set up Leaderboards
- Master Hologram Management
