From 5064c989ed5bc14ab3e1cd56c7fee5945ec28b83 Mon Sep 17 00:00:00 2001 From: filoghost Date: Tue, 23 Dec 2014 11:42:52 +0100 Subject: [PATCH] Track placeholders when using setText() --- .../object/line/CraftTextLine.java | 15 ++++++++++++--- .../placeholder/PlaceholdersManager.java | 13 ++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/line/CraftTextLine.java b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/line/CraftTextLine.java index 9f8177f1..d08fc5a6 100644 --- a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/line/CraftTextLine.java +++ b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/object/line/CraftTextLine.java @@ -10,6 +10,7 @@ import com.gmail.filoghost.holographicdisplays.api.line.TextLine; import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSNameable; import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSRideable; import com.gmail.filoghost.holographicdisplays.object.CraftHologram; +import com.gmail.filoghost.holographicdisplays.placeholder.PlaceholdersManager; import com.gmail.filoghost.holographicdisplays.util.Offsets; public class CraftTextLine extends CraftTouchableLine implements TextLine { @@ -37,8 +38,16 @@ public class CraftTextLine extends CraftTouchableLine implements TextLine { public void setText(String text) { this.text = text; - if (nmsNameble != null && text != null && !text.isEmpty()) { - nmsNameble.setCustomNameNMS(text); + if (nmsNameble != null) { + if (text != null && !text.isEmpty()) { + nmsNameble.setCustomNameNMS(text); + } else { + nmsNameble.setCustomNameNMS(null); + } + + if (getParent().isAllowPlaceholders()) { + PlaceholdersManager.trackIfNecessary(this); + } } } @@ -143,6 +152,6 @@ public class CraftTextLine extends CraftTouchableLine implements TextLine { @Override public String toString() { return "CraftTextLine [text=" + text + "]"; - } + } } diff --git a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/placeholder/PlaceholdersManager.java b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/placeholder/PlaceholdersManager.java index 1fe79a37..f2c4d0b5 100644 --- a/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/placeholder/PlaceholdersManager.java +++ b/HolographicDisplays/Plugin/com/gmail/filoghost/holographicdisplays/placeholder/PlaceholdersManager.java @@ -37,7 +37,7 @@ public class PlaceholdersManager { public static void load(Plugin plugin) { - Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() { @@ -131,7 +131,7 @@ public class PlaceholdersManager { } - // Players in a world count pattern. + // Players in a world count pattern. matcher = WORLD_PATTERN.matcher(name); while (matcher.find()) { @@ -168,7 +168,7 @@ public class PlaceholdersManager { return String.valueOf(BungeeServerTracker.getPlayersOnline(serverName)); } }); - } + } // Animation pattern. matcher = ANIMATION_PATTERN.matcher(name); @@ -212,10 +212,13 @@ public class PlaceholdersManager { } // It could be already tracked! - if (linesToUpdate.add(lineData)) { - updatePlaceholders(lineData); + if (!linesToUpdate.add(lineData)) { + linesToUpdate.remove(lineData); + linesToUpdate.add(lineData); } + updatePlaceholders(lineData); + } else { // The name needs to be updated anyways.