Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package games.coob.hologram;
- import games.coob.nmsinterface.HologramRegistry;
- import games.coob.nmsinterface.NMSHologramI;
- import lombok.RequiredArgsConstructor;
- import org.bukkit.Location;
- import org.bukkit.entity.Player;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.mineacademy.fo.remain.Remain;
- /**
- * Represents a self-repeating task managing hologram.
- */
- @RequiredArgsConstructor
- public final class HologramTask extends BukkitRunnable {
- @Override
- public void run() {
- final double range = 20;
- for (final Player player : Remain.getOnlinePlayers()) {
- for (final HologramRegistry registry : HologramRegistry.getHolograms()) {
- final NMSHologramI hologram = registry.getHologram();
- System.out.println("Holograms: " + HologramRegistry.getHolograms());
- System.out.println("Hologram IDs: " + HologramRegistry.getHologramIDs());
- if (hologram == null)
- continue;
- if (!player.hasMetadata(hologram.getUniqueId().toString())/* && registry.getHologram().isRegistered(hologram)*/)
- showPlayersInRange(hologram, player, range);
- if (player.getLocation().distance(hologram.getLocation()) > range && hologram.isShown())
- hologram.hide(player);
- }
- }
- }
- /*
- * Shows the hologram to players within the set range
- */
- private void showPlayersInRange(final NMSHologramI hologram, final Player player, final double range) {
- final Location hologramLocation = hologram.getLocation();
- final Location playerLocation = player.getLocation();
- final String[] array = new String[hologram.getLines().size()];
- if (player.getWorld().equals(hologramLocation.getWorld()) && playerLocation.distance(hologramLocation) <= range)
- hologram.show(hologramLocation, player, hologram.getLines().toArray(array));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement