Prevent default and prefix from being in defaults, fixes #19 & #20

This commit is contained in:
Draycia committed 2020-09-04 01:30:37 -07:00
1 parent 8270d8e98c
commit 4b29191623
1 file changed
+40 -20
@@ -373,7 +373,7 @@ public class CarbonChatChannel extends ChatChannel {
@Override @Override
public Boolean isDefault() { public Boolean isDefault() {
return getBoolean("default"); return getBoolean("default", false);
} }
@Override @Override
@@ -416,11 +416,7 @@ public class CarbonChatChannel extends ChatChannel {
@Override @Override
@Nullable @Nullable
public String getMessagePrefix() { public String getMessagePrefix() {
if (config != null && config.contains("message-prefix")) { return getString("message-prefix", false);
return config.getString("message-prefix");
}
return null;
} }
@Override @Override
@@ -512,62 +508,86 @@ public class CarbonChatChannel extends ChatChannel {
return section.get(key); return section.get(key);
} }
private String getString(String key) { private String getString(String key, boolean includeDefault) {
if (config != null && config.contains(key)) { if (config != null && config.contains(key)) {
return config.getString(key); return config.getString(key);
} }
if (includeDefault) {
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default"); ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
if (defaultSection != null && defaultSection.contains(key)) { if (defaultSection != null && defaultSection.contains(key)) {
return defaultSection.getString(key); return defaultSection.getString(key);
} }
}
return null;
}
private String getString(String key) {
return this.getString(key, true);
}
private List<String> getStringList(String key, boolean includeDefault) {
if (config != null && config.contains(key)) {
return config.getStringList(key);
}
if (includeDefault) {
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
if (defaultSection != null && defaultSection.contains(key)) {
return defaultSection.getStringList(key);
}
}
return null; return null;
} }
private List<String> getStringList(String key) { private List<String> getStringList(String key) {
if (config != null && config.contains(key)) { return this.getStringList(key, true);
return config.getStringList(key);
} }
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default"); private boolean getBoolean(String key, boolean includeDefault) {
if (defaultSection != null && defaultSection.contains(key)) {
return defaultSection.getStringList(key);
}
return Collections.emptyList();
}
private boolean getBoolean(String key) {
if (config != null && config.contains(key)) { if (config != null && config.contains(key)) {
return config.getBoolean(key); return config.getBoolean(key);
} }
if (includeDefault) {
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default"); ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
if (defaultSection != null && defaultSection.contains(key)) { if (defaultSection != null && defaultSection.contains(key)) {
return defaultSection.getBoolean(key); return defaultSection.getBoolean(key);
} }
}
return false; return false;
} }
private double getDouble(String key) { private boolean getBoolean(String key) {
return this.getBoolean(key, true);
}
private double getDouble(String key, boolean includeDefault) {
if (config != null && config.contains(key)) { if (config != null && config.contains(key)) {
return config.getDouble(key); return config.getDouble(key);
} }
if (includeDefault) {
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default"); ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
if (defaultSection != null && defaultSection.contains(key)) { if (defaultSection != null && defaultSection.contains(key)) {
return defaultSection.getDouble(key); return defaultSection.getDouble(key);
} }
}
return 0; return 0;
} }
private double getDouble(String key) {
return this.getDouble(key, true);
}
@Override @Override
public String getKey() { public String getKey() {
return key; return key;