diff --git a/src/main/java/wtf/beatrice/hidekobot/Cache.java b/src/main/java/wtf/beatrice/hidekobot/Cache.java index deb170d..07df5be 100644 --- a/src/main/java/wtf/beatrice/hidekobot/Cache.java +++ b/src/main/java/wtf/beatrice/hidekobot/Cache.java @@ -4,6 +4,7 @@ import net.dv8tion.jda.api.interactions.commands.Command; import org.jetbrains.annotations.Nullable; import wtf.beatrice.hidekobot.database.DatabaseManager; import wtf.beatrice.hidekobot.listeners.MessageLogger; +import wtf.beatrice.hidekobot.utils.ConfigurationManager; import java.awt.*; import java.time.LocalDateTime; @@ -14,7 +15,7 @@ import java.util.List; public class Cache { - + private static ConfigurationManager configManager = null; private static DatabaseManager dbManager = null; private static boolean verbose = false; private static MessageLogger verbosityLogger; @@ -235,4 +236,10 @@ public class Cache } public static String getExecPath() { return execPath; } + public static ConfigurationManager getConfigurationManager() + { return configManager; } + + public static void setConfigManager(ConfigurationManager configurationManager) + { configManager = configurationManager; } + } diff --git a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java index 5e66c4d..33768c9 100644 --- a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java +++ b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java @@ -14,7 +14,7 @@ import wtf.beatrice.hidekobot.listeners.SlashCommandListener; import wtf.beatrice.hidekobot.runnables.CommandsUpdateTask; import wtf.beatrice.hidekobot.runnables.ExpiredMessageTask; import wtf.beatrice.hidekobot.runnables.HeartBeatTask; -import wtf.beatrice.hidekobot.utils.ConfigurationUtil; +import wtf.beatrice.hidekobot.utils.ConfigurationManager; import wtf.beatrice.hidekobot.utils.Logger; import wtf.beatrice.hidekobot.utils.SlashCommandUtil; @@ -114,9 +114,9 @@ public class HidekoBot // load configuration String configFilePath = Cache.getExecPath() + File.separator + "config.yml"; - ConfigurationUtil configurationUtil = new ConfigurationUtil(configFilePath); - configurationUtil.initConfig(); - + ConfigurationManager configurationManager = new ConfigurationManager(configFilePath); + configurationManager.initConfig(); + Cache.setConfigManager(configurationManager); // connect to database logger.log("Connecting to database..."); diff --git a/src/main/java/wtf/beatrice/hidekobot/utils/ConfigurationUtil.java b/src/main/java/wtf/beatrice/hidekobot/utils/ConfigurationManager.java similarity index 86% rename from src/main/java/wtf/beatrice/hidekobot/utils/ConfigurationUtil.java rename to src/main/java/wtf/beatrice/hidekobot/utils/ConfigurationManager.java index 4439132..f6153cc 100644 --- a/src/main/java/wtf/beatrice/hidekobot/utils/ConfigurationUtil.java +++ b/src/main/java/wtf/beatrice/hidekobot/utils/ConfigurationManager.java @@ -7,13 +7,15 @@ import wtf.beatrice.hidekobot.HidekoBot; import java.io.*; import java.util.LinkedHashMap; -public class ConfigurationUtil +public class ConfigurationManager { + + private final LinkedHashMap configurationEntries = new LinkedHashMap<>(); private final Logger logger; private final String configFilePath; - public ConfigurationUtil(String configFilePath) + public ConfigurationManager(String configFilePath) { this.configFilePath = configFilePath; logger = new Logger(getClass()); @@ -114,7 +116,21 @@ public class ConfigurationUtil return; } + // finally, dump all entries to cache. + loadConfig(filledEntries); + } else { + // if no key is missing, just cache all entries and values from filesystem. + loadConfig(fsConfigContents); } + } + + private void loadConfig(LinkedHashMap configurationEntries) + { + configurationEntries.putAll(configurationEntries); + } + private Object getConfigValue(String key) + { + return configurationEntries.get(key); } }