Advertisement
JackOUT

Untitled

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