Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentIteratorType;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -65,7 +66,18 @@ protected ChatListenerInternal(
final CarbonPlayer.ChannelMessage channelMessage = sender.channelForMessage(originalMessage);
final ChatChannel channel = channelMessage.channel();

return this.prepareAndEmitChatEvent(sender, channelMessage.message(), signedMessage, channel);
Component message = originalMessage;

final String prefix = channel.quickPrefix();
if (prefix != null) {
message = originalMessage.replaceText(TextReplacementConfig.builder()
.once()
.matchLiteral(prefix)
.replacement(Component.empty())
.build());
}

return this.prepareAndEmitChatEvent(sender, message, signedMessage, channel);
}

protected @Nullable CarbonChatEventImpl prepareAndEmitChatEvent(final CarbonPlayer sender, final Component message, final @Nullable SignedMessage signedMessage, final ChatChannel channel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
Expand Down Expand Up @@ -236,9 +235,6 @@ public UUID uuid() {
@Override
public ChannelMessage channelForMessage(final Component message) {
final String text = PlainTextComponentSerializer.plainText().serialize(message);
Component formattedMessage = message;

ChatChannel channel = requireNonNullElse(this.selectedChannel(), this.carbonPlayerCommon.channelRegistry().defaultChannel());

for (final Key channelKey : this.carbonPlayerCommon.channelRegistry().keys()) {
final ChatChannel chatChannel = this.carbonPlayerCommon.channelRegistry().channelOrThrow(channelKey);
Expand All @@ -249,17 +245,16 @@ public ChannelMessage channelForMessage(final Component message) {
}

if (text.startsWith(prefix) && chatChannel.permissions().speechPermitted(this).permitted()) {
channel = chatChannel;
formattedMessage = formattedMessage.replaceText(TextReplacementConfig.builder()
.once()
.matchLiteral(channel.quickPrefix())
.replacement(Component.empty())
.build());
break;
return new ChannelMessage(message, chatChannel);
}
}

return new ChannelMessage(formattedMessage, channel);
return new ChannelMessage(message,
requireNonNullElse(
this.selectedChannel(),
this.carbonPlayerCommon.channelRegistry().defaultChannel()
)
);
}

@Override
Expand Down
Loading