diff --git a/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/ChannelOptions.java b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/ChannelOptions.java index 9fc9c24c..b4b3dee9 100644 --- a/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/ChannelOptions.java +++ b/CarbonChat-API/src/main/java/net/draycia/carbon/api/config/ChannelOptions.java @@ -70,10 +70,29 @@ public class ChannelOptions { return this.color; } + @Nullable + public Context context(final @NonNull String key) { + final Context localContext; + + if (this.contexts != null) { + localContext = this.contexts.get(key); + } else { + localContext = null; + } + + if (localContext == null) { + if (this.defaultOptions().contexts() != null) { + return this.defaultOptions().contexts().get(key); + } else { + return null; + } + } + + return localContext; + } + @Nullable public Map contexts() { - // TODO: properly implement default context inheritence - // TODO: perhaps add an option to make it so overriding any context overrides all? if (this.contexts == null) { return this.defaultOptions().contexts(); } @@ -82,18 +101,40 @@ public class ChannelOptions { } @Nullable - public String format(final String key) { - if (this.formats == null) { - return this.defaultOptions().formats().get(key); + public Map contextsAndDefault() { + if (this.contexts == null) { + return this.defaultOptions().contexts(); } - final String format = this.formats.get(key); - - if (format != null) { - return format; + if (this.defaultOptions().contexts() == null) { + return this.contexts; } - return this.defaultOptions().formats().get(key); + final Map contexts = new HashMap<>(this.defaultOptions().contexts()); + contexts.putAll(this.contexts); + + return contexts; + } + + @Nullable + public String format(final @NonNull String key) { + final String localFormat; + + if (this.formats() != null) { + localFormat = this.formats().get(key); + } else { + localFormat = null; + } + + if (localFormat == null) { + if (this.defaultOptions().formats() != null) { + return this.defaultOptions().formats().get(key); + } else { + return null; + } + } + + return localFormat; } @Nullable @@ -105,6 +146,22 @@ public class ChannelOptions { return this.formats; } + @Nullable + public Map formatsAndDefault() { + if (this.formats == null) { + return this.defaultOptions().formats(); + } + + if (this.defaultOptions().formats() == null) { + return this.formats; + } + + final Map formats = new HashMap<>(this.defaultOptions().formats()); + formats.putAll(this.formats); + + return formats; + } + @Nullable public String defaultFormatName() { if (this.defaultFormatName == null || this.defaultFormatName.isEmpty()) { diff --git a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/channels/CarbonChatChannel.java b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/channels/CarbonChatChannel.java index 266bd20b..9657310e 100644 --- a/CarbonChat-Common/src/main/java/net/draycia/carbon/common/channels/CarbonChatChannel.java +++ b/CarbonChat-Common/src/main/java/net/draycia/carbon/common/channels/CarbonChatChannel.java @@ -515,7 +515,7 @@ public class CarbonChatChannel implements ChatChannel { @Override @Nullable public Context context(final @NonNull String key) { - return this.options().contexts().get(key); + return this.options().context(key); } @Override