From 0016b5de30244151c90cfa44d75f47e8a1868744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Tue, 22 Nov 2022 23:42:21 +0100 Subject: [PATCH] Force using config enum class instead of direct entry path --- src/main/java/wtf/beatrice/hidekobot/Cache.java | 9 +++++---- .../hidekobot/datasource/ConfigurationSource.java | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/wtf/beatrice/hidekobot/Cache.java b/src/main/java/wtf/beatrice/hidekobot/Cache.java index 08cd638..490cd4f 100644 --- a/src/main/java/wtf/beatrice/hidekobot/Cache.java +++ b/src/main/java/wtf/beatrice/hidekobot/Cache.java @@ -1,6 +1,7 @@ package wtf.beatrice.hidekobot; import org.jetbrains.annotations.Nullable; +import wtf.beatrice.hidekobot.datasource.ConfigurationEntry; import wtf.beatrice.hidekobot.datasource.ConfigurationSource; import wtf.beatrice.hidekobot.datasource.DatabaseSource; import wtf.beatrice.hidekobot.datasource.PropertiesSource; @@ -97,7 +98,7 @@ public class Cache * @return a long of the account's id */ public static long getBotOwnerId() { - return configurationSource == null ? 0L : (Long) configurationSource.getConfigValue("bot-owner-id"); + return configurationSource == null ? 0L : (Long) configurationSource.getConfigValue(ConfigurationEntry.BOT_OWNER_ID); } @@ -107,7 +108,7 @@ public class Cache * @return a String of the bot's token. */ public static String getBotToken() { - return configurationSource == null ? null : (String) configurationSource.getConfigValue("bot-token"); + return configurationSource == null ? null : (String) configurationSource.getConfigValue(ConfigurationEntry.BOT_TOKEN); } /** @@ -205,7 +206,7 @@ public class Cache public static Color getBotColor() { Color defaultColor = Color.PINK; if(configurationSource == null) return defaultColor; - String colorName = (String) configurationSource.getConfigValue("bot-color"); + String colorName = (String) configurationSource.getConfigValue(ConfigurationEntry.BOT_COLOR); Color color = null; try { @@ -247,7 +248,7 @@ public class Cache public static LocalDateTime getStartupTime() { return startupTime; } public static String getFullHeartBeatLink() { - return configurationSource == null ? null : (String) configurationSource.getConfigValue("heartbeat-link"); + return configurationSource == null ? null : (String) configurationSource.getConfigValue(ConfigurationEntry.HEARTBEAT_LINK); } //todo javadocs public static String getExecPath() { return execPath; } diff --git a/src/main/java/wtf/beatrice/hidekobot/datasource/ConfigurationSource.java b/src/main/java/wtf/beatrice/hidekobot/datasource/ConfigurationSource.java index df3ef17..afaee79 100644 --- a/src/main/java/wtf/beatrice/hidekobot/datasource/ConfigurationSource.java +++ b/src/main/java/wtf/beatrice/hidekobot/datasource/ConfigurationSource.java @@ -133,8 +133,8 @@ public class ConfigurationSource { this.configurationEntries.putAll(configurationEntries); } - public Object getConfigValue(String key) + public Object getConfigValue(ConfigurationEntry key) { - return configurationEntries.get(key); + return configurationEntries.get(key.getPath()); } }