mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Extract channel prefix check to CarbonPlayer
This commit is contained in:
1 parent
d452106e0b
commit
76e3b68dfe
4 files changed
+45
No files matched your search
@@ -39,6 +39,8 @@ import net.kyori.adventure.audience.ForwardingAudience;
|
||||
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.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -365,6 +367,34 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelMessage channelForMessage(final Component message) {
|
||||
final String text = PlainTextComponentSerializer.plainText().serialize(message);
|
||||
Component formattedMessage = message;
|
||||
|
||||
@Nullable ChatChannel channel = this.selectedChannel();
|
||||
|
||||
for (final ChatChannel chatChannel : this.carbonChat.channelRegistry()) {
|
||||
final @MonotonicNonNull String prefix = chatChannel.quickPrefix();
|
||||
|
||||
if (prefix == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (text.startsWith(prefix) && chatChannel.speechPermitted(this).permitted()) {
|
||||
channel = chatChannel;
|
||||
formattedMessage = formattedMessage.replaceText(TextReplacementConfig.builder()
|
||||
.once()
|
||||
.matchLiteral(channel.quickPrefix())
|
||||
.replacement(Component.empty())
|
||||
.build());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new ChannelMessage(formattedMessage, channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double distanceSquaredFrom(final CarbonPlayer other) {
|
||||
return -1;
|
||||
|
||||
@@ -149,6 +149,11 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
return this.carbonPlayerCommon().locale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelMessage channelForMessage(final Component message) {
|
||||
return this.carbonPlayerCommon().channelForMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ChatChannel selectedChannel() {
|
||||
return this.carbonPlayerCommon().selectedChannel();
|
||||
|
||||
Reference in new issue
Block a user