Advertisement
JackOUT

Untitled

Jan 8th, 2022
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. package games.coob.core.hologram;
  2.  
  3. import games.coob.core.specific.hologram.NMSHologram;
  4. import lombok.RequiredArgsConstructor;
  5. import org.bukkit.Location;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.scheduler.BukkitRunnable;
  8. import org.mineacademy.fo.remain.Remain;
  9.  
  10. /**
  11.  * Represents a self-repeating task managing hologram.
  12.  */
  13. @RequiredArgsConstructor
  14. public final class HologramTask extends BukkitRunnable {
  15.  
  16.     /**
  17.      * The range from which holograms are visible
  18.      */
  19.     private final double visibleTresholdBlocks;
  20.  
  21.     /**
  22.      * @see Runnable#run()
  23.      */
  24.     @Override
  25.     public void run() {
  26.         final HologramRegistry registry = HologramRegistry.getInstance();
  27.  
  28.         for (final Player player : Remain.getOnlinePlayers()) {
  29.             for (final NMSHologram hologram : registry.getLoadedHolograms()) {
  30.                 if (registry.isRegistered(hologram))
  31.                     NMSHologram.sendTo(hologram.getLocation(), player, hologram.getLines());
  32.                 else showPlayersInRange(hologram);
  33.             }
  34.         }
  35.     }
  36.  
  37.     /*
  38.      * Shows players within the set range to the NPC
  39.      */
  40.     private void showPlayersInRange(final NMSHologram hologram) {
  41.         final Location hologramLocation = hologram.getLocation();
  42.  
  43.         for (final Player online : Remain.getOnlinePlayers()) {
  44.             final Location onlineLocation = online.getLocation();
  45.  
  46.             if (onlineLocation.getWorld().equals(hologramLocation.getWorld()) && onlineLocation.distance(hologramLocation) < this.visibleTresholdBlocks) {
  47.                 hologram.show(hologramLocation, online, hologram.getLines());
  48.             }
  49.         }
  50.     }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement