mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Add channel defaults handling
This commit is contained in:
1 parent
6c9810ea72
commit
50e359a51f
4 files changed
+137
-49
No files matched your search
@@ -108,7 +108,7 @@ public class CarbonSettings {
|
||||
return this.showTips;
|
||||
}
|
||||
|
||||
public @NonNull List<@NonNull ChannelOptions> channelSettings() {
|
||||
public @NonNull List<@NonNull ChannelOptions> channelOptions() {
|
||||
return this.channelSettings;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.Context;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -20,17 +21,17 @@ public class ChannelOptions {
|
||||
@Setting private Map<String, Context> contexts = new HashMap<>(); // TODO: set defaults
|
||||
@Setting private Map<String, String> formats = new HashMap<>(); // TODO: set defaults
|
||||
@Setting private String defaultFormatName = "default";
|
||||
@Setting private boolean isDefault = false;
|
||||
@Setting private boolean ignorable = true;
|
||||
@Setting private boolean crossServer = true;
|
||||
@Setting private boolean honorsRecipientList = false;
|
||||
@Setting private boolean permissionGroupMatching = false;
|
||||
@Setting private boolean isDefault = false; // primitive because missing = false
|
||||
@Setting private Boolean ignorable = true; // boxed because missing = use defaults
|
||||
@Setting private Boolean crossServer = true;
|
||||
@Setting private Boolean honorsRecipientList = false;
|
||||
@Setting private Boolean permissionGroupMatching = false;
|
||||
@Setting private List<String> groupOverrides = new ArrayList<>();
|
||||
@Setting private String name = "";
|
||||
@Setting private String messagePrefix = "";
|
||||
@Setting private List<String> aliases = new ArrayList<>();
|
||||
@Setting private boolean shouldCancelChatEvent = false;
|
||||
@Setting private boolean primaryGroupOnly = false;
|
||||
@Setting private Boolean shouldCancelChatEvent = false;
|
||||
@Setting private Boolean primaryGroupOnly = false;
|
||||
@Setting private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
|
||||
@Setting private String switchOtherMessage = "<gray><player> <reset><gray>is now in <color><channel> <gray>chat!";
|
||||
@Setting private String switchFailureMessage = "<red>You cannot use channel <channel>!";
|
||||
@@ -41,6 +42,9 @@ public class ChannelOptions {
|
||||
@Setting private String cannotUseMessage = "You cannot use that channel!";
|
||||
@Setting private String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
|
||||
|
||||
private final SharedChannelOptions defaultOptions =
|
||||
CarbonChatProvider.carbonChat().channelSettings().defaultChannelOptions();
|
||||
|
||||
public static ChannelOptions defaultChannel() {
|
||||
final ChannelOptions settings = new ChannelOptions();
|
||||
settings.key = "global";
|
||||
@@ -58,21 +62,41 @@ public class ChannelOptions {
|
||||
|
||||
@Nullable
|
||||
public String color() {
|
||||
if (this.color == null) {
|
||||
return this.defaultOptions.color();
|
||||
}
|
||||
|
||||
return this.color;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Map<String, Context> 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();
|
||||
}
|
||||
|
||||
return this.contexts;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Map<String, String> formats() {
|
||||
// TODO: properly implement default format inheritence
|
||||
// TODO: perhaps add an option to make it so overriding any format overrides all?
|
||||
if (this.formats == null) {
|
||||
return this.defaultOptions.formats();
|
||||
}
|
||||
|
||||
return this.formats;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String defaultFormatName() {
|
||||
if (this.defaultFormatName == null || this.defaultFormatName.isEmpty()) {
|
||||
return this.defaultOptions.defaultFormatName();
|
||||
}
|
||||
|
||||
return this.defaultFormatName;
|
||||
}
|
||||
|
||||
@@ -80,24 +104,44 @@ public class ChannelOptions {
|
||||
return this.isDefault;
|
||||
}
|
||||
|
||||
public boolean ignorable() {
|
||||
public Boolean ignorable() {
|
||||
if (this.ignorable == null) {
|
||||
return this.defaultOptions.ignorable();
|
||||
}
|
||||
|
||||
return this.ignorable;
|
||||
}
|
||||
|
||||
public boolean crossServer() {
|
||||
public Boolean crossServer() {
|
||||
if (this.crossServer == null) {
|
||||
return this.defaultOptions.crossServer();
|
||||
}
|
||||
|
||||
return this.crossServer;
|
||||
}
|
||||
|
||||
public boolean honorsRecipientList() {
|
||||
public Boolean honorsRecipientList() {
|
||||
if (this.honorsRecipientList == null) {
|
||||
return this.defaultOptions.honorsRecipientList();
|
||||
}
|
||||
|
||||
return this.honorsRecipientList;
|
||||
}
|
||||
|
||||
public boolean permissionGroupMatching() {
|
||||
public Boolean permissionGroupMatching() {
|
||||
if (this.permissionGroupMatching == null) {
|
||||
return this.defaultOptions.permissionGroupMatching();
|
||||
}
|
||||
|
||||
return this.permissionGroupMatching;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<@NonNull String> groupOverrides() {
|
||||
if (this.groupOverrides == null) {
|
||||
return this.defaultOptions.groupOverrides();
|
||||
}
|
||||
|
||||
return this.groupOverrides;
|
||||
}
|
||||
|
||||
@@ -117,54 +161,98 @@ public class ChannelOptions {
|
||||
|
||||
@Nullable
|
||||
public String switchMessage() {
|
||||
if (this.switchMessage == null) {
|
||||
return this.defaultOptions.switchMessage();
|
||||
}
|
||||
|
||||
return this.switchMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String switchOtherMessage() {
|
||||
if (this.switchOtherMessage == null) {
|
||||
return this.defaultOptions.switchOtherMessage();
|
||||
}
|
||||
|
||||
return this.switchOtherMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String switchFailureMessage() {
|
||||
if (this.switchFailureMessage == null) {
|
||||
return this.defaultOptions.switchFailureMessage();
|
||||
}
|
||||
|
||||
return this.switchFailureMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String cannotIgnoreMessage() {
|
||||
if (this.cannotIgnoreMessage == null) {
|
||||
return this.defaultOptions.cannotIgnoreMessage();
|
||||
}
|
||||
|
||||
return this.cannotIgnoreMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOffMessage() {
|
||||
if (this.toggleOffMessage == null) {
|
||||
return this.defaultOptions.toggleOffMessage();
|
||||
}
|
||||
|
||||
return this.toggleOffMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOnMessage() {
|
||||
if (this.toggleOnMessage == null) {
|
||||
return this.defaultOptions.toggleOnMessage();
|
||||
}
|
||||
|
||||
return this.toggleOnMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOtherOnMessage() {
|
||||
if (this.toggleOtherOnMessage == null) {
|
||||
return this.defaultOptions.toggleOtherOnMessage();
|
||||
}
|
||||
|
||||
return this.toggleOtherOnMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOtherOffMessage() {
|
||||
if (this.toggleOtherOffMessage == null) {
|
||||
return this.defaultOptions.toggleOtherOffMessage();
|
||||
}
|
||||
|
||||
return this.toggleOtherOffMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String cannotUseMessage() {
|
||||
if (this.cannotUseMessage == null) {
|
||||
return this.defaultOptions.cannotUseMessage();
|
||||
}
|
||||
|
||||
return this.cannotUseMessage;
|
||||
}
|
||||
|
||||
public boolean primaryGroupOnly() {
|
||||
public Boolean primaryGroupOnly() {
|
||||
if (this.primaryGroupOnly == null) {
|
||||
return this.defaultOptions.primaryGroupOnly();
|
||||
}
|
||||
|
||||
return this.primaryGroupOnly;
|
||||
}
|
||||
|
||||
public boolean shouldCancelChatEvent() {
|
||||
public Boolean shouldCancelChatEvent() {
|
||||
if (this.shouldCancelChatEvent == null) {
|
||||
return this.defaultOptions.shouldCancelChatEvent();
|
||||
}
|
||||
|
||||
return this.shouldCancelChatEvent;
|
||||
}
|
||||
|
||||
|
||||
+31
-31
@@ -1,7 +1,7 @@
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.config.ChannelSettings;
|
||||
import net.draycia.carbon.api.config.ChannelOptions;
|
||||
import net.draycia.carbon.common.utils.ColorUtils;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
@@ -33,15 +33,15 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@NonNull
|
||||
private final ChannelSettings settings;
|
||||
private final ChannelOptions options;
|
||||
|
||||
public CarbonChatChannel(final @NonNull CarbonChat carbonChat, @Nullable final ChannelSettings settings) {
|
||||
public CarbonChatChannel(final @NonNull CarbonChat carbonChat, @Nullable final ChannelOptions options) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.settings = settings;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
public @NonNull ChannelSettings settings() {
|
||||
return this.settings;
|
||||
public @NonNull ChannelOptions options() {
|
||||
return this.options;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -271,7 +271,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
@Override
|
||||
@Nullable
|
||||
public String format(final @NonNull String group) {
|
||||
return this.settings().formats().get("formats." + group);
|
||||
return this.options().formats().get("formats." + group);
|
||||
}
|
||||
|
||||
private boolean isUserSpying(final @NonNull ChatUser sender, final @NonNull ChatUser target) {
|
||||
@@ -339,7 +339,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
return userColor;
|
||||
}
|
||||
|
||||
final String input = this.settings().color();
|
||||
final String input = this.options().color();
|
||||
|
||||
final TextColor color = ColorUtils.parseColor(user, input);
|
||||
|
||||
@@ -357,114 +357,114 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
|
||||
@Nullable
|
||||
public String defaultFormatName() {
|
||||
return this.settings().defaultFormatName();
|
||||
return this.options().defaultFormatName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault() {
|
||||
return this.settings().isDefault();
|
||||
return this.options().isDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignorable() {
|
||||
return this.settings().ignorable();
|
||||
return this.options().ignorable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean crossServer() {
|
||||
return this.settings().crossServer();
|
||||
return this.options().crossServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean honorsRecipientList() {
|
||||
return this.settings().honorsRecipientList();
|
||||
return this.options().honorsRecipientList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean permissionGroupMatching() {
|
||||
return this.settings().permissionGroupMatching();
|
||||
return this.options().permissionGroupMatching();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public List<@NonNull String> groupOverrides() {
|
||||
return this.settings().groupOverrides();
|
||||
return this.options().groupOverrides();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String name() {
|
||||
return this.settings().name();
|
||||
return this.options().name();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String messagePrefix() {
|
||||
return this.settings().messagePrefix();
|
||||
return this.options().messagePrefix();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String switchMessage() {
|
||||
return this.settings().switchMessage();
|
||||
return this.options().switchMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String switchOtherMessage() {
|
||||
return this.settings().switchOtherMessage();
|
||||
return this.options().switchOtherMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String switchFailureMessage() {
|
||||
return this.settings().switchFailureMessage();
|
||||
return this.options().switchFailureMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String cannotIgnoreMessage() {
|
||||
return this.settings().cannotIgnoreMessage();
|
||||
return this.options().cannotIgnoreMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String toggleOffMessage() {
|
||||
return this.settings().toggleOffMessage();
|
||||
return this.options().toggleOffMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String toggleOnMessage() {
|
||||
return this.settings().toggleOnMessage();
|
||||
return this.options().toggleOnMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String toggleOtherOnMessage() {
|
||||
return this.settings().toggleOtherOnMessage();
|
||||
return this.options().toggleOtherOnMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String toggleOtherOffMessage() {
|
||||
return this.settings().toggleOtherOffMessage();
|
||||
return this.options().toggleOtherOffMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String cannotUseMessage() {
|
||||
return this.settings().cannotUseMessage();
|
||||
return this.options().cannotUseMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean primaryGroupOnly() {
|
||||
return this.settings().primaryGroupOnly();
|
||||
return this.options().primaryGroupOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCancelChatEvent() {
|
||||
return this.settings().shouldCancelChatEvent();
|
||||
return this.options().shouldCancelChatEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -476,19 +476,19 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
@Override
|
||||
@Nullable
|
||||
public List<String> aliases() {
|
||||
return this.settings().aliases();
|
||||
return this.options().aliases();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Context context(final @NonNull String key) {
|
||||
return this.settings().contexts().get(key);
|
||||
return this.options().contexts().get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String key() {
|
||||
return this.settings().key();
|
||||
return this.options().key();
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.config.ChannelSettings;
|
||||
import net.draycia.carbon.api.config.ChannelOptions;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
@@ -32,7 +32,7 @@ public class ChannelManager {
|
||||
this.reload();
|
||||
}
|
||||
|
||||
public @Nullable ChatChannel loadChannel(final @NonNull ChannelSettings settings) {
|
||||
public @Nullable ChatChannel loadChannel(final @NonNull ChannelOptions settings) {
|
||||
final ChatChannel channel = new CarbonChatChannel(this.carbonChat, settings);
|
||||
|
||||
final String name = settings.name();
|
||||
@@ -84,8 +84,8 @@ public class ChannelManager {
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
for (final ChannelSettings settings : this.carbonChat.carbonSettings().channelSettings()) {
|
||||
final ChatChannel channel = this.loadChannel(settings);
|
||||
for (final ChannelOptions options : this.carbonChat.carbonSettings().channelOptions()) {
|
||||
final ChatChannel channel = this.loadChannel(options);
|
||||
|
||||
if (channel != null) {
|
||||
this.registerChannel(channel);
|
||||
|
||||
Reference in new issue
Block a user