Fix channel loading

This commit is contained in:
Draycia committed 2020-09-25 02:23:00 -07:00
1 parent ada690d46c
commit 0a76cad4f7
3 files changed
+30 -26

No files matched your search

@@ -1,13 +1,16 @@
package net.draycia.carbon.api; package net.draycia.carbon.api;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable;
import java.util.List; import java.util.List;
@ConfigSerializable
public class Context { public class Context {
private final @NonNull String key; @Setting private final @NonNull String key;
private final @NonNull Object value; @Setting private final @NonNull Object value;
public Context(final @NonNull String key, final @NonNull Object value) { public Context(final @NonNull String key, final @NonNull Object value) {
this.key = key; this.key = key;
@@ -41,9 +41,10 @@ public class ChannelOptions {
@Setting private String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!"; @Setting private String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
@Setting private String cannotUseMessage = "You cannot use that channel!"; @Setting private String cannotUseMessage = "You cannot use that channel!";
@Setting private String cannotIgnoreMessage = "<red>You cannot ignore that channel!"; @Setting private String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
private final SharedChannelOptions defaultOptions = private SharedChannelOptions defaultOptions() {
CarbonChatProvider.carbonChat().channelSettings().defaultChannelOptions(); return CarbonChatProvider.carbonChat().channelSettings().defaultChannelOptions();
}
public static ChannelOptions defaultChannel() { public static ChannelOptions defaultChannel() {
final ChannelOptions settings = new ChannelOptions(); final ChannelOptions settings = new ChannelOptions();
@@ -63,7 +64,7 @@ public class ChannelOptions {
@Nullable @Nullable
public String color() { public String color() {
if (this.color == null) { if (this.color == null) {
return this.defaultOptions.color(); return this.defaultOptions().color();
} }
return this.color; return this.color;
@@ -74,7 +75,7 @@ public class ChannelOptions {
// TODO: properly implement default context inheritence // TODO: properly implement default context inheritence
// TODO: perhaps add an option to make it so overriding any context overrides all? // TODO: perhaps add an option to make it so overriding any context overrides all?
if (this.contexts == null) { if (this.contexts == null) {
return this.defaultOptions.contexts(); return this.defaultOptions().contexts();
} }
return this.contexts; return this.contexts;
@@ -85,7 +86,7 @@ public class ChannelOptions {
// TODO: properly implement default format inheritence // TODO: properly implement default format inheritence
// TODO: perhaps add an option to make it so overriding any format overrides all? // TODO: perhaps add an option to make it so overriding any format overrides all?
if (this.formats == null) { if (this.formats == null) {
return this.defaultOptions.formats(); return this.defaultOptions().formats();
} }
return this.formats; return this.formats;
@@ -94,7 +95,7 @@ public class ChannelOptions {
@Nullable @Nullable
public String defaultFormatName() { public String defaultFormatName() {
if (this.defaultFormatName == null || this.defaultFormatName.isEmpty()) { if (this.defaultFormatName == null || this.defaultFormatName.isEmpty()) {
return this.defaultOptions.defaultFormatName(); return this.defaultOptions().defaultFormatName();
} }
return this.defaultFormatName; return this.defaultFormatName;
@@ -106,7 +107,7 @@ public class ChannelOptions {
public Boolean ignorable() { public Boolean ignorable() {
if (this.ignorable == null) { if (this.ignorable == null) {
return this.defaultOptions.ignorable(); return this.defaultOptions().ignorable();
} }
return this.ignorable; return this.ignorable;
@@ -114,7 +115,7 @@ public class ChannelOptions {
public Boolean crossServer() { public Boolean crossServer() {
if (this.crossServer == null) { if (this.crossServer == null) {
return this.defaultOptions.crossServer(); return this.defaultOptions().crossServer();
} }
return this.crossServer; return this.crossServer;
@@ -122,7 +123,7 @@ public class ChannelOptions {
public Boolean honorsRecipientList() { public Boolean honorsRecipientList() {
if (this.honorsRecipientList == null) { if (this.honorsRecipientList == null) {
return this.defaultOptions.honorsRecipientList(); return this.defaultOptions().honorsRecipientList();
} }
return this.honorsRecipientList; return this.honorsRecipientList;
@@ -130,7 +131,7 @@ public class ChannelOptions {
public Boolean permissionGroupMatching() { public Boolean permissionGroupMatching() {
if (this.permissionGroupMatching == null) { if (this.permissionGroupMatching == null) {
return this.defaultOptions.permissionGroupMatching(); return this.defaultOptions().permissionGroupMatching();
} }
return this.permissionGroupMatching; return this.permissionGroupMatching;
@@ -139,7 +140,7 @@ public class ChannelOptions {
@NonNull @NonNull
public List<@NonNull String> groupOverrides() { public List<@NonNull String> groupOverrides() {
if (this.groupOverrides == null) { if (this.groupOverrides == null) {
return this.defaultOptions.groupOverrides(); return this.defaultOptions().groupOverrides();
} }
return this.groupOverrides; return this.groupOverrides;
@@ -162,7 +163,7 @@ public class ChannelOptions {
@Nullable @Nullable
public String switchMessage() { public String switchMessage() {
if (this.switchMessage == null) { if (this.switchMessage == null) {
return this.defaultOptions.switchMessage(); return this.defaultOptions().switchMessage();
} }
return this.switchMessage; return this.switchMessage;
@@ -171,7 +172,7 @@ public class ChannelOptions {
@Nullable @Nullable
public String switchOtherMessage() { public String switchOtherMessage() {
if (this.switchOtherMessage == null) { if (this.switchOtherMessage == null) {
return this.defaultOptions.switchOtherMessage(); return this.defaultOptions().switchOtherMessage();
} }
return this.switchOtherMessage; return this.switchOtherMessage;
@@ -180,7 +181,7 @@ public class ChannelOptions {
@Nullable @Nullable
public String switchFailureMessage() { public String switchFailureMessage() {
if (this.switchFailureMessage == null) { if (this.switchFailureMessage == null) {
return this.defaultOptions.switchFailureMessage(); return this.defaultOptions().switchFailureMessage();
} }
return this.switchFailureMessage; return this.switchFailureMessage;
@@ -189,7 +190,7 @@ public class ChannelOptions {
@Nullable @Nullable
public String cannotIgnoreMessage() { public String cannotIgnoreMessage() {
if (this.cannotIgnoreMessage == null) { if (this.cannotIgnoreMessage == null) {
return this.defaultOptions.cannotIgnoreMessage(); return this.defaultOptions().cannotIgnoreMessage();
} }
return this.cannotIgnoreMessage; return this.cannotIgnoreMessage;
@@ -198,7 +199,7 @@ public class ChannelOptions {
@Nullable @Nullable
public String toggleOffMessage() { public String toggleOffMessage() {
if (this.toggleOffMessage == null) { if (this.toggleOffMessage == null) {
return this.defaultOptions.toggleOffMessage(); return this.defaultOptions().toggleOffMessage();
} }
return this.toggleOffMessage; return this.toggleOffMessage;
@@ -207,7 +208,7 @@ public class ChannelOptions {
@Nullable @Nullable
public String toggleOnMessage() { public String toggleOnMessage() {
if (this.toggleOnMessage == null) { if (this.toggleOnMessage == null) {
return this.defaultOptions.toggleOnMessage(); return this.defaultOptions().toggleOnMessage();
} }
return this.toggleOnMessage; return this.toggleOnMessage;
@@ -216,7 +217,7 @@ public class ChannelOptions {
@Nullable @Nullable
public String toggleOtherOnMessage() { public String toggleOtherOnMessage() {
if (this.toggleOtherOnMessage == null) { if (this.toggleOtherOnMessage == null) {
return this.defaultOptions.toggleOtherOnMessage(); return this.defaultOptions().toggleOtherOnMessage();
} }
return this.toggleOtherOnMessage; return this.toggleOtherOnMessage;
@@ -225,7 +226,7 @@ public class ChannelOptions {
@Nullable @Nullable
public String toggleOtherOffMessage() { public String toggleOtherOffMessage() {
if (this.toggleOtherOffMessage == null) { if (this.toggleOtherOffMessage == null) {
return this.defaultOptions.toggleOtherOffMessage(); return this.defaultOptions().toggleOtherOffMessage();
} }
return this.toggleOtherOffMessage; return this.toggleOtherOffMessage;
@@ -234,7 +235,7 @@ public class ChannelOptions {
@Nullable @Nullable
public String cannotUseMessage() { public String cannotUseMessage() {
if (this.cannotUseMessage == null) { if (this.cannotUseMessage == null) {
return this.defaultOptions.cannotUseMessage(); return this.defaultOptions().cannotUseMessage();
} }
return this.cannotUseMessage; return this.cannotUseMessage;
@@ -242,7 +243,7 @@ public class ChannelOptions {
public Boolean primaryGroupOnly() { public Boolean primaryGroupOnly() {
if (this.primaryGroupOnly == null) { if (this.primaryGroupOnly == null) {
return this.defaultOptions.primaryGroupOnly(); return this.defaultOptions().primaryGroupOnly();
} }
return this.primaryGroupOnly; return this.primaryGroupOnly;
@@ -250,7 +251,7 @@ public class ChannelOptions {
public Boolean shouldCancelChatEvent() { public Boolean shouldCancelChatEvent() {
if (this.shouldCancelChatEvent == null) { if (this.shouldCancelChatEvent == null) {
return this.defaultOptions.shouldCancelChatEvent(); return this.defaultOptions().shouldCancelChatEvent();
} }
return this.shouldCancelChatEvent; return this.shouldCancelChatEvent;
@@ -280,7 +280,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
private void loadChannelSettings() { private void loadChannelSettings() {
try { try {
final CommentedConfigurationNode node = final CommentedConfigurationNode node =
this.loadConfigFile("channels.conf", true); this.loadConfigFile("channels.conf", false);
this.channelSettings = ChannelSettings.loadFrom(node); this.channelSettings = ChannelSettings.loadFrom(node);
} catch (final ObjectMappingException exception) { } catch (final ObjectMappingException exception) {