diff --git a/common/src/main/java/net/draycia/carbon/common/channels/CarbonChannelRegistry.java b/common/src/main/java/net/draycia/carbon/common/channels/CarbonChannelRegistry.java index 91eb131c..e5ef7c12 100644 --- a/common/src/main/java/net/draycia/carbon/common/channels/CarbonChannelRegistry.java +++ b/common/src/main/java/net/draycia/carbon/common/channels/CarbonChannelRegistry.java @@ -56,7 +56,6 @@ import net.draycia.carbon.common.messages.CarbonMessages; import net.draycia.carbon.common.util.Exceptions; import net.draycia.carbon.common.util.FileUtil; import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.key.InvalidKeyException; import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import org.apache.logging.log4j.Logger; @@ -225,21 +224,10 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann continue; } - final @Nullable ChatChannel chatChannel; - - 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; - } - + final @Nullable ChatChannel chatChannel = this.loadChannel(channelConfigFile); if (chatChannel == null) { continue; } - final Key channelKey = chatChannel.key(); if (this.defaultKey.equals(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 + "]"); } - 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() { try { 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); try { final ConfigurationNode loaded = updateNode(loader.load()); loader.save(loaded); return MAPPER.load(loaded); - } catch (final ConfigurateException configurateException) { - this.logger.warn("Failed to load channel from file '{}'", channelFile); - throw configurateException; + } catch (final ConfigurateException exception) { + this.logger.warn("Failed to load channel from file '{}'", channelFile, exception); } + + return null; } private void sendMessageInChannelAsPlayer( diff --git a/common/src/main/java/net/draycia/carbon/common/channels/ConfigChatChannel.java b/common/src/main/java/net/draycia/carbon/common/channels/ConfigChatChannel.java index 4f14523e..4a3654ff 100644 --- a/common/src/main/java/net/draycia/carbon/common/channels/ConfigChatChannel.java +++ b/common/src/main/java/net/draycia/carbon/common/channels/ConfigChatChannel.java @@ -43,7 +43,6 @@ import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.key.Key; -import net.kyori.adventure.key.KeyPattern; import net.kyori.adventure.text.Component; import net.kyori.moonshine.Moonshine; import net.kyori.moonshine.exception.scan.UnscannableMethodException; @@ -68,21 +67,12 @@ public final class ConfigChatChannel implements ChatChannel { 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(""" The channel's key, used to track the channel. 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 @Nullable Key key = null; + private @Nullable Key key = Key.key("carbon", "global"); @Comment(""" The permission required to use the /channel and / commands. @@ -102,7 +92,6 @@ public final class ConfigChatChannel implements ChatChannel { private @Nullable Boolean shouldRegisterCommands = true; - @Deprecated(since = "2.0", forRemoval = true) private @Nullable String commandName = null; private @Nullable List commandAliases = Collections.emptyList(); @@ -139,7 +128,7 @@ public final class ConfigChatChannel implements ChatChannel { @Override public String commandName() { - return Objects.requireNonNullElse(this.commandName, this.key().value()); + return Objects.requireNonNullElse(this.commandName, this.key.value()); } @Override @@ -172,7 +161,7 @@ public final class ConfigChatChannel implements ChatChannel { @Override 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 @@ -204,11 +193,7 @@ public final class ConfigChatChannel implements ChatChannel { @Override public @NonNull Key key() { - if (this.key != null) { - return this.key; - } - - return Key.key("carbon", this.name); + return Objects.requireNonNull(this.key); } public String messageFormat(final CarbonPlayer sender) {