@@ -21,6 +21,7 @@ final class LegacyHologram implements Hologram.Legacy {
2121 private float lineOffset = -0.9875f ;
2222 private float markerOffset = -0.40625f ;
2323 private boolean marker ;
24+ private boolean spawned = false ;
2425
2526 LegacyHologram (@ NotNull Location location ) {
2627 this .location = location ;
@@ -40,6 +41,59 @@ public void addViewer(@NotNull UUID viewer) {
4041 }
4142 }
4243
44+ @ Override
45+ public boolean updateLineContent (int index , @ NotNull Component line ) {
46+ if (index < 0 || index >= lines .size ()) {
47+ return false ;
48+ }
49+ ArmorStandMeta meta = (ArmorStandMeta ) lines .get (index ).getEntityMeta ();
50+ meta .setCustomName (line );
51+ return true ;
52+ }
53+
54+ @ Override
55+ public void setLines (List <Component > newLines ) {
56+ int existingCount = lines .size ();
57+ int newCount = newLines .size ();
58+
59+ if (newCount == 0 ) {
60+ for (WrapperEntity line : lines ) {
61+ line .remove ();
62+ }
63+ lines .clear ();
64+ return ;
65+ }
66+
67+ for (int i = 0 ; i < Math .min (existingCount , newCount ); i ++) {
68+ ArmorStandMeta meta = (ArmorStandMeta ) lines .get (i ).getEntityMeta ();
69+ meta .setCustomName (newLines .get (i ));
70+ }
71+
72+ for (int i = existingCount - 1 ; i >= newCount ; i --) {
73+ lines .get (i ).remove ();
74+ lines .remove (i );
75+ }
76+
77+ for (int i = existingCount ; i < newCount ; i ++) {
78+ WrapperEntity e = new WrapperEntity (EntityTypes .ARMOR_STAND );
79+ ArmorStandMeta meta = (ArmorStandMeta ) e .getEntityMeta ();
80+ meta .setCustomName (newLines .get (i ));
81+ meta .setCustomNameVisible (true );
82+ meta .setInvisible (true );
83+ meta .setHasNoGravity (true );
84+ meta .setSmall (true );
85+ meta .setMarker (marker );
86+ if (spawned ) {
87+ e .spawn (location );
88+ }
89+ lines .add (e );
90+ }
91+
92+ if (spawned ) {
93+ teleport (location );
94+ }
95+ }
96+
4397 @ Override
4498 public void removeViewer (@ NotNull UUID viewer ) {
4599 for (WrapperEntity line : lines ) {
@@ -73,13 +127,15 @@ public void show() {
73127 line .spawn (location );
74128 }
75129 teleport (location );
130+ spawned = true ;
76131 }
77132
78133 @ Override
79134 public void hide () {
80135 for (WrapperEntity line : lines ) {
81136 line .despawn ();
82137 }
138+ spawned = false ;
83139 }
84140
85141 @ Override
0 commit comments