Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Moving holograms

filoghost edited this page May 1, 2023 · 15 revisions

Moving holograms it's really simple. Just use the teleport(Location loc) method.

Example

A hologram that follows a player above his head for 5 seconds.

// Suppose that we have already a Player object called "player"
HolographicDisplaysAPI api = HolographicDisplaysAPI.get(plugin);
final Hologram hologram = api.createHologram(player.getLocation().add(0.0, 2.0, 0.0));
hologram.getLines().appendText("Chat > Hello World");

new BukkitRunnable() {

	// We don't want the task to run indefinitely
	int ticksRun;

	@Override
	public void run() {
		ticksRun++;
		hologram.setPosition(player.getLocation().add(0.0, 2.0, 0.0));

		// 100 ticks = 5 seconds
		if (ticksRun > 100) {
			hologram.delete();
			cancel();
		}
	}

}.runTaskTimer(plugin, 1L, 1L);