Skip to content

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.

HologramManager Methods

Existence Checks

// Check by ID
boolean exists = hologramManager.hologramExists("unique_id");

// Check by instance
boolean exists = hologramManager.hologramExists(hologram);

Hologram Retrieval

// 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();

Conditional Operations

// 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();
});

Hologram Removal

// Remove by ID
hologramManager.remove("unique_id");

// Remove by instance
hologramManager.remove(hologram);

// Remove leaderboard
hologramManager.remove(leaderboardHologram);

// Remove all holograms
hologramManager.removeAll();

Viewer Management

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) ..

Adding/Removing Viewers

// 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();

Entity Attachments

Attaching Holograms

// Basic attachment
hologramManager.attach(hologram, entityId);

// Attachment with persistence flag
hologramManager.attach(hologram, entityId, true);

Hologram Copying

Basic Copy

// Creates copy with auto-generated ID
Hologram<?> copy = hologramManager.copyHologram(sourceHologram);

Copy with Custom ID

// Creates copy with specified ID
Hologram<?> copy = hologramManager.copyHologram(sourceHologram, "new_id");

Update Configuration

Update Settings

hologram
    .setUpdateTaskPeriod(20L * 3)  // Update every 3 seconds
    .setNearbyEntityScanningDistance(30.0)  // Scan range in blocks
    .update();

Best Practices

Error Handling

hologramManager.getHologram("id").ifPresentOrElse(
    hologram -> {
        // Modify hologram safely
    },
    () -> {
        // Handle missing hologram
    }
);

Performance Optimization

// Batch updates
hologram
    .setText("New Text")
    .setScale(2.0F, 2.0F, 2.0F)
    .setBillboard(Display.Billboard.CENTER)
    .update(); // Single update at the end

Safe Modification

// Check existence before modification
hologramManager.updateHologramIfExists("id", hologram -> {
   hologram.setScale(4F, 4F, 4F).update();
});

Common Issues and Solutions

Visibility Issues

  • 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)

Related Topics