mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-30 12:02:02 +01:00
Refactored Theme
This commit is contained in:
parent
7be0acfd70
commit
8a0270ddac
@ -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<ThemeVal> 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<ThemeVal> 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) {
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user