Revert "Add channel 'name' option, don't register channels with invalid keys/names"

This reverts commit 9daac8eff3.
This commit is contained in:
Jason Penilla authored and Jason committed 2023-07-17 11:21:25 -07:00
1 parent 9daac8eff3
commit 8d761519e4
2 files changed
+10 -45

No files matched your search

@@ -56,7 +56,6 @@ import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.util.Exceptions; import net.draycia.carbon.common.util.Exceptions;
import net.draycia.carbon.common.util.FileUtil; import net.draycia.carbon.common.util.FileUtil;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.InvalidKeyException;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@@ -225,21 +224,10 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
continue; continue;
} }
final @Nullable ChatChannel chatChannel; final @Nullable ChatChannel chatChannel = this.loadChannel(channelConfigFile);
try {
chatChannel = this.loadChannel(channelConfigFile);
} catch (final ConfigurateException configurateException) {
if (this.findThrowableRootCause(configurateException) instanceof InvalidKeyException keyException) {
this.logger.error("Invalid channel key found: " + keyException.getMessage());
}
continue;
}
if (chatChannel == null) { if (chatChannel == null) {
continue; continue;
} }
final Key channelKey = chatChannel.key(); final Key channelKey = chatChannel.key();
if (this.defaultKey.equals(channelKey)) { if (this.defaultKey.equals(channelKey)) {
this.logger.info("Default channel is [" + channelKey + "]"); this.logger.info("Default channel is [" + channelKey + "]");
@@ -265,15 +253,6 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
this.logger.info("Registered channels: [" + channels + "]"); this.logger.info("Registered channels: [" + channels + "]");
} }
private Throwable findThrowableRootCause(Throwable throwable) {
Objects.requireNonNull(throwable);
Throwable rootCause = throwable;
while (rootCause.getCause() != null && rootCause.getCause() != rootCause) {
rootCause = rootCause.getCause();
}
return rootCause;
}
private void saveDefaultChannelConfig() { private void saveDefaultChannelConfig() {
try { try {
final Path configFile = this.configChannelDir.resolve("global.conf"); final Path configFile = this.configChannelDir.resolve("global.conf");
@@ -287,17 +266,18 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
} }
} }
private @Nullable ChatChannel loadChannel(final Path channelFile) throws ConfigurateException { private @Nullable ChatChannel loadChannel(final Path channelFile) {
final ConfigurationLoader<?> loader = this.configFactory.configurationLoader(channelFile); final ConfigurationLoader<?> loader = this.configFactory.configurationLoader(channelFile);
try { try {
final ConfigurationNode loaded = updateNode(loader.load()); final ConfigurationNode loaded = updateNode(loader.load());
loader.save(loaded); loader.save(loaded);
return MAPPER.load(loaded); return MAPPER.load(loaded);
} catch (final ConfigurateException configurateException) { } catch (final ConfigurateException exception) {
this.logger.warn("Failed to load channel from file '{}'", channelFile); this.logger.warn("Failed to load channel from file '{}'", channelFile, exception);
throw configurateException;
} }
return null;
} }
private void sendMessageInChannelAsPlayer( private void sendMessageInChannelAsPlayer(
@@ -43,7 +43,6 @@ import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver
import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver; import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.moonshine.Moonshine; import net.kyori.moonshine.Moonshine;
import net.kyori.moonshine.exception.scan.UnscannableMethodException; import net.kyori.moonshine.exception.scan.UnscannableMethodException;
@@ -68,21 +67,12 @@ public final class ConfigChatChannel implements ChatChannel {
private transient @MonotonicNonNull @Inject CarbonChat carbonChat; private transient @MonotonicNonNull @Inject CarbonChat carbonChat;
@Comment("""
The channel's name.
This is also what's used for channel commands.
The 'key' option overrides this.
Must follow the format of [a-z0-9/.-_]
""")
@KeyPattern
private String name = "global";
@Comment(""" @Comment("""
The channel's key, used to track the channel. The channel's key, used to track the channel.
You only need to change the second part of the key. "global" by default. 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. The value is what's used in commands, this is probably what you want to change.
""") """)
private @Nullable Key key = null; private @Nullable Key key = Key.key("carbon", "global");
@Comment(""" @Comment("""
The permission required to use the /channel <channelname> and /<channelname> commands. The permission required to use the /channel <channelname> and /<channelname> commands.
@@ -102,7 +92,6 @@ public final class ConfigChatChannel implements ChatChannel {
private @Nullable Boolean shouldRegisterCommands = true; private @Nullable Boolean shouldRegisterCommands = true;
@Deprecated(since = "2.0", forRemoval = true)
private @Nullable String commandName = null; private @Nullable String commandName = null;
private @Nullable List<String> commandAliases = Collections.emptyList(); private @Nullable List<String> commandAliases = Collections.emptyList();
@@ -139,7 +128,7 @@ public final class ConfigChatChannel implements ChatChannel {
@Override @Override
public String commandName() { public String commandName() {
return Objects.requireNonNullElse(this.commandName, this.key().value()); return Objects.requireNonNullElse(this.commandName, this.key.value());
} }
@Override @Override
@@ -172,7 +161,7 @@ public final class ConfigChatChannel implements ChatChannel {
@Override @Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) { public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return ChannelPermissionResult.allowedIf(empty(), () -> player.hasPermission(this.permission() + ".see") && !player.leftChannels().contains(this.key())); return ChannelPermissionResult.allowedIf(empty(), () -> player.hasPermission(this.permission() + ".see") && !player.leftChannels().contains(this.key));
} }
@Override @Override
@@ -204,11 +193,7 @@ public final class ConfigChatChannel implements ChatChannel {
@Override @Override
public @NonNull Key key() { public @NonNull Key key() {
if (this.key != null) { return Objects.requireNonNull(this.key);
return this.key;
}
return Key.key("carbon", this.name);
} }
public String messageFormat(final CarbonPlayer sender) { public String messageFormat(final CarbonPlayer sender) {