Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package games.coob.core.hologram;
- import games.coob.core.specific.hologram.NMSHologram;
- 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 {
- /**
- * The range from which holograms are visible
- */
- private final double visibleTresholdBlocks;
- /**
- * @see Runnable#run()
- */
- @Override
- public void run() {
- final HologramRegistry registry = HologramRegistry.getInstance();
- for (final Player player : Remain.getOnlinePlayers()) {
- for (final NMSHologram hologram : registry.getLoadedHolograms()) {
- if (registry.isRegistered(hologram))
- NMSHologram.sendTo(hologram.getLocation(), player, hologram.getLines());
- else showPlayersInRange(hologram);
- }
- }
- }
- /*
- * Shows players within the set range to the NPC
- */
- private void showPlayersInRange(final NMSHologram hologram) {
- final Location hologramLocation = hologram.getLocation();
- for (final Player online : Remain.getOnlinePlayers()) {
- final Location onlineLocation = online.getLocation();
- if (onlineLocation.getWorld().equals(hologramLocation.getWorld()) && onlineLocation.distance(hologramLocation) < this.visibleTresholdBlocks) {
- hologram.show(hologramLocation, online, hologram.getLines());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement