mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Fix channel prefixes not working
This commit is contained in:
1 parent
068ba26cfc
commit
14b229152e
4 files changed
+45
-45
No files matched your search
@@ -53,7 +53,6 @@ import net.kyori.moonshine.Moonshine;
|
||||
import net.kyori.moonshine.exception.scan.UnscannableMethodException;
|
||||
import net.kyori.moonshine.strategy.StandardPlaceholderResolverStrategy;
|
||||
import net.kyori.moonshine.strategy.supertype.StandardSupertypeThenInterfaceSupertypeStrategy;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -75,7 +74,7 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
You only need to change the second part of the key. "global" by default.
|
||||
The value is what's used in commands, this is probably what you want to change.
|
||||
""")
|
||||
private final @Nullable Key key = Key.key("carbon", "global");
|
||||
private @Nullable Key key = Key.key("carbon", "global");
|
||||
|
||||
@Comment("""
|
||||
The permission required to use the /channel <channelname> and /<channelname> commands.
|
||||
@@ -84,23 +83,20 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
To read messages you must have the permission carbon.channel.global.see
|
||||
To send messages you must have the permission carbon.channel.global.speak
|
||||
""")
|
||||
private final @Nullable String permission = "carbon.channel.global";
|
||||
private @Nullable String permission = null;
|
||||
|
||||
@Setting("format")
|
||||
@Comment("The chat formats for this channel.")
|
||||
private final @Nullable ConfigChannelMessageSource messageSource = new ConfigChannelMessageSource();
|
||||
private @Nullable ConfigChannelMessageSource messageSource = new ConfigChannelMessageSource();
|
||||
|
||||
@Comment("Messages will be sent in this channel if they start with this prefix.")
|
||||
private final @Nullable String quickPrefix = "";
|
||||
private @Nullable String quickPrefix = null;
|
||||
|
||||
private final @Nullable
|
||||
Boolean shouldRegisterCommands = true;
|
||||
private @Nullable Boolean shouldRegisterCommands = true;
|
||||
|
||||
private final @Nullable
|
||||
String commandName = null;
|
||||
private @Nullable String commandName = null;
|
||||
|
||||
private final @Nullable
|
||||
List<String> commandAliases = Collections.emptyList();
|
||||
private @Nullable List<String> commandAliases = Collections.emptyList();
|
||||
|
||||
private transient @Nullable ConfigChannelMessages carbonMessages = null;
|
||||
|
||||
@@ -109,15 +105,13 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
A value of '0' requires that both players are in the same world.
|
||||
On velocity, '0' requires that both players are in the same server.
|
||||
""")
|
||||
private final int radius = -1;
|
||||
private int radius = -1;
|
||||
|
||||
@Comment("""
|
||||
If true, players will be able to see if they're not sending messages to anyone
|
||||
because they're out of range from the radius.
|
||||
""")
|
||||
private final boolean emptyRadiusRecipientsMessage = true;
|
||||
|
||||
private final transient @Nullable ConfigChannelMessages messageService = null;
|
||||
private boolean emptyRadiusRecipientsMessage = true;
|
||||
|
||||
@Override
|
||||
public @Nullable String quickPrefix() {
|
||||
@@ -296,7 +290,11 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @MonotonicNonNull String permission() {
|
||||
public String permission() {
|
||||
if (this.permission == null) {
|
||||
return "carbon.channel." + this.key().value();
|
||||
}
|
||||
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,6 @@ 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;
|
||||
@@ -179,7 +177,7 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String permission) {
|
||||
return false;
|
||||
return this.carbonPlayer().hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -369,30 +367,7 @@ 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);
|
||||
return new ChannelMessage(message, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,14 +23,18 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.InventorySlot;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.util.Tristate;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -151,7 +155,30 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
|
||||
@Override
|
||||
public ChannelMessage channelForMessage(final Component message) {
|
||||
return this.carbonPlayerCommon().channelForMessage(message);
|
||||
final String text = PlainTextComponentSerializer.plainText().serialize(message);
|
||||
Component formattedMessage = message;
|
||||
|
||||
@Nullable ChatChannel channel = this.selectedChannel();
|
||||
|
||||
for (final ChatChannel chatChannel : CarbonChatProvider.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
|
||||
|
||||
Reference in new issue
Block a user