From 17439240d65b9c66b5d62cdd2cba42d5bada52ac Mon Sep 17 00:00:00 2001 From: Draycia Date: Mon, 13 Dec 2021 20:39:37 -0800 Subject: [PATCH] More verbose channel registration logging --- .../channels/CarbonChannelRegistry.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) 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 127e277f..86887606 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 @@ -36,6 +36,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; +import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Stream; @@ -94,7 +95,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry private final CarbonMessageService messageService; private final CarbonChat carbonChat; - private final BiMap map = Maps.synchronizedBiMap(HashBiMap.create()); + private final BiMap channelMap = Maps.synchronizedBiMap(HashBiMap.create()); @Inject public CarbonChannelRegistry( @@ -178,6 +179,19 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry this.registerChannelCommands(chatChannel, commandManager); } }); + + if (!this.channelMap.containsKey(this.defaultKey)) { + final List channelList = new ArrayList<>(); + + for (final ChatChannel chatChannel : this.channelMap.values()) { + channelList.add(chatChannel.key().asString()); + } + + final String channels = String.join(", ", channelList); + + this.logger.warn("No default channel found! Default channel key: [" + this.defaultKey().asString() + "]"); + this.logger.warn("Registered channels: [" + channels + "]"); + } } catch (final IOException exception) { exception.printStackTrace(); } @@ -245,7 +259,12 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry final Key channelKey = channel.key(); - this.logger.info("Registering channel with key [" + channelKey + "]"); + if (this.defaultKey.equals(channelKey)) { + this.logger.info("Registering default channel with key [" + channelKey + "]"); + } else { + this.logger.info("Registering channel with key [" + channelKey + "]"); + } + this.register(channelKey, channel); return channel; @@ -354,28 +373,28 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry @Override public @NonNull ChatChannel register(final @NonNull Key key, final @NonNull ChatChannel value) { - this.map.put(key, value); + this.channelMap.put(key, value); return value; } @Override public @Nullable ChatChannel get(final @NonNull Key key) { - return this.map.get(key); + return this.channelMap.get(key); } @Override public @Nullable Key key(final @NonNull ChatChannel value) { - return this.map.inverse().get(value); + return this.channelMap.inverse().get(value); } @Override public @NonNull Set keySet() { - return Collections.unmodifiableSet(this.map.keySet()); + return Collections.unmodifiableSet(this.channelMap.keySet()); } @Override public @NonNull Iterator iterator() { - return Iterators.unmodifiableIterator(this.map.values().iterator()); + return Iterators.unmodifiableIterator(this.channelMap.values().iterator()); } }