From ab102be69d5dea7b2c0a920a51ff0e6e3a40f255 Mon Sep 17 00:00:00 2001 From: Draycia Date: Fri, 4 Sep 2020 03:44:48 -0700 Subject: [PATCH] Prevent default and prefix from being in defaults --- .../channels/impls/CarbonChatChannel.java | 82 ++++++++----------- 1 file changed, 33 insertions(+), 49 deletions(-) diff --git a/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java b/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java index 32b5524a..1d434251 100644 --- a/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java +++ b/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java @@ -373,7 +373,11 @@ public class CarbonChatChannel extends ChatChannel { @Override public Boolean isDefault() { - return getBoolean("default", false); + if (config != null && config.contains("default")) { + return config.getBoolean("default"); + } + + return false; } @Override @@ -416,7 +420,11 @@ public class CarbonChatChannel extends ChatChannel { @Override @Nullable public String getMessagePrefix() { - return getString("message-prefix", false); + if (config != null && config.contains("message-prefix")) { + return config.getString("message-prefix"); + } + + return null; } @Override @@ -508,86 +516,62 @@ public class CarbonChatChannel extends ChatChannel { return section.get(key); } - private String getString(String key, boolean includeDefault) { + private String getString(String key) { if (config != null && config.contains(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)) { - return defaultSection.getString(key); - } - } - - return null; - } - - private String getString(String key) { - return this.getString(key, true); - } - - private List 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); - } + if (defaultSection != null && defaultSection.contains(key)) { + return defaultSection.getString(key); } return null; } private List getStringList(String key) { - return this.getStringList(key, true); + if (config != null && config.contains(key)) { + return config.getStringList(key); + } + + ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default"); + + if (defaultSection != null && defaultSection.contains(key)) { + return defaultSection.getStringList(key); + } + + return Collections.emptyList(); } - private boolean getBoolean(String key, boolean includeDefault) { + private boolean getBoolean(String key) { if (config != null && config.contains(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)) { - return defaultSection.getBoolean(key); - } + if (defaultSection != null && defaultSection.contains(key)) { + return defaultSection.getBoolean(key); } return false; } - private boolean getBoolean(String key) { - return this.getBoolean(key, true); - } - - private double getDouble(String key, boolean includeDefault) { + private double getDouble(String key) { if (config != null && config.contains(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)) { - return defaultSection.getDouble(key); - } + if (defaultSection != null && defaultSection.contains(key)) { + return defaultSection.getDouble(key); } return 0; } - private double getDouble(String key) { - return this.getDouble(key, true); - } - @Override public String getKey() { return key;