Advertisement
JackOUT

Untitled

Jun 4th, 2023
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package games.coob.hologram;
  2.  
  3. import games.coob.nmsinterface.HologramRegistry;
  4. import games.coob.nmsinterface.NMSHologramI;
  5. import lombok.RequiredArgsConstructor;
  6. import org.bukkit.Location;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.scheduler.BukkitRunnable;
  9. import org.mineacademy.fo.remain.Remain;
  10.  
  11. /**
  12.  * Represents a self-repeating task managing hologram.
  13.  */
  14. @RequiredArgsConstructor
  15. public final class HologramTask extends BukkitRunnable {
  16.  
  17.     @Override
  18.     public void run() {
  19.         final double range = 20;
  20.  
  21.         for (final Player player : Remain.getOnlinePlayers()) {
  22.             for (final HologramRegistry registry : HologramRegistry.getHolograms()) {
  23.                 final NMSHologramI hologram = registry.getHologram();
  24.  
  25.                 System.out.println("Holograms: " + HologramRegistry.getHolograms());
  26.                 System.out.println("Hologram IDs: " + HologramRegistry.getHologramIDs());
  27.  
  28.                 if (hologram == null)
  29.                     continue;
  30.  
  31.                 if (!player.hasMetadata(hologram.getUniqueId().toString())/* && registry.getHologram().isRegistered(hologram)*/)
  32.                     showPlayersInRange(hologram, player, range);
  33.  
  34.                 if (player.getLocation().distance(hologram.getLocation()) > range && hologram.isShown())
  35.                     hologram.hide(player);
  36.             }
  37.         }
  38.     }
  39.  
  40.     /*
  41.      * Shows the hologram to players within the set range
  42.      */
  43.     private void showPlayersInRange(final NMSHologramI hologram, final Player player, final double range) {
  44.         final Location hologramLocation = hologram.getLocation();
  45.         final Location playerLocation = player.getLocation();
  46.         final String[] array = new String[hologram.getLines().size()];
  47.  
  48.         if (player.getWorld().equals(hologramLocation.getWorld()) && playerLocation.distance(hologramLocation) <= range)
  49.             hologram.show(hologramLocation, player, hologram.getLines().toArray(array));
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement