15 Moving holograms
filoghost edited this page 2023-05-01 16:25:35 +02:00

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