Skip to content

Usage (Spigot)

Huynh Tien edited this page Sep 13, 2024 · 14 revisions

Get the provider

There are several ways to get yourself a hologram provider

Plugin

Add the plugin as a provided dependency

<dependency>
    <groupId>io.github.projectunified</groupId>
    <artifactId>uni-hologram-spigot-plugin</artifactId>
    <version>VERSION</version>
    <scope>provided</scope>
</dependency>

Add the plugin to the depend list of your plugin.yml

depend:
  - UniHologram

Now you can get the provider within the plugin

HologramProvider<Location> provider = JavaPlugin.getPlugin(UniHologramPlugin.class).getProvider();

Built-in Picker

Add the picker dependency

<dependency>
    <groupId>io.github.projectunified</groupId>
    <artifactId>uni-hologram-spigot-picker</artifactId>
    <version>VERSION</version>
</dependency>

Add the required plugins to the softdepend list of your plugin.yml

softdepend:
  - DecentHolograms
  - HolographicDisplays
  - CMI
  - FancyHolograms

Now you can use the prepared picker to get yourself a hologram provider

HologramProvider<Location> provider = new SpigotHologramProviderPicker(plugin).pick();

Do-it-yourself Picker

In case you want only some providers but not all providers, you can make yourself a picker and let it choose the provider for you.

Add the picker dependency

<dependency>
    <groupId>io.github.projectunified</groupId>
    <artifactId>uni-hologram-picker</artifactId>
    <version>VERSION</version>
</dependency>

Add dependencies of the providers

<!-- Holographic Displays -->
<dependency>
    <groupId>me.hsgamer</groupId>
    <artifactId>uni-hologram-spigot-holographicdisplays</artifactId>
    <version>VERSION</version>
</dependency>

<!-- DecentHolograms -->
<dependency>
    <groupId>me.hsgamer</groupId>
    <artifactId>uni-hologram-spigot-decentholograms</artifactId>
    <version>VERSION</version>
</dependency>

<!-- CMI -->
<dependency>
    <groupId>me.hsgamer</groupId>
    <artifactId>uni-hologram-spigot-cmi</artifactId>
    <version>VERSION</version>
</dependency>

<!-- Fancy Holograms -->
<dependency>
    <groupId>me.hsgamer</groupId>
    <artifactId>uni-hologram-spigot-fancyholograms</artifactId>
    <version>VERSION</version>
</dependency>

<!-- Vanilla -->
<dependency>
    <groupId>me.hsgamer</groupId>
    <artifactId>uni-hologram-spigot-vanilla</artifactId>
    <version>VERSION</version>
</dependency>

<!-- Check the project files for more providers -->

Add the required plugins to the softdepend list of your plugin.yml

softdepend:
  - DecentHolograms
  - HolographicDisplays
  - CMI
  - FancyHolograms

Now, you can create a picker, add the providers and then let it pick an appropriate one

HologramProvider<Location> provider = new HologramProviderPicker<Plugin, Location>(plugin)
                                          .add(CMIHologramProvider::isAvailable, CMIHologramProvider::new)
                                          .add(DHHologramProvider::isAvailable, DHHologramProvider::new)
                                          .add(FHHologramProvider::isAvailable, FHHologramProvider::new)
                                          .add(HDHologramProvider::isAvailable, HDHologramProvider::new)
                                          .add(() -> true, VanillaHologramProvider::new)
                                          .pick();

Shade

When you shade the library to your plugin, it's recommended to relocate the package so that it doesn't cause conflict with other plugins

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.6.0</version>
    <configuration>
        <relocations>
            <relocation>
                <pattern>io.github.projectunified.unihologram</pattern>
                <shadedPattern>YOUR_PACKAGE.unihologram</shadedPattern>
            </relocation>
        </relocations>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Basic Usage

// Create & Initialize the hologram
Hologram<Location> hologram = provider.createHologram("test", location);
hologram.init(); // Important

// Hologram methods
hologram.addLine(new TextHologramLine("This is a fancy line"));
hologram.setLine(new TextHologramLine("This is another line"));
hologram.insertLine(0, new ItemHologramLine(new ItemStack(Material.STONE)));
hologram.removeLine(1);
hologram.setLines(Arrays.asList(
  new ItemHologramLine(new ItemStack(Material.STONE)),
  new TextHologramLine("&f&lThis is a mysterious stone"),
  new TextHologramLine("&c&lYou cannot touch it")
));

// Visibility methods
if (hologram instanceof PlayerVisibility) {
  PlayerVisibility visibility = (PlayerVisibility) hologram;
  visibility.hideAll();
  visibility.showAll();
  visibility.hideTo(player);
  visibility.showTo(player);
  if (visibility.isVisible(player)) System.out.println("He can see the hologram");
}

// Clear/Delete the hologram
hologram.clear();
Clone this wiki locally