Updates per-sign inverted colors when the main or highlighting color is changed

This commit is contained in:
Kristian Knarvik 2022-01-26 20:30:16 +01:00
parent 02f6c6e9fc
commit 366cd3107e
4 changed files with 40 additions and 17 deletions

View File

@ -15,7 +15,8 @@ can share a network or be split into clusters; they can be hidden on a network o
- **API available** -- using the API, a lot of behavior can be changed - **API available** -- using the API, a lot of behavior can be changed
- **Button customization** -- a large amount of materials usable as buttons (buttons, wall corals, shulkers, chests) - **Button customization** -- a large amount of materials usable as buttons (buttons, wall corals, shulkers, chests)
- **Config commands** -- All main config values can be changed from the commandline - **Config commands** -- All main config values can be changed from the commandline
- **RGB and dye support** -- Signs can use RGB colors as their default colors, and can also be dyed on a per-sign basis - **RGB and dye support** -- Signs can use RGB colors (using hex codes) as their main and highlighting colors, and can
also be dyed on a per-sign basis
## Background ## Background

View File

@ -200,22 +200,29 @@ public class CommandConfig implements CommandExecutor {
if (ConfigTag.requiresFullReload(configOption)) { if (ConfigTag.requiresFullReload(configOption)) {
//Reload everything //Reload everything
Stargate.getStargateConfig().reload(commandSender); Stargate.getStargateConfig().reload(commandSender);
} else if (ConfigTag.requiresPortalReload(configOption)) { } else {
if (ConfigTag.requiresColorReload(configOption)) {
Stargate.getStargateConfig().getStargateGateConfig().loadPerSignColors();
}
if (ConfigTag.requiresPortalReload(configOption)) {
//Just unload and reload the portals //Just unload and reload the portals
Stargate.getStargateConfig().unloadAllPortals(); Stargate.getStargateConfig().unloadAllPortals();
Stargate.getStargateConfig().loadAllPortals(); Stargate.getStargateConfig().loadAllPortals();
} else if (ConfigTag.requiresLanguageReload(configOption)) { }
if (ConfigTag.requiresLanguageReload(configOption)) {
//Reload the language loader //Reload the language loader
Stargate.getStargateConfig().getLanguageLoader().reload(); Stargate.getStargateConfig().getLanguageLoader().reload();
//Re-draw all portal signs //Re-draw all portal signs
for (Portal portal : PortalRegistry.getAllPortals()) { for (Portal portal : PortalRegistry.getAllPortals()) {
portal.drawSign(); portal.drawSign();
} }
} else if (ConfigTag.requiresEconomyReload(configOption)) { }
if (ConfigTag.requiresEconomyReload(configOption)) {
//Load or unload Vault and Economy as necessary //Load or unload Vault and Economy as necessary
Stargate.getStargateConfig().reloadEconomy(); Stargate.getStargateConfig().reloadEconomy();
} }
} }
}
/** /**
* Prints information about a config option and its current value * Prints information about a config option and its current value

View File

@ -31,6 +31,16 @@ public enum ConfigTag {
return Arrays.stream(taggedOptions).anyMatch((item) -> item == option); return Arrays.stream(taggedOptions).anyMatch((item) -> item == option);
} }
/**
* Checks whether a given config option requires a "reload of colors" to take effect
*
* @param configOption <p>The config option to check</p>
* @return <p>True if changing the config option requires a "reload of colors" to take effect</p>
*/
public static boolean requiresColorReload(ConfigOption configOption) {
return COLOR.isTagged(configOption) && configOption != ConfigOption.FREE_GATES_COLOR;
}
/** /**
* Checks whether a given config option requires a full reload to take effect * Checks whether a given config option requires a full reload to take effect
* *

View File

@ -193,7 +193,7 @@ public final class StargateGateConfig {
/** /**
* Loads the per-sign colors specified in the config file * Loads the per-sign colors specified in the config file
*/ */
private void loadPerSignColors() { public void loadPerSignColors() {
List<?> perSignColors = (List<?>) configOptions.get(ConfigOption.PER_SIGN_COLORS); List<?> perSignColors = (List<?>) configOptions.get(ConfigOption.PER_SIGN_COLORS);
ChatColor[] defaultColors = new ChatColor[]{PortalSignDrawer.getMainColor(), PortalSignDrawer.getHighlightColor()}; ChatColor[] defaultColors = new ChatColor[]{PortalSignDrawer.getMainColor(), PortalSignDrawer.getHighlightColor()};
List<Map<Material, ChatColor>> colorMaps = new ArrayList<>(); List<Map<Material, ChatColor>> colorMaps = new ArrayList<>();
@ -279,10 +279,15 @@ public final class StargateGateConfig {
private void loadPerSignColor(String mainSignColor, String highlightSignColor) { private void loadPerSignColor(String mainSignColor, String highlightSignColor) {
try { try {
PortalSignDrawer.setMainColor(ChatColor.of(mainSignColor.toUpperCase())); PortalSignDrawer.setMainColor(ChatColor.of(mainSignColor.toUpperCase()));
} catch (IllegalArgumentException | NullPointerException exception) {
Stargate.logWarning("You have specified an invalid main sign color in your config.yml. Defaulting to BLACK");
PortalSignDrawer.setMainColor(ChatColor.BLACK);
}
try {
PortalSignDrawer.setHighlightColor(ChatColor.of(highlightSignColor.toUpperCase())); PortalSignDrawer.setHighlightColor(ChatColor.of(highlightSignColor.toUpperCase()));
} catch (IllegalArgumentException | NullPointerException exception) { } catch (IllegalArgumentException | NullPointerException exception) {
Stargate.logWarning("You have specified an invalid color in your config.yml. Defaulting to BLACK and WHITE"); Stargate.logWarning("You have specified an invalid highlighting sign color in your config.yml. Defaulting to WHITE");
PortalSignDrawer.setMainColor(ChatColor.BLACK);
PortalSignDrawer.setHighlightColor(ChatColor.WHITE); PortalSignDrawer.setHighlightColor(ChatColor.WHITE);
} }
} }