diff --git a/src/main/java/org/lushplugins/chatcolorhandler/ChatColorHandlerSettings.java b/src/main/java/org/lushplugins/chatcolorhandler/ChatColorHandlerSettings.java index cf79f31..fdeadca 100644 --- a/src/main/java/org/lushplugins/chatcolorhandler/ChatColorHandlerSettings.java +++ b/src/main/java/org/lushplugins/chatcolorhandler/ChatColorHandlerSettings.java @@ -72,15 +72,16 @@ public ChatColorHandlerSettings debug(boolean debug) { private void init() { initialised = true; - Parsers.register(LegacyHexParser.INSTANCE, 85); - Parsers.register(LegacySpigotParser.INSTANCE, 84); Parsers.register(HexParser.INSTANCE, 83); + Parsers.register(SpigotParser.INSTANCE, 65); try { Class.forName("net.kyori.adventure.text.minimessage.MiniMessage").getMethod("miniMessage"); messenger(new MiniMessageMessenger()); Parsers.register(MiniMessageResolverParser.INSTANCE, 89); + Parsers.register(LegacyHexParser.INSTANCE, 75); + Parsers.register(LegacySpigotParser.INSTANCE, 74); Parsers.register(MiniMessageColorParser.INSTANCE, 73); Parsers.register(MiniMessageInteractionParser.INSTANCE, 72); Parsers.register(MiniMessagePlaceholderParser.INSTANCE, 71); diff --git a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/LegacySpigotParser.java b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/LegacySpigotParser.java index 7529d19..ce4e74d 100644 --- a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/LegacySpigotParser.java +++ b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/LegacySpigotParser.java @@ -1,6 +1,5 @@ package org.lushplugins.chatcolorhandler.parsers.custom; -import org.bukkit.ChatColor; import org.jetbrains.annotations.NotNull; import org.lushplugins.chatcolorhandler.parsers.Parser; import org.lushplugins.chatcolorhandler.parsers.ParserTypes; @@ -18,7 +17,7 @@ public String getType() { @Override public String parseString(@NotNull String string, @NotNull OutputType outputType) { return switch (outputType) { - case SPIGOT -> ChatColor.translateAlternateColorCodes('&', string); + case SPIGOT -> string; case MINI_MESSAGE -> string // Legacy Ampersand .replace("§", "&") diff --git a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageColorParser.java b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageColorParser.java index 15cbf15..3c4226d 100644 --- a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageColorParser.java +++ b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageColorParser.java @@ -32,8 +32,7 @@ public String parseString(@NotNull String string, @NotNull OutputType outputType return switch (outputType) { case SPIGOT -> { string = string.replace('§', '&'); - yield MiniMessageMessenger.LEGACY_COMPONENT_SERIALIZER.serialize(MiniMessageMessenger.MINI_MESSAGE.deserialize(string, BASIC_COLORS)) - .replace('&', '§'); + yield MiniMessageMessenger.LEGACY_COMPONENT_SERIALIZER.serialize(MiniMessageMessenger.MINI_MESSAGE.deserialize(string, BASIC_COLORS)); } case MINI_MESSAGE -> string; }; diff --git a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageInteractionParser.java b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageInteractionParser.java index eee9032..b89c74f 100644 --- a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageInteractionParser.java +++ b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageInteractionParser.java @@ -29,8 +29,7 @@ public String parseString(@NotNull String string, @NotNull OutputType outputType return switch (outputType) { case SPIGOT -> { string = string.replace('§', '&'); - yield MiniMessageMessenger.LEGACY_COMPONENT_SERIALIZER.serialize(MiniMessageMessenger.MINI_MESSAGE.deserialize(string, INTERACTION)) - .replace('&', '§'); + yield MiniMessageMessenger.LEGACY_COMPONENT_SERIALIZER.serialize(MiniMessageMessenger.MINI_MESSAGE.deserialize(string, INTERACTION)); } case MINI_MESSAGE -> string; }; diff --git a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessagePlaceholderParser.java b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessagePlaceholderParser.java index c3b864b..dd96a5c 100644 --- a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessagePlaceholderParser.java +++ b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessagePlaceholderParser.java @@ -32,8 +32,7 @@ public String parseString(@NotNull String string, @NotNull OutputType outputType return switch (outputType) { case SPIGOT -> { string = string.replace('§', '&'); - yield MiniMessageMessenger.LEGACY_COMPONENT_SERIALIZER.serialize(MiniMessageMessenger.MINI_MESSAGE.deserialize(string, VANILLA_PLACEHOLDERS)) - .replace('&', '§'); + yield MiniMessageMessenger.LEGACY_COMPONENT_SERIALIZER.serialize(MiniMessageMessenger.MINI_MESSAGE.deserialize(string, VANILLA_PLACEHOLDERS)); } case MINI_MESSAGE -> string; }; diff --git a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageResolverParser.java b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageResolverParser.java index 8de8e72..537789a 100644 --- a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageResolverParser.java +++ b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageResolverParser.java @@ -8,6 +8,10 @@ import org.lushplugins.chatcolorhandler.parsers.Parser; import org.lushplugins.chatcolorhandler.parsers.ParserTypes; import org.lushplugins.chatcolorhandler.parsers.Parsers; +import org.lushplugins.chatcolorhandler.parsers.Resolver; + +import java.util.List; +import java.util.Objects; public class MiniMessageResolverParser implements Parser { public static final MiniMessageResolverParser INSTANCE = new MiniMessageResolverParser(); @@ -30,11 +34,17 @@ public String parseString(@NotNull String string, @NotNull OutputType outputType case SPIGOT -> { string = string.replace('§', '&'); - TagResolver resolver = Parsers.getCombinedResolvers(player instanceof Audience audience ? audience : null); - yield MiniMessageMessenger.LEGACY_COMPONENT_SERIALIZER.serialize(MiniMessageMessenger.MINI_MESSAGE.deserialize(string, resolver)) - .replace('&', '§'); + TagResolver resolver = Parsers.getCombinedResolvers(player instanceof Audience audience ? audience : null, getPlaceholderResolvers()); + yield MiniMessageMessenger.LEGACY_COMPONENT_SERIALIZER.serialize(MiniMessageMessenger.MINI_MESSAGE.deserialize(string, resolver)); } case MINI_MESSAGE -> string; }; } + + private static List getPlaceholderResolvers() { + return ParserTypes.placeholder().stream() + .map(parser -> parser instanceof Resolver parserResolver ? parserResolver : null) + .filter(Objects::nonNull) + .toList(); + } } diff --git a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageTextFormattingParser.java b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageTextFormattingParser.java index 8c7ae29..1b4405d 100644 --- a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageTextFormattingParser.java +++ b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/MiniMessageTextFormattingParser.java @@ -28,8 +28,7 @@ public String parseString(@NotNull String string, @NotNull OutputType outputType return switch (outputType) { case SPIGOT -> { string = string.replace('§', '&'); - yield MiniMessageMessenger.LEGACY_COMPONENT_SERIALIZER.serialize(MiniMessageMessenger.MINI_MESSAGE.deserialize(string, TEXT_FORMATTING)) - .replace('&', '§'); + yield MiniMessageMessenger.LEGACY_COMPONENT_SERIALIZER.serialize(MiniMessageMessenger.MINI_MESSAGE.deserialize(string, TEXT_FORMATTING)); } case MINI_MESSAGE -> string; }; diff --git a/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/SpigotParser.java b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/SpigotParser.java new file mode 100644 index 0000000..e4fb4b3 --- /dev/null +++ b/src/main/java/org/lushplugins/chatcolorhandler/parsers/custom/SpigotParser.java @@ -0,0 +1,25 @@ +package org.lushplugins.chatcolorhandler.parsers.custom; + +import org.bukkit.ChatColor; +import org.jetbrains.annotations.NotNull; +import org.lushplugins.chatcolorhandler.parsers.Parser; +import org.lushplugins.chatcolorhandler.parsers.ParserTypes; + +public class SpigotParser implements Parser { + public static final SpigotParser INSTANCE = new SpigotParser(); + + private SpigotParser() {} + + @Override + public String getType() { + return ParserTypes.COLOR; + } + + @Override + public String parseString(@NotNull String string, @NotNull OutputType outputType) { + return switch (outputType) { + case SPIGOT -> ChatColor.translateAlternateColorCodes('&', string); + case MINI_MESSAGE -> string; + }; + } +}