Adds the possibility to use the inverted default colors for per-sign colors
Adds code for getting inverted colors if "inverted" is given as the per-sign color Fixes exceptions thrown when the per-sign config value is malformed Changes the default to use inverted colors for crimson, dark_oak, spruce and warped signs Adds methods to get main and highlighting colors from the portal sign drawer in case the given default colors are invalid and fallback colors are necessary instead
This commit is contained in:
parent
2773079a09
commit
97670c9367
@ -51,8 +51,8 @@ public enum ConfigOption {
|
||||
HIGHLIGHT_SIGN_COLOR("gates.cosmetic.highlightSignColor", "The text color used for highlighting stargate signs", "WHITE"),
|
||||
|
||||
PER_SIGN_COLORS("gates.cosmetic.perSignColors", "The per-sign color specification", new String[]{
|
||||
"'ACACIA:default,default'", "'BIRCH:default,default'", "'CRIMSON:WHITE,BLACK'", "'DARK_OAK:WHITE,BLACK'",
|
||||
"'JUNGLE:default,default'", "'OAK:default,default'", "'SPRUCE:WHITE,BLACK'", "'WARPED:WHITE,BLACK'"}),
|
||||
"'ACACIA:default,default'", "'BIRCH:default,default'", "'CRIMSON:inverted,inverted'", "'DARK_OAK:inverted,inverted'",
|
||||
"'JUNGLE:default,default'", "'OAK:default,default'", "'SPRUCE:inverted,inverted'", "'WARPED:inverted,inverted'"}),
|
||||
|
||||
/**
|
||||
* Whether to destroy portals when any blocks are broken by explosions
|
||||
|
@ -2,9 +2,12 @@ package net.knarcraft.stargate.config;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||
import net.knarcraft.stargate.utility.ColorHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -181,27 +184,91 @@ public final class StargateGateConfig {
|
||||
*/
|
||||
private void loadGateConfig() {
|
||||
//Load the sign colors
|
||||
loadSignColor((String) configOptions.get(ConfigOption.MAIN_SIGN_COLOR),
|
||||
(String) configOptions.get(ConfigOption.HIGHLIGHT_SIGN_COLOR));
|
||||
String mainSignColor = (String) configOptions.get(ConfigOption.MAIN_SIGN_COLOR);
|
||||
String highlightSignColor = (String) configOptions.get(ConfigOption.HIGHLIGHT_SIGN_COLOR);
|
||||
loadPerSignColor(mainSignColor, highlightSignColor);
|
||||
loadPerSignColors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the per-sign colors specified in the config file
|
||||
*/
|
||||
private void loadPerSignColors() {
|
||||
List<?> perSignColors = (List<?>) configOptions.get(ConfigOption.PER_SIGN_COLORS);
|
||||
ChatColor[] defaultColors = new ChatColor[]{PortalSignDrawer.getMainColor(), PortalSignDrawer.getHighlightColor()};
|
||||
List<Map<Material, ChatColor>> colorMaps = new ArrayList<>();
|
||||
colorMaps.add(new HashMap<>());
|
||||
colorMaps.add(new HashMap<>());
|
||||
|
||||
Map<Material, ChatColor> signMainColors = new HashMap<>();
|
||||
Map<Material, ChatColor> signHighlightColors = new HashMap<>();
|
||||
for (Object signColorSpecification : perSignColors) {
|
||||
String[] specificationData = String.valueOf(signColorSpecification).split(":");
|
||||
String[] colors = specificationData[1].split(",");
|
||||
if (!colors[0].equalsIgnoreCase("default") && ChatColor.of(colors[0]) != null) {
|
||||
signMainColors.put(Material.matchMaterial(specificationData[0] + "_SIGN"), ChatColor.of(colors[0]));
|
||||
signMainColors.put(Material.matchMaterial(specificationData[0] + "_WALL_SIGN"), ChatColor.of(colors[0]));
|
||||
parsePerSignColors(signColorSpecification, defaultColors, colorMaps);
|
||||
}
|
||||
if (!colors[1].equalsIgnoreCase("default") && ChatColor.of(colors[1]) != null) {
|
||||
signHighlightColors.put(Material.matchMaterial(specificationData[0] + "_SIGN"), ChatColor.of(colors[1]));
|
||||
signHighlightColors.put(Material.matchMaterial(specificationData[0] + "_WALL_SIGN"), ChatColor.of(colors[1]));
|
||||
|
||||
PortalSignDrawer.setPerSignMainColors(colorMaps.get(0));
|
||||
PortalSignDrawer.setPerSignHighlightColors(colorMaps.get(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a per-sign color specification object and stores the result
|
||||
*
|
||||
* @param signColorSpecification <p>The sign color specification to parse</p>
|
||||
* @param defaultColors <p>The specified default colors</p>
|
||||
* @param colorMaps <p>The list of color maps to save the resulting colors to</p>
|
||||
*/
|
||||
private void parsePerSignColors(Object signColorSpecification, ChatColor[] defaultColors,
|
||||
List<Map<Material, ChatColor>> colorMaps) {
|
||||
String[] specificationData = String.valueOf(signColorSpecification).split(":");
|
||||
Material[] signMaterials = new Material[]{Material.matchMaterial(specificationData[0] + "_SIGN"),
|
||||
Material.matchMaterial(specificationData[0] + "_WALL_SIGN")};
|
||||
|
||||
if (specificationData.length != 2) {
|
||||
Stargate.logWarning("You have an invalid per-sign line in your config.yml file. Please fix it!");
|
||||
return;
|
||||
}
|
||||
String[] colors = specificationData[1].split(",");
|
||||
if (colors.length != 2) {
|
||||
Stargate.logWarning("You have an invalid per-sign line in your config.yml file. Please fix it!");
|
||||
return;
|
||||
}
|
||||
for (int colorIndex = 0; colorIndex < 2; colorIndex++) {
|
||||
if (colors[colorIndex].equalsIgnoreCase("default")) {
|
||||
continue;
|
||||
}
|
||||
loadPerSignColor(colors, colorIndex, defaultColors, signMaterials, colorMaps);
|
||||
}
|
||||
}
|
||||
|
||||
PortalSignDrawer.setPerSignMainColors(signMainColors);
|
||||
PortalSignDrawer.setPerSignHighlightColors(signHighlightColors);
|
||||
/**
|
||||
* Loads a per-sign color
|
||||
*
|
||||
* @param colors <p>The colors specified in the config file</p>
|
||||
* @param colorIndex <p>The index of the color to load</p>
|
||||
* @param defaultColors <p>The specified default colors</p>
|
||||
* @param signMaterials <p>The materials to load this color for</p>
|
||||
* @param colorMaps <p>The list of color maps to save the resulting color to</p>
|
||||
*/
|
||||
private void loadPerSignColor(String[] colors, int colorIndex, ChatColor[] defaultColors, Material[] signMaterials,
|
||||
List<Map<Material, ChatColor>> colorMaps) {
|
||||
ChatColor parsedColor;
|
||||
if (colors[colorIndex].equalsIgnoreCase("inverted")) {
|
||||
//Convert from ChatColor to awt.Color to Bukkit.Color then invert and convert to ChatColor
|
||||
java.awt.Color color = defaultColors[colorIndex].getColor();
|
||||
parsedColor = ColorHelper.fromColor(ColorHelper.invert(Color.fromRGB(color.getRed(),
|
||||
color.getGreen(), color.getBlue())));
|
||||
} else {
|
||||
try {
|
||||
parsedColor = ChatColor.of(colors[colorIndex]);
|
||||
} catch (IllegalArgumentException | NullPointerException exception) {
|
||||
Stargate.logWarning("You have specified an invalid per-sign color in your config.yml. Custom color for \"" +
|
||||
signMaterials[0] + "\" disabled");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (parsedColor != null) {
|
||||
for (Material signMaterial : signMaterials) {
|
||||
colorMaps.get(colorIndex).put(signMaterial, parsedColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -209,7 +276,7 @@ public final class StargateGateConfig {
|
||||
*
|
||||
* @param mainSignColor <p>A string representing the main sign color</p>
|
||||
*/
|
||||
private void loadSignColor(String mainSignColor, String highlightSignColor) {
|
||||
private void loadPerSignColor(String mainSignColor, String highlightSignColor) {
|
||||
try {
|
||||
PortalSignDrawer.setMainColor(ChatColor.of(mainSignColor.toUpperCase()));
|
||||
PortalSignDrawer.setHighlightColor(ChatColor.of(highlightSignColor.toUpperCase()));
|
||||
|
@ -85,6 +85,24 @@ public class PortalSignDrawer {
|
||||
PortalSignDrawer.perSignHighlightColors = signHighlightColors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently used main sign color
|
||||
*
|
||||
* @return <p>The currently used main sign color</p>
|
||||
*/
|
||||
public static ChatColor getMainColor() {
|
||||
return mainColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently used highlighting sign color
|
||||
*
|
||||
* @return <p>The currently used highlighting sign color</p>
|
||||
*/
|
||||
public static ChatColor getHighlightColor() {
|
||||
return highlightColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the sign of the portal this sign drawer is responsible for
|
||||
*/
|
||||
|
@ -27,12 +27,12 @@ gates:
|
||||
perSignColors:
|
||||
- 'ACACIA:default,default'
|
||||
- 'BIRCH:default,default'
|
||||
- 'CRIMSON:WHITE,BLACK'
|
||||
- 'DARK_OAK:WHITE,BLACK'
|
||||
- 'CRIMSON:inverted,inverted'
|
||||
- 'DARK_OAK:inverted,inverted'
|
||||
- 'JUNGLE:default,default'
|
||||
- 'OAK:default,default'
|
||||
- 'SPRUCE:WHITE,BLACK'
|
||||
- 'WARPED:WHITE,BLACK'
|
||||
- 'SPRUCE:inverted,inverted'
|
||||
- 'WARPED:inverted,inverted'
|
||||
integrity:
|
||||
# destroyedByExplosion - Whether to destroy gates with explosions (Creeper, TNT, etc.)
|
||||
destroyedByExplosion: false
|
||||
|
Loading…
x
Reference in New Issue
Block a user