Skip to content

Repository files navigation

How to use the Holograms-API

Setup the dependency

Add jitpack as a repository and the API as a dependency.

Gradle example:

repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile "com.github.randombyte-developer.holograms:holograms-api:v2.1.1"
}

That dependency only contains this one file.

How to use in code

Although everything is documented in theHologramService.kt it may not be clear how to use that Service written in Kotlin from a plugin written in Java. Basically, the fields prefixed with var like text and location have a getter and a setter method automatically generated to be used from the Java side.

Here is an example:

Optional<HologramsService> hologramsServiceOptional = Sponge.getServiceManager().provide(HologramsService.class);
HologramsServicehologramsService = hologramsServiceOptional.orElseThrow(
() -> newRuntimeException("HologramsAPI not available! Is the plugin 'holograms' installed?"));
// Creating a HologramOptional<HologramsService.Hologram> hologramOptional = hologramsService
.createHologram(player.getLocation(), Text.of(TextColors.GREEN, "Example text"));
if (!hologramOptional.isPresent()) {
player.sendMessage(Text.of("Hologram couldn't be spawned!"));
returnCommandResult.success();
}
// Modifying the HologramHologramhologram = hologramOptional.get();
hologram.setText(Text.of("New text"));
Location<World> newLocation = hologram.getLocation().add(0.0, 5.0, 0.0);
hologram.setLocation(newLocation);
// Finding the Hologram by UUID// Both UUIDs are saved somewhere (e.g. in a config file)UUIDhologramUuid = hologram.getUuid();
UUIDworldUuid = hologram.getWorldUuid();
Optional<World> worldOptional = Sponge.getServer().getWorld(worldUuid);
if (!worldOptional.isPresent()) {
player.sendMessage(Text.of("Couldn't find world!"));
returnCommandResult.success();
}
Worldworld = worldOptional.get();
Optional<? extendsHologram> loadedHologramOptional = hologramsService.getHologram(world, hologramUuid);
if (!loadedHologramOptional.isPresent()) {
player.sendMessage(Text.of("Couldn't find Hologram!"));
returnCommandResult.success();
}
HologramloadedHologram = loadedHologramOptional.get();
loadedHologram.setText(Text.of("This Hologram was found!"));
// Removing the HologramloadedHologram.remove();

If you have questions, please ask me!

Releases

Packages

Contributors

Languages