Refactored Theme

This commit is contained in:
Rsl1122 2017-12-02 11:25:19 +02:00
parent 7be0acfd70
commit 8a0270ddac
2 changed files with 18 additions and 25 deletions

View File

@ -28,42 +28,33 @@ public class Theme {
public Theme() throws PlanEnableException { public Theme() throws PlanEnableException {
String themeName = Settings.THEME_BASE.toString(); String themeName = Settings.THEME_BASE.toString();
try { try {
config = new ThemeConfig(themeName); config = new ThemeConfig(themeName);
} catch (IOException e) { } 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) { public String getColor(ThemeVal variable) {
String path = color.getThemePath(); String path = variable.getThemePath();
try { try {
String value = config.getString(path); String value = config.getString(path);
String returnValue = "";
if (value.isEmpty()) { if (value.contains(".")) {
return value; return "url(\"" + value + "\")";
} else if (value.contains(".")) {
returnValue += "url(\"" + value + "\")";
} else { } else {
returnValue = value; return value;
} }
if (returnValue.isEmpty()) {
returnValue = color.getDefaultValue();
}
return returnValue;
} catch (Exception | NoSuchFieldError e) { } 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) { public String replaceThemeColors(String resourceString) {
String replaced = resourceString; String replaced = resourceString;
List<ThemeVal> themeVariables = EnumUtility.getSupportedEnumValues(ThemeVal.class, "RED", "PINK", "PURPLE", "DEEP_PURPLE", List<ThemeVal> themeVariables = EnumUtility.getSupportedEnumValues(ThemeVal.class, "RED", "PINK", "PURPLE",
"INDIGO", "BLUE", "LIGHT_BLUE", "CYAN", "TEAL", "GREEN", "LIGHT_GREEN", "LIME", "YELLOW", "AMBER", "DEEP_PURPLE", "INDIGO", "BLUE", "LIGHT_BLUE", "CYAN", "TEAL", "GREEN", "LIGHT_GREEN", "LIME",
"ORANGE", "DEEP_ORANGE", "BROWN", "GREY", "BLUE_GREY", "BLACK", "WHITE", "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_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_CPU", "GRAPH_RAM", "GRAPH_CHUNKS", "GRAPH_ENTITIES", "GRAPH_WORLD_PIE", "GRAPH_GM_PIE",
"GRAPH_ACTIVITY_PIE", "GRAPH_SERVER_PREF_PIE", "FONT_STYLESHEET", "FONT_FAMILY"); "GRAPH_ACTIVITY_PIE", "GRAPH_SERVER_PREF_PIE", "FONT_STYLESHEET", "FONT_FAMILY");
@ -91,8 +82,8 @@ public class Theme {
return config.getString(color.getThemePath()); return config.getString(color.getThemePath());
} }
public static String getValue(ThemeVal color) { public static String getValue(ThemeVal variable) {
return MiscUtils.getIPlan().getTheme().getThemeValue(color); return MiscUtils.getIPlan().getTheme().getThemeValue(variable);
} }
public static String replaceColors(String resourceString) { public static String replaceColors(String resourceString) {

View File

@ -5,6 +5,7 @@
package main.java.com.djrapitops.plan.settings.theme; package main.java.com.djrapitops.plan.settings.theme;
import com.djrapitops.plugin.api.config.Config; 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.api.IPlan;
import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.file.FileUtil; import main.java.com.djrapitops.plan.utilities.file.FileUtil;
@ -36,6 +37,7 @@ public class ThemeConfig extends Config {
try { try {
return FileUtil.lines(plugin, fileLocation); return FileUtil.lines(plugin, fileLocation);
} catch (IOException e) { } catch (IOException e) {
Log.error("Could not find theme " + fileLocation + ". Attempting to use default.");
return FileUtil.lines(plugin, "themes/theme.yml"); return FileUtil.lines(plugin, "themes/theme.yml");
} }
} }
@ -50,15 +52,15 @@ public class ThemeConfig extends Config {
case "harsh": case "harsh":
case "saturated": case "saturated":
case "high": case "high":
return "themes/pastel.yml"; return "themes/pastel.yml";
case "sepia": case "sepia":
case "brown": case "brown":
return "themes/sepia.yml"; return "themes/sepia.yml";
case "grey": case "grey":
case "gray": case "gray":
case "greyscale": case "greyscale":
case "grayscale": case "grayscale":
return "themes/greyscale.yml"; return "themes/greyscale.yml";
default: default:
return "themes/theme.yml"; return "themes/theme.yml";
} }