diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java index bfc0ba11..15372780 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/HolographicDisplays.java @@ -187,7 +187,7 @@ public class HolographicDisplays extends FCommonsPlugin { @Override public void onDisable() { if (lineTrackerManager != null) { - lineTrackerManager.clearTrackedPlayersAndSendPackets(); + lineTrackerManager.resetViewersAndSendDestroyPackets(); } if (nmsManager != null) { diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramLine.java index 3941bc53..5f63e6d7 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/base/BaseHologramLine.java @@ -35,8 +35,8 @@ public abstract class BaseHologramLine extends BaseHologramComponent implements tracker.setLineChanged(); } - protected final boolean isTrackedPlayer(Player player) { - return tracker.isTrackedPlayer(player); + protected final boolean isViewer(Player player) { + return tracker.isViewer(player); } @Override @@ -72,7 +72,7 @@ public abstract class BaseHologramLine extends BaseHologramComponent implements return !isDeleted() && player.isOnline() && player.getGameMode() != GameMode.SPECTATOR - && isTrackedPlayer(player) + && isViewer(player) && isVisibleTo(player); } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ClickableLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ClickableLineTracker.java index ebebe132..5175b23b 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ClickableLineTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ClickableLineTracker.java @@ -12,7 +12,7 @@ import me.filoghost.holographicdisplays.plugin.hologram.base.BaseClickableHologr import me.filoghost.holographicdisplays.plugin.listener.LineClickListener; import org.jetbrains.annotations.MustBeInvokedByOverriders; -public abstract class ClickableLineTracker extends PositionBasedLineTracker { +public abstract class ClickableLineTracker extends PositionBasedLineTracker { private final ClickableNMSPacketEntity clickableEntity; private final double positionOffsetY; diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/DisplayText.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/DisplayText.java index 1ca82b23..e9178400 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/DisplayText.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/DisplayText.java @@ -60,13 +60,13 @@ class DisplayText { return globalText; } - public boolean updateReplacements(Collection trackedPlayers) { + public boolean updateReplacements(Collection viewers) { boolean changed = false; if (containsIndividualPlaceholders()) { - for (TextLineTrackedPlayer trackedPlayer : trackedPlayers) { - String individualText = computeIndividualText(trackedPlayer); - if (trackedPlayer.updateIndividualText(individualText)) { + for (TextLineViewer viewer : viewers) { + String individualText = computeIndividualText(viewer); + if (viewer.updateIndividualText(individualText)) { changed = true; } } @@ -89,9 +89,9 @@ class DisplayText { } } - public @NotNull String computeIndividualText(TrackedPlayer trackedPlayer) { + public @NotNull String computeIndividualText(Viewer viewer) { Preconditions.notNull(unreplacedText, "unreplacedText"); - Player player = trackedPlayer.getPlayer(); + Player player = viewer.getPlayer(); return unreplacedText.replaceParts( (PlaceholderOccurrence placeholderOccurrence) -> { diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java index 7d655486..e93375d4 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/ItemLineTracker.java @@ -16,7 +16,7 @@ import org.jetbrains.annotations.MustBeInvokedByOverriders; import java.util.Collection; import java.util.Objects; -public class ItemLineTracker extends ClickableLineTracker { +public class ItemLineTracker extends ClickableLineTracker { private final BaseItemHologramLine line; private final ItemNMSPacketEntity itemEntity; @@ -43,10 +43,10 @@ public class ItemLineTracker extends ClickableLineTracker { protected void update(Collection onlinePlayers) { super.update(onlinePlayers); - if (spawnItemEntity && hasTrackedPlayers() && line.hasPickupCallback()) { - for (TrackedPlayer trackedPlayer : getTrackedPlayers()) { - if (CollisionHelper.isInPickupRange(trackedPlayer.getPlayer(), position)) { - line.onPickup(trackedPlayer.getPlayer()); + if (spawnItemEntity && hasViewers() && line.hasPickupCallback()) { + for (Viewer viewer : getViewers()) { + if (CollisionHelper.isInPickupRange(viewer.getPlayer(), position)) { + line.onPickup(viewer.getPlayer()); } } } @@ -58,8 +58,8 @@ public class ItemLineTracker extends ClickableLineTracker { } @Override - protected TrackedPlayer createTrackedPlayer(Player player) { - return new TrackedPlayer(player); + protected Viewer createViewer(Player player) { + return new Viewer(player); } @MustBeInvokedByOverriders @@ -90,7 +90,7 @@ public class ItemLineTracker extends ClickableLineTracker { @MustBeInvokedByOverriders @Override - protected void sendSpawnPackets(Viewers viewers) { + protected void sendSpawnPackets(Viewers viewers) { super.sendSpawnPackets(viewers); if (spawnItemEntity) { @@ -100,7 +100,7 @@ public class ItemLineTracker extends ClickableLineTracker { @MustBeInvokedByOverriders @Override - protected void sendDestroyPackets(Viewers viewers) { + protected void sendDestroyPackets(Viewers viewers) { super.sendDestroyPackets(viewers); if (spawnItemEntity) { @@ -110,7 +110,7 @@ public class ItemLineTracker extends ClickableLineTracker { @MustBeInvokedByOverriders @Override - protected void sendChangesPackets(Viewers viewers) { + protected void sendChangesPackets(Viewers viewers) { super.sendChangesPackets(viewers); if (spawnItemEntityChanged) { @@ -127,7 +127,7 @@ public class ItemLineTracker extends ClickableLineTracker { @MustBeInvokedByOverriders @Override - protected void sendPositionChangePackets(Viewers viewers) { + protected void sendPositionChangePackets(Viewers viewers) { super.sendPositionChangePackets(viewers); if (spawnItemEntity) { diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java index 381058f2..6ce3b53e 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTracker.java @@ -13,10 +13,10 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; -public abstract class LineTracker { +public abstract class LineTracker { - private final Map trackedPlayers; - private final Viewers trackedPlayersIterableView; + private final Map viewers; + private final Viewers iterableViewers; /** * Flag to indicate that the line has changed in some way and there could be the need to send update packets. @@ -24,8 +24,8 @@ public abstract class LineTracker { private boolean lineChanged; protected LineTracker() { - this.trackedPlayers = new HashMap<>(); - this.trackedPlayersIterableView = action -> trackedPlayers.values().forEach(action); + this.viewers = new HashMap<>(); + this.iterableViewers = action -> viewers.values().forEach(action); } protected abstract BaseHologramLine getLine(); @@ -36,7 +36,7 @@ public abstract class LineTracker { @MustBeInvokedByOverriders public void onRemoval() { - clearTrackedPlayersAndSendPackets(); + resetViewersAndSendDestroyPackets(); } public final void setLineChanged() { @@ -60,14 +60,14 @@ public abstract class LineTracker { // Then, send the changes (if any) to already tracked players if (sendChangesPackets) { - if (hasTrackedPlayers()) { - sendChangesPackets(trackedPlayersIterableView); + if (hasViewers()) { + sendChangesPackets(iterableViewers); } clearDetectedChanges(); } // Finally, add/remove tracked players sending them the full spawn/destroy packets - modifyTrackedPlayersAndSendPackets(onlinePlayers); + modifyViewersAndSendPackets(onlinePlayers); } protected abstract void detectChanges(); @@ -76,9 +76,9 @@ public abstract class LineTracker { protected abstract boolean updatePlaceholders(); - private void modifyTrackedPlayersAndSendPackets(Collection onlinePlayers) { + private void modifyViewersAndSendPackets(Collection onlinePlayers) { if (!getLine().isInLoadedChunk()) { - clearTrackedPlayersAndSendPackets(); + resetViewersAndSendDestroyPackets(); return; } @@ -88,21 +88,21 @@ public abstract class LineTracker { for (Player player : onlinePlayers) { if (shouldTrackPlayer(player)) { - if (!trackedPlayers.containsKey(player)) { - T trackedPlayer = createTrackedPlayer(player); - trackedPlayers.put(player, trackedPlayer); + if (!viewers.containsKey(player)) { + T viewer = createViewer(player); + viewers.put(player, viewer); if (addedPlayers == null) { addedPlayers = new MutableViewers<>(); } - addedPlayers.add(trackedPlayer); + addedPlayers.add(viewer); } } else { - if (trackedPlayers.containsKey(player)) { - T trackedPlayer = trackedPlayers.remove(player); + if (viewers.containsKey(player)) { + T viewer = viewers.remove(player); if (removedPlayers == null) { removedPlayers = new MutableViewers<>(); } - removedPlayers.add(trackedPlayer); + removedPlayers.add(viewer); } } } @@ -115,33 +115,33 @@ public abstract class LineTracker { } } - protected abstract T createTrackedPlayer(Player player); + protected abstract T createViewer(Player player); protected abstract boolean shouldTrackPlayer(Player player); - protected final boolean hasTrackedPlayers() { - return !trackedPlayers.isEmpty(); + protected final boolean hasViewers() { + return !viewers.isEmpty(); } - protected final Collection getTrackedPlayers() { - return trackedPlayers.values(); + protected final Collection getViewers() { + return viewers.values(); } - public final boolean isTrackedPlayer(Player player) { - return trackedPlayers.containsKey(player); + public final boolean isViewer(Player player) { + return viewers.containsKey(player); } - protected final void removeTrackedPlayer(Player player) { - trackedPlayers.remove(player); + protected final void removeViewer(Player player) { + viewers.remove(player); } - protected final void clearTrackedPlayersAndSendPackets() { - if (!hasTrackedPlayers()) { + protected final void resetViewersAndSendDestroyPackets() { + if (!hasViewers()) { return; } - sendDestroyPackets(trackedPlayersIterableView); - trackedPlayers.clear(); + sendDestroyPackets(iterableViewers); + viewers.clear(); } protected abstract void sendSpawnPackets(Viewers viewers); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTrackerManager.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTrackerManager.java index 48dad358..405460e1 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTrackerManager.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/LineTrackerManager.java @@ -61,15 +61,15 @@ public class LineTrackerManager { } } - public void clearTrackedPlayersAndSendPackets() { + public void resetViewersAndSendDestroyPackets() { for (LineTracker tracker : lineTrackers) { - tracker.clearTrackedPlayersAndSendPackets(); + tracker.resetViewersAndSendDestroyPackets(); } } public void onPlayerQuit(Player player) { for (LineTracker tracker : lineTrackers) { - tracker.removeTrackedPlayer(player); + tracker.removeViewer(player); } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/MutableViewers.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/MutableViewers.java index a86f33a4..aa5cf15c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/MutableViewers.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/MutableViewers.java @@ -9,7 +9,7 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -public class MutableViewers implements Viewers { +public class MutableViewers implements Viewers { // Optimization: the viewer is frequently only a single player private T viewer; diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/PositionBasedLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/PositionBasedLineTracker.java index 45554232..52159724 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/PositionBasedLineTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/PositionBasedLineTracker.java @@ -12,7 +12,7 @@ import org.jetbrains.annotations.MustBeInvokedByOverriders; import java.util.Objects; -abstract class PositionBasedLineTracker extends LineTracker { +abstract class PositionBasedLineTracker extends LineTracker { private static final int ENTITY_VIEW_RANGE = 64; diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java index e73e335b..a78012a5 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTracker.java @@ -16,7 +16,7 @@ import org.jetbrains.annotations.MustBeInvokedByOverriders; import java.util.Objects; -public class TextLineTracker extends ClickableLineTracker { +public class TextLineTracker extends ClickableLineTracker { private final BaseTextHologramLine line; private final TextNMSPacketEntity textEntity; @@ -42,7 +42,7 @@ public class TextLineTracker extends ClickableLineTracker @Override protected boolean updatePlaceholders() { - boolean placeholdersChanged = displayText.updateReplacements(getTrackedPlayers()); + boolean placeholdersChanged = displayText.updateReplacements(getViewers()); if (placeholdersChanged) { displayTextChanged = true; // Mark as changed to trigger a packet send with updated placeholders } @@ -50,8 +50,8 @@ public class TextLineTracker extends ClickableLineTracker } @Override - protected TextLineTrackedPlayer createTrackedPlayer(Player player) { - return new TextLineTrackedPlayer(player, displayText); + protected TextLineViewer createViewer(Player player) { + return new TextLineViewer(player, displayText); } @MustBeInvokedByOverriders @@ -81,7 +81,7 @@ public class TextLineTracker extends ClickableLineTracker @MustBeInvokedByOverriders @Override - protected void sendSpawnPackets(Viewers viewers) { + protected void sendSpawnPackets(Viewers viewers) { super.sendSpawnPackets(viewers); IndividualTextPacketGroup spawnPackets = textEntity.newSpawnPackets(position); @@ -90,13 +90,13 @@ public class TextLineTracker extends ClickableLineTracker @MustBeInvokedByOverriders @Override - protected void sendDestroyPackets(Viewers viewers) { + protected void sendDestroyPackets(Viewers viewers) { super.sendDestroyPackets(viewers); viewers.sendPackets(textEntity.newDestroyPackets()); } @Override - protected void sendChangesPackets(Viewers viewers) { + protected void sendChangesPackets(Viewers viewers) { super.sendChangesPackets(viewers); if (displayTextChanged) { @@ -107,7 +107,7 @@ public class TextLineTracker extends ClickableLineTracker @MustBeInvokedByOverriders @Override - protected void sendPositionChangePackets(Viewers viewers) { + protected void sendPositionChangePackets(Viewers viewers) { super.sendPositionChangePackets(viewers); viewers.sendPackets(textEntity.newTeleportPackets(position)); } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTrackedPlayer.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineViewer.java similarity index 93% rename from plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTrackedPlayer.java rename to plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineViewer.java index a1ade1e4..3ec5fba1 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineTrackedPlayer.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TextLineViewer.java @@ -11,14 +11,14 @@ import org.jetbrains.annotations.Nullable; import java.util.Objects; -class TextLineTrackedPlayer extends TrackedPlayer { +class TextLineViewer extends Viewer { private final DisplayText displayText; private String individualText; private String lastSentText; - TextLineTrackedPlayer(Player player, DisplayText displayText) { + TextLineViewer(Player player, DisplayText displayText) { super(player); this.displayText = displayText; } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TrackedPlayer.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/Viewer.java similarity index 89% rename from plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TrackedPlayer.java rename to plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/Viewer.java index 0f11b0ba..0e75997e 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/TrackedPlayer.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/Viewer.java @@ -8,11 +8,11 @@ package me.filoghost.holographicdisplays.plugin.hologram.tracking; import me.filoghost.holographicdisplays.nms.common.PacketGroup; import org.bukkit.entity.Player; -class TrackedPlayer { +class Viewer { private final Player player; - TrackedPlayer(Player player) { + Viewer(Player player) { this.player = player; } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/Viewers.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/Viewers.java index 51dca9bb..fdc82855 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/Viewers.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/tracking/Viewers.java @@ -9,7 +9,7 @@ import me.filoghost.holographicdisplays.nms.common.PacketGroup; import java.util.function.Consumer; -interface Viewers { +interface Viewers { void forEach(Consumer action);