-
Notifications
You must be signed in to change notification settings - Fork 5
4. Hologram Management
Maxim edited this page Feb 2, 2025
·
4 revisions
This page covers all aspects of managing holograms using the HologramManager, including retrieval, modifications, and advanced operations.
// Check by ID
boolean exists = hologramManager.hologramExists("unique_id");
// Check by instance
boolean exists = hologramManager.hologramExists(hologram);
// Get by ID
Optional<Hologram<?>> hologram = hologramManager.getHologram("unique_id");
// Get all holograms
List<Hologram<?>> allHolograms = hologramManager.getHolograms();
// Get all hologram IDs
List<String> allIds = hologramManager.getHologramIds();
// Execute if hologram exists
hologramManager.ifHologramExists("unique_id", hologram -> {
// Modify hologram
});
// Update if exists and return success status
boolean updated = hologramManager.updateHologramIfExists("unique_id", hologram -> {
if(hologram instanceof TextHologram textHologram) textHologram.setText("New Text").update();
});
// Remove by ID
hologramManager.remove("unique_id");
// Remove by instance
hologramManager.remove(hologram);
// Remove leaderboard
hologramManager.remove(leaderboardHologram);
// Remove all holograms
hologramManager.removeAll();
The following methods will only affect anything if you spawned a hologram with RenderMode.VIEWER_LIST
!
...
TextHologram textHologram = new TextHologram("unique_id", RenderMode.VIEWER_LIST) ..
// Add single viewer
hologram.addViewer(player);
// Add multiple viewers
hologram.addAllViewers(playerList);
// Remove viewer
hologram.removeViewer(player);
// Remove all viewers
hologram.removeAllViewers();
// Get current viewers (Which are allowed to see the hologram if `RenderMode` is set to `VIEWER_LIST`)
List<Player> viewers = hologram.getViewers();
// Get active viewers (currently seeing the hologram)
List<Player> activeViewers = hologram.getActiveViewers();
// Basic attachment
hologramManager.attach(hologram, entityId);
// Attachment with persistence flag
hologramManager.attach(hologram, entityId, true);
// Creates copy with auto-generated ID
Hologram<?> copy = hologramManager.copyHologram(sourceHologram);
// Creates copy with specified ID
Hologram<?> copy = hologramManager.copyHologram(sourceHologram, "new_id");
hologram
.setUpdateTaskPeriod(20L * 3) // Update every 3 seconds
.setNearbyEntityScanningDistance(30.0) // Scan range in blocks
.update();
hologramManager.getHologram("id").ifPresentOrElse(
hologram -> {
// Modify hologram safely
},
() -> {
// Handle missing hologram
}
);
// Batch updates
hologram
.setText("New Text")
.setScale(2.0F, 2.0F, 2.0F)
.setBillboard(Display.Billboard.CENTER)
.update(); // Single update at the end
// Check existence before modification
hologramManager.updateHologramIfExists("id", hologram -> {
hologram.setScale(4F, 4F, 4F).update();
});
- Check background color & text opacity
- Check for Billboard type (Billboard.FIXED will only make the hologram visible from one side)
- Check for scale
- Check if you even spawned the hologram or not using
HologramManager#spawn(Hologram)
- Creating Holograms for hologram creation
- Animations for text animation management
- Leaderboards for leaderboard management