From 421945070545843e031d36f78d575e4747a11513 Mon Sep 17 00:00:00 2001 From: pop4959 Date: Mon, 26 Feb 2024 05:09:02 -0800 Subject: [PATCH] Hotfix legacy serializer to include capitalized formatting code chars (#5711) --- .../essentials/utils/AdventureUtil.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/AdventureUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/AdventureUtil.java index 18bf8aa8d..e3d361803 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/AdventureUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/AdventureUtil.java @@ -4,10 +4,17 @@ import net.ess3.api.IEssentials; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.flattener.ComponentFlattener; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import net.kyori.adventure.text.serializer.legacy.CharacterAndFormat; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.serializer.legacy.Reset; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; public final class AdventureUtil { private static final LegacyComponentSerializer LEGACY_SERIALIZER; @@ -18,7 +25,26 @@ public final class AdventureUtil { private static MiniMessage miniMessageInstance; static { - final LegacyComponentSerializer.Builder builder = LegacyComponentSerializer.builder().flattener(ComponentFlattener.basic()).useUnusualXRepeatedCharacterHexFormat(); + final List formats = new ArrayList<>(); + formats.addAll(CharacterAndFormat.defaults()); + formats.addAll(Arrays.asList( + CharacterAndFormat.characterAndFormat('A', NamedTextColor.GREEN), + CharacterAndFormat.characterAndFormat('B', NamedTextColor.AQUA), + CharacterAndFormat.characterAndFormat('C', NamedTextColor.RED), + CharacterAndFormat.characterAndFormat('D', NamedTextColor.LIGHT_PURPLE), + CharacterAndFormat.characterAndFormat('E', NamedTextColor.YELLOW), + CharacterAndFormat.characterAndFormat('F', NamedTextColor.WHITE), + CharacterAndFormat.characterAndFormat('K', TextDecoration.OBFUSCATED), + CharacterAndFormat.characterAndFormat('L', TextDecoration.BOLD), + CharacterAndFormat.characterAndFormat('M', TextDecoration.STRIKETHROUGH), + CharacterAndFormat.characterAndFormat('N', TextDecoration.UNDERLINED), + CharacterAndFormat.characterAndFormat('O', TextDecoration.ITALIC), + CharacterAndFormat.characterAndFormat('R', Reset.INSTANCE) + )); + final LegacyComponentSerializer.Builder builder = LegacyComponentSerializer.builder() + .flattener(ComponentFlattener.basic()) + .formats(formats) + .useUnusualXRepeatedCharacterHexFormat(); if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_16_1_R01)) { builder.hexColors(); }