Skip to content

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.

Initializing HologramLib

Basic Setup

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.")
        );
    }
}

Storing the Manager Reference

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.

Understanding Rendering Modes

HologramLib offers different rendering modes to control hologram visibility:

Available Modes

public enum RenderMode {
    ALL,        // Visible to all online players
    VIEWER_LIST, // Only visible to specifically added players
    NONE        // Not visible to any players
}

Usage Example

/* Create a hologram with specific render mode */
TextHologram hologram = new TextHologram("unique_id", RenderMode.NEARBY);

Billboard Types

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/down

Basic Hologram Properties

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

Event Loop and Updates

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

Best Practices

  1. ID Management

    • IDs must be unique for each hologram
    • IDs cannot contain spaces
  2. Resource Management

    • Remove holograms when no longer needed using HologramManager#remove(id/hologram)
  3. Error Handling

    hologramManager.getHologram("id").ifPresent(hologram -> {
        if(hologram instanceof TextHologram textHologram) {
          /*Safely modify hologram*/
          textHologram.setText("Another text").update();
        }
    });

Next Steps

Clone this wiki locally