|
1 | 1 | package net.megavex.scoreboardlibrary.implementation.commons; |
2 | 2 |
|
3 | 3 | import net.kyori.adventure.text.Component; |
| 4 | +import net.kyori.adventure.text.TextComponent; |
4 | 5 | import net.kyori.adventure.text.format.NamedTextColor; |
5 | 6 | import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; |
6 | 7 | import net.kyori.adventure.text.serializer.legacy.LegacyFormat; |
|
14 | 15 | import java.util.Objects; |
15 | 16 |
|
16 | 17 | import static net.kyori.adventure.text.Component.empty; |
| 18 | +import static net.kyori.adventure.text.Component.space; |
17 | 19 | import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection; |
18 | 20 | import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.parseChar; |
19 | 21 |
|
@@ -57,7 +59,24 @@ public static String serialize(@Nullable Component component, @Nullable Locale l |
57 | 59 | translated = component; |
58 | 60 | } |
59 | 61 |
|
60 | | - return legacySection().serialize(translated); |
| 62 | + String legacyFormat = legacySection().serialize(translated); |
| 63 | + |
| 64 | + // Legacy format serializer ignores empty components, so it's impossible to set player color on 1.8 via team prefix |
| 65 | + // Need to manually add the missing legacy format of the last component |
| 66 | + Component lastChild = translated; |
| 67 | + while (!lastChild.children().isEmpty()) { |
| 68 | + lastChild = lastChild.children().get(0); |
| 69 | + } |
| 70 | + |
| 71 | + if (lastChild instanceof TextComponent) { |
| 72 | + String content = ((TextComponent) lastChild).content(); |
| 73 | + if (content.isEmpty()) { |
| 74 | + String ending = legacySection().serialize(lastChild.append(space())); |
| 75 | + legacyFormat += ending.substring(0, ending.length() - 1); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + return legacyFormat; |
61 | 80 | } |
62 | 81 |
|
63 | 82 | public static char getChar(@Nullable NamedTextColor color) { |
|
0 commit comments