Skip to content

Commit ef41953

Browse files
Deal with legacy colour codes on construct signs correctly
1 parent bba0fb9 commit ef41953

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/main/java/me/eccentric_nz/TARDIS/builders/exterior/InstantBlockPresetBuilder.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import me.eccentric_nz.tardischunkgenerator.worldgen.TARDISChunkGenerator;
3838
import net.kyori.adventure.text.Component;
3939
import net.kyori.adventure.text.format.NamedTextColor;
40+
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
4041
import org.bukkit.*;
4142
import org.bukkit.block.Block;
4243
import org.bukkit.block.BlockFace;
@@ -335,10 +336,15 @@ public void buildPreset() {
335336
front.line(1, Component.text(line1, sign_colour));
336337
front.line(2, Component.text(line2, sign_colour));
337338
} else {
338-
front.line(0, Component.text(rscs.getLine1()));
339-
front.line(1, Component.text(rscs.getLine2()));
340-
front.line(2, Component.text(rscs.getLine3()));
341-
front.line(3, Component.text(rscs.getLine4()));
339+
// player has set custom text - potentially with colour codes
340+
Component raw1 = LegacyComponentSerializer.legacyAmpersand().deserialize(rscs.getLine1());
341+
Component raw2 = LegacyComponentSerializer.legacyAmpersand().deserialize(rscs.getLine2());
342+
Component raw3 = LegacyComponentSerializer.legacyAmpersand().deserialize(rscs.getLine3());
343+
Component raw4 = LegacyComponentSerializer.legacyAmpersand().deserialize(rscs.getLine4());
344+
front.line(0, raw1);
345+
front.line(1, raw2);
346+
front.line(2, raw3);
347+
front.line(3, raw4);
342348
}
343349
}
344350
}

src/main/java/me/eccentric_nz/TARDIS/builders/exterior/MaterialiseBlockPreset.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import me.eccentric_nz.tardischunkgenerator.worldgen.TARDISChunkGenerator;
4444
import net.kyori.adventure.text.Component;
4545
import net.kyori.adventure.text.format.NamedTextColor;
46+
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
4647
import org.bukkit.*;
4748
import org.bukkit.block.Block;
4849
import org.bukkit.block.BlockFace;
@@ -432,10 +433,15 @@ public void run() {
432433
front.line(1, Component.text(line1, sign_colour));
433434
front.line(2, Component.text(line2, sign_colour));
434435
} else {
435-
front.line(0, Component.text(rscs.getLine1()));
436-
front.line(1, Component.text(rscs.getLine2()));
437-
front.line(2, Component.text(rscs.getLine3()));
438-
front.line(3, Component.text(rscs.getLine4()));
436+
// player has set custom text - potentially with colour codes
437+
Component raw1 = LegacyComponentSerializer.legacyAmpersand().deserialize(rscs.getLine1());
438+
Component raw2 = LegacyComponentSerializer.legacyAmpersand().deserialize(rscs.getLine2());
439+
Component raw3 = LegacyComponentSerializer.legacyAmpersand().deserialize(rscs.getLine3());
440+
Component raw4 = LegacyComponentSerializer.legacyAmpersand().deserialize(rscs.getLine4());
441+
front.line(0, raw1);
442+
front.line(1, raw2);
443+
front.line(2, raw3);
444+
front.line(3, raw4);
439445
}
440446
}
441447
}

src/main/java/me/eccentric_nz/TARDIS/commands/tardis/ConstructCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ public boolean setLine(Player player, String[] args) {
6868
where.put("tardis_id", id);
6969
HashMap<String, Object> set = new HashMap<>();
7070
int l = TARDISNumberParsers.parseInt(args[1]);
71-
Component raw = LegacyComponentSerializer.legacyAmpersand().deserialize(String.join(" ", Arrays.copyOfRange(args, 2, args.length)));
71+
String joined = String.join(" ", Arrays.copyOfRange(args, 2, args.length));
72+
Component raw = LegacyComponentSerializer.legacyAmpersand().deserialize(joined);
7273
// strip color codes and check length
7374
if (ComponentUtils.stripColour(raw).length() > 16) {
7475
plugin.getMessenger().send(player, TardisModule.TARDIS, "CONSTRUCT_LINE_LEN");
7576
return true;
7677
}
77-
set.put("line" + l, raw);
78+
set.put("line" + l, joined);
7879
// save it
7980
plugin.getQueryFactory().doUpdate("chameleon", set, where);
8081
plugin.getMessenger().send(player, TardisModule.TARDIS, "CONSTRUCT_LINE_SAVED");

0 commit comments

Comments
 (0)