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