From b206dfab0865bc87a9af77d6d9d89bf1410f6235 Mon Sep 17 00:00:00 2001 From: Ilya Andreev Date: Mon, 16 Sep 2024 20:01:19 +0300 Subject: [PATCH] Fix messages coloring without permissions --- .../construct/ComponentFromContextConstructorImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spigot/src/main/java/ru/brikster/chatty/chat/construct/ComponentFromContextConstructorImpl.java b/spigot/src/main/java/ru/brikster/chatty/chat/construct/ComponentFromContextConstructorImpl.java index c4415cf..8ab8965 100644 --- a/spigot/src/main/java/ru/brikster/chatty/chat/construct/ComponentFromContextConstructorImpl.java +++ b/spigot/src/main/java/ru/brikster/chatty/chat/construct/ComponentFromContextConstructorImpl.java @@ -1,9 +1,11 @@ package ru.brikster.chatty.chat.construct; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import ru.brikster.chatty.api.chat.message.context.MessageContext; import ru.brikster.chatty.convert.component.ComponentStringConverter; +import ru.brikster.chatty.convert.message.LegacyToMiniMessageConverter; import ru.brikster.chatty.util.AdventureUtil; import javax.inject.Inject; @@ -16,6 +18,9 @@ public final class ComponentFromContextConstructorImpl implements ComponentFromC @Inject private ComponentStringConverter componentStringConverter; + @Inject + private LegacyToMiniMessageConverter legacyToMiniMessageConverter; + private static final Pattern PLAYER_OR_MESSAGE_PLACEHOLDER = Pattern.compile("\\{player}|\\{message}"); private static final String PLAYER_FORMAT_PLACEHOLDER = "{player}"; @@ -24,9 +29,10 @@ public final class ComponentFromContextConstructorImpl implements ComponentFromC @Override public Component construct(MessageContext context) { String messageWithMmFormat = componentStringConverter.componentToString(context.getMessage()); - String formattedMessage = context.getMessageFormat() + String convertedMessageFormat = legacyToMiniMessageConverter.convert(context.getMessageFormat()); + String formattedMessage = convertedMessageFormat .replace("{original-message}", messageWithMmFormat); - Component formattedMessageComponent = componentStringConverter.stringToComponent(formattedMessage); + Component formattedMessageComponent = MiniMessage.miniMessage().deserialize(formattedMessage); return AdventureUtil.replaceWithEndingSpace(context.getFormat(), PLAYER_OR_MESSAGE_PLACEHOLDER,