From 8a0270ddace7cb0beb4803af7a3101f8e5b747ec Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 2 Dec 2017 11:25:19 +0200 Subject: [PATCH] Refactored Theme --- .../djrapitops/plan/settings/theme/Theme.java | 35 +++++++------------ .../plan/settings/theme/ThemeConfig.java | 8 +++-- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/settings/theme/Theme.java b/Plan/src/main/java/com/djrapitops/plan/settings/theme/Theme.java index d3201cd61..abf7584e8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/settings/theme/Theme.java +++ b/Plan/src/main/java/com/djrapitops/plan/settings/theme/Theme.java @@ -28,42 +28,33 @@ public class Theme { public Theme() throws PlanEnableException { String themeName = Settings.THEME_BASE.toString(); try { - config = new ThemeConfig(themeName); } catch (IOException e) { - throw new PlanEnableException("Theme could not be loaded: " + themeName, e); + throw new PlanEnableException("Default theme could not be loaded.", e); } } - public String getColor(ThemeVal color) { - String path = color.getThemePath(); + public String getColor(ThemeVal variable) { + String path = variable.getThemePath(); try { String value = config.getString(path); - String returnValue = ""; - if (value.isEmpty()) { - return value; - } else if (value.contains(".")) { - returnValue += "url(\"" + value + "\")"; + if (value.contains(".")) { + return "url(\"" + value + "\")"; } else { - returnValue = value; + return value; } - - if (returnValue.isEmpty()) { - returnValue = color.getDefaultValue(); - } - return returnValue; } catch (Exception | NoSuchFieldError e) { - Log.error("Something went wrong with getting color " + color.name() + " for: " + path); + Log.error("Something went wrong with getting variable " + variable.name() + " for: " + path); } - return color.getDefaultValue(); + return variable.getDefaultValue(); } public String replaceThemeColors(String resourceString) { String replaced = resourceString; - List themeVariables = EnumUtility.getSupportedEnumValues(ThemeVal.class, "RED", "PINK", "PURPLE", "DEEP_PURPLE", - "INDIGO", "BLUE", "LIGHT_BLUE", "CYAN", "TEAL", "GREEN", "LIGHT_GREEN", "LIME", "YELLOW", "AMBER", - "ORANGE", "DEEP_ORANGE", "BROWN", "GREY", "BLUE_GREY", "BLACK", "WHITE", + List themeVariables = EnumUtility.getSupportedEnumValues(ThemeVal.class, "RED", "PINK", "PURPLE", + "DEEP_PURPLE", "INDIGO", "BLUE", "LIGHT_BLUE", "CYAN", "TEAL", "GREEN", "LIGHT_GREEN", "LIME", + "YELLOW", "AMBER", "ORANGE", "DEEP_ORANGE", "BROWN", "GREY", "BLUE_GREY", "BLACK", "WHITE", "GRAPH_PUNCHCARD", "GRAPH_PLAYERS_ONLINE", "GRAPH_TPS_HIGH", "GRAPH_TPS_MED", "GRAPH_TPS_LOW", "GRAPH_CPU", "GRAPH_RAM", "GRAPH_CHUNKS", "GRAPH_ENTITIES", "GRAPH_WORLD_PIE", "GRAPH_GM_PIE", "GRAPH_ACTIVITY_PIE", "GRAPH_SERVER_PREF_PIE", "FONT_STYLESHEET", "FONT_FAMILY"); @@ -91,8 +82,8 @@ public class Theme { return config.getString(color.getThemePath()); } - public static String getValue(ThemeVal color) { - return MiscUtils.getIPlan().getTheme().getThemeValue(color); + public static String getValue(ThemeVal variable) { + return MiscUtils.getIPlan().getTheme().getThemeValue(variable); } public static String replaceColors(String resourceString) { diff --git a/Plan/src/main/java/com/djrapitops/plan/settings/theme/ThemeConfig.java b/Plan/src/main/java/com/djrapitops/plan/settings/theme/ThemeConfig.java index 8616ef239..7131fc426 100644 --- a/Plan/src/main/java/com/djrapitops/plan/settings/theme/ThemeConfig.java +++ b/Plan/src/main/java/com/djrapitops/plan/settings/theme/ThemeConfig.java @@ -5,6 +5,7 @@ package main.java.com.djrapitops.plan.settings.theme; import com.djrapitops.plugin.api.config.Config; +import com.djrapitops.plugin.api.utility.log.Log; import main.java.com.djrapitops.plan.api.IPlan; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.file.FileUtil; @@ -36,6 +37,7 @@ public class ThemeConfig extends Config { try { return FileUtil.lines(plugin, fileLocation); } catch (IOException e) { + Log.error("Could not find theme " + fileLocation + ". Attempting to use default."); return FileUtil.lines(plugin, "themes/theme.yml"); } } @@ -50,15 +52,15 @@ public class ThemeConfig extends Config { case "harsh": case "saturated": case "high": - return "themes/pastel.yml"; + return "themes/pastel.yml"; case "sepia": case "brown": - return "themes/sepia.yml"; + return "themes/sepia.yml"; case "grey": case "gray": case "greyscale": case "grayscale": - return "themes/greyscale.yml"; + return "themes/greyscale.yml"; default: return "themes/theme.yml"; }