Skip to content

Commit

Permalink
Fix messages coloring without permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Brikster committed Sep 16, 2024
1 parent f16aac4 commit b206dfa
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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}";
Expand All @@ -24,9 +29,10 @@ public final class ComponentFromContextConstructorImpl implements ComponentFromC
@Override
public Component construct(MessageContext<Component> 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,
Expand Down

0 comments on commit b206dfa

Please sign in to comment.