From ed73b8e0983c27c432c69c6082ea0a8807f92d63 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 25 Jul 2021 20:18:28 +0200 Subject: [PATCH] Add back support for placeholder toggle --- .../common/hologram/StandardHologramLine.java | 2 ++ .../plugin/hologram/api/APIHologram.java | 3 +++ .../hologram/base/BaseHologramLine.java | 3 ++- .../plugin/hologram/tracking/DisplayText.java | 2 +- .../hologram/tracking/TextLineTracker.java | 19 +++++++++++++++++-- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramLine.java b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramLine.java index 0fbc4183..0ecb2e27 100644 --- a/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramLine.java +++ b/common/src/main/java/me/filoghost/holographicdisplays/common/hologram/StandardHologramLine.java @@ -15,4 +15,6 @@ public interface StandardHologramLine extends StandardHologramComponent { double getHeight(); + void setChanged(); + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologram.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologram.java index eff987c2..01622d77 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologram.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/hologram/api/APIHologram.java @@ -101,6 +101,9 @@ public class APIHologram extends BaseHologram implements Hologr } this.allowPlaceholders = allowPlaceholders; + for (APIHologramLine line : getLines()) { + line.setChanged(); + } } @Override 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 39baf1de..7914c8e5 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 @@ -30,7 +30,8 @@ public abstract class BaseHologramLine extends BaseHologramComponent implements return hologram; } - protected void setChanged() { + @Override + public void setChanged() { tracker.setLineChanged(); } 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 8741a929..9e80ba60 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 @@ -26,7 +26,7 @@ class DisplayText { void set(@Nullable String textString) { textWithoutReplacements = StringWithPlaceholders.of(textString); - textWithGlobalReplacements = null; + textWithGlobalReplacements = textWithoutReplacements; } String get() { 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 48665f0a..1c652a8d 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 @@ -20,6 +20,7 @@ public class TextLineTracker extends TouchableLineTracker { private final DisplayText displayText; private boolean displayTextChanged; + private boolean allowPlaceholders; public TextLineTracker(StandardTextLine line, NMSManager nmsManager, PlaceholderTracker placeholderTracker) { super(line, nmsManager); @@ -29,6 +30,10 @@ public class TextLineTracker extends TouchableLineTracker { @Override protected boolean updatePlaceholders() { + if (!allowPlaceholders) { + return false; + } + boolean placeholdersChanged = displayText.updateGlobalReplacements(); if (placeholdersChanged) { displayTextChanged = true; // Mark as changed to trigger a packet send with updated placeholders @@ -46,6 +51,12 @@ public class TextLineTracker extends TouchableLineTracker { this.displayText.set(displayText); this.displayTextChanged = true; } + + boolean allowPlaceholders = line.isAllowPlaceholders(); + if (this.allowPlaceholders != allowPlaceholders) { + this.allowPlaceholders = allowPlaceholders; + this.displayTextChanged = true; + } } @MustBeInvokedByOverriders @@ -60,7 +71,9 @@ public class TextLineTracker extends TouchableLineTracker { protected void addSpawnPackets(NMSPacketList packetList) { super.addSpawnPackets(packetList); - if (displayText.containsIndividualPlaceholders()) { + if (!allowPlaceholders) { + packetList.addArmorStandSpawnPackets(armorStandEntityID, locationX, getArmorStandLocationY(), locationZ, displayText.get()); + } else if (displayText.containsIndividualPlaceholders()) { packetList.addArmorStandSpawnPackets(armorStandEntityID, locationX, getArmorStandLocationY(), locationZ, displayText::getWithIndividualReplacements); } else { packetList.addArmorStandSpawnPackets(armorStandEntityID, locationX, getArmorStandLocationY(), locationZ, displayText.getWithGlobalReplacements()); @@ -79,7 +92,9 @@ public class TextLineTracker extends TouchableLineTracker { super.addChangesPackets(packetList); if (displayTextChanged) { - if (displayText.containsIndividualPlaceholders()) { + if (!allowPlaceholders) { + packetList.addArmorStandNameChangePackets(armorStandEntityID, displayText.get()); + } else if (displayText.containsIndividualPlaceholders()) { packetList.addArmorStandNameChangePackets(armorStandEntityID, displayText::getWithIndividualReplacements); } else { packetList.addArmorStandNameChangePackets(armorStandEntityID, displayText.getWithGlobalReplacements());