Makes a lot of changes necessary for RGB and per-sign color configuration support
This commit is contained in:
parent
acbdcd3ce3
commit
2bb0e8670d
@ -1,7 +1,7 @@
|
||||
package net.knarcraft.stargate.command;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import org.bukkit.ChatColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -6,7 +6,7 @@ import net.knarcraft.stargate.config.ConfigTag;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||
import org.bukkit.ChatColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -61,7 +61,7 @@ public class CommandConfig implements CommandExecutor {
|
||||
//Validate any sign colors
|
||||
if (ConfigTag.COLOR.isTagged(selectedOption)) {
|
||||
try {
|
||||
ChatColor.valueOf(value.toUpperCase());
|
||||
ChatColor.of(value.toUpperCase());
|
||||
} catch (IllegalArgumentException | NullPointerException ignored) {
|
||||
commandSender.sendMessage(ChatColor.RED + "Invalid color given");
|
||||
return;
|
||||
@ -153,7 +153,7 @@ public class CommandConfig implements CommandExecutor {
|
||||
*/
|
||||
private ChatColor parseColor(String value) {
|
||||
try {
|
||||
return ChatColor.valueOf(value.toUpperCase());
|
||||
return ChatColor.of(value.toUpperCase());
|
||||
} catch (IllegalArgumentException | NullPointerException ignored) {
|
||||
return null;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.knarcraft.stargate.command;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -2,7 +2,7 @@ package net.knarcraft.stargate.command;
|
||||
|
||||
import net.knarcraft.stargate.config.ConfigOption;
|
||||
import net.knarcraft.stargate.config.OptionDataType;
|
||||
import org.bukkit.ChatColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@ -137,7 +137,7 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
private List<String> getColors() {
|
||||
List<String> colors = new ArrayList<>();
|
||||
for (ChatColor color : getChatColors()) {
|
||||
colors.add(color.name());
|
||||
colors.add(color.getName());
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
@ -50,6 +50,10 @@ 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:default,default", "DARK_OAK:default,default",
|
||||
"JUNGLE:default,default", "OAK:default,default", "SPRUCE:default,default", "WARPED:default,default"}),
|
||||
|
||||
/**
|
||||
* Whether to destroy portals when any blocks are broken by explosions
|
||||
*/
|
||||
@ -172,7 +176,9 @@ public enum ConfigOption {
|
||||
this.description = description;
|
||||
this.defaultValue = defaultValue;
|
||||
|
||||
if (defaultValue instanceof String) {
|
||||
if (defaultValue instanceof String[]) {
|
||||
this.dataType = OptionDataType.STRING_LIST;
|
||||
} else if (defaultValue instanceof String) {
|
||||
this.dataType = OptionDataType.STRING;
|
||||
} else if (defaultValue instanceof Boolean) {
|
||||
this.dataType = OptionDataType.BOOLEAN;
|
||||
|
@ -4,8 +4,8 @@ import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -33,7 +33,7 @@ public final class EconomyConfig {
|
||||
this.configOptions = configOptions;
|
||||
try {
|
||||
String freeColor = (String) configOptions.get(ConfigOption.FREE_GATES_COLOR);
|
||||
PortalSignDrawer.setFreeColor(ChatColor.valueOf(freeColor.toUpperCase()));
|
||||
PortalSignDrawer.setFreeColor(ChatColor.of(freeColor.toUpperCase()));
|
||||
} catch (IllegalArgumentException | NullPointerException ignored) {
|
||||
PortalSignDrawer.setFreeColor(ChatColor.DARK_GREEN);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,7 @@ public enum OptionDataType {
|
||||
* The data type for the option is a Boolean
|
||||
*/
|
||||
BOOLEAN,
|
||||
STRING_LIST,
|
||||
/**
|
||||
* The data type for the option is an Integer
|
||||
*/
|
||||
|
@ -2,8 +2,10 @@ package net.knarcraft.stargate.config;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||
import org.bukkit.ChatColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -180,6 +182,25 @@ public final class StargateGateConfig {
|
||||
//Load the sign colors
|
||||
loadSignColor((String) configOptions.get(ConfigOption.MAIN_SIGN_COLOR),
|
||||
(String) configOptions.get(ConfigOption.HIGHLIGHT_SIGN_COLOR));
|
||||
String[] perSignColors = (String[]) configOptions.get(ConfigOption.PER_SIGN_COLORS);
|
||||
|
||||
Map<Material, ChatColor> signMainColors = new HashMap<>();
|
||||
Map<Material, ChatColor> signHighlightColors = new HashMap<>();
|
||||
for (String signColorSpecification : perSignColors) {
|
||||
String[] specificationData = signColorSpecification.split(":");
|
||||
String[] colors = specificationData[1].split(",");
|
||||
if (!colors[0].equalsIgnoreCase("default")) {
|
||||
signMainColors.put(Material.matchMaterial(specificationData[0] + "_SIGN"), ChatColor.of(colors[0]));
|
||||
signMainColors.put(Material.matchMaterial(specificationData[0] + "_WALL_SIGN"), ChatColor.of(colors[0]));
|
||||
}
|
||||
if (!colors[1].equalsIgnoreCase("default")) {
|
||||
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(signMainColors);
|
||||
PortalSignDrawer.setPerSignHighlightColors(signHighlightColors);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,8 +210,8 @@ public final class StargateGateConfig {
|
||||
*/
|
||||
private void loadSignColor(String mainSignColor, String highlightSignColor) {
|
||||
try {
|
||||
PortalSignDrawer.setMainColor(ChatColor.valueOf(mainSignColor.toUpperCase()));
|
||||
PortalSignDrawer.setHighlightColor(ChatColor.valueOf(highlightSignColor.toUpperCase()));
|
||||
PortalSignDrawer.setMainColor(ChatColor.of(mainSignColor.toUpperCase()));
|
||||
PortalSignDrawer.setHighlightColor(ChatColor.of(highlightSignColor.toUpperCase()));
|
||||
} catch (IllegalArgumentException | NullPointerException exception) {
|
||||
Stargate.logWarning("You have specified an invalid color in your config.yml. Defaulting to BLACK and WHITE");
|
||||
PortalSignDrawer.setMainColor(ChatColor.BLACK);
|
||||
|
@ -14,7 +14,7 @@ import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.UUIDMigrationHelper;
|
||||
import net.knarcraft.stargate.utility.UpdateChecker;
|
||||
import org.bukkit.ChatColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
|
@ -8,7 +8,7 @@ import net.knarcraft.stargate.portal.property.PortalOptions;
|
||||
import net.knarcraft.stargate.portal.property.PortalOwner;
|
||||
import net.knarcraft.stargate.portal.property.PortalStructure;
|
||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||
import org.bukkit.ChatColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -3,11 +3,16 @@ package net.knarcraft.stargate.portal;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import org.bukkit.ChatColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* The portal sign drawer draws the sing of a given portal
|
||||
*/
|
||||
@ -18,6 +23,8 @@ public class PortalSignDrawer {
|
||||
private static ChatColor freeColor;
|
||||
private static ChatColor mainColor;
|
||||
private static ChatColor highlightColor;
|
||||
private static Map<Material, ChatColor> perSignMainColors;
|
||||
private static Map<Material, ChatColor> perSignHighlightColors;
|
||||
|
||||
/**
|
||||
* Instantiates a new portal sign drawer
|
||||
@ -59,6 +66,24 @@ public class PortalSignDrawer {
|
||||
PortalSignDrawer.freeColor = freeColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the per-sign main colors
|
||||
*
|
||||
* @param signMainColors <p>The per-sign main colors</p>
|
||||
*/
|
||||
public static void setPerSignMainColors(Map<Material, ChatColor> signMainColors) {
|
||||
PortalSignDrawer.perSignMainColors = signMainColors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the per-sign highlight colors
|
||||
*
|
||||
* @param signHighlightColors <p>The per-sign highlight colors</p>
|
||||
*/
|
||||
public static void setPerSignHighlightColors(Map<Material, ChatColor> signHighlightColors) {
|
||||
PortalSignDrawer.perSignHighlightColors = signHighlightColors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the sign of the portal this sign drawer is responsible for
|
||||
*/
|
||||
@ -96,9 +121,11 @@ public class PortalSignDrawer {
|
||||
* @param sign <p>The sign re-draw</p>
|
||||
*/
|
||||
private void drawSign(Sign sign) {
|
||||
ChatColor highlightColor = getHighlightColor(sign.getType());
|
||||
ChatColor mainColor = getMainColor(sign.getType());
|
||||
//Clear sign
|
||||
clearSign(sign);
|
||||
setLine(sign, 0, highlightColor + "-" + mainColor + fixColor(portal.getName()) + highlightColor + "-");
|
||||
setLine(sign, 0, highlightColor + "-" + mainColor + translateAllColorCodes(portal.getName()) + highlightColor + "-");
|
||||
|
||||
if (!portal.getPortalActivator().isActive()) {
|
||||
//Default sign text
|
||||
@ -139,7 +166,7 @@ public class PortalSignDrawer {
|
||||
return;
|
||||
}
|
||||
clearSign(sign);
|
||||
sign.setLine(0, fixColor(portal.getName()));
|
||||
sign.setLine(0, translateAllColorCodes(portal.getName()));
|
||||
sign.update();
|
||||
}
|
||||
|
||||
@ -184,15 +211,17 @@ public class PortalSignDrawer {
|
||||
* @param signLineIndex <p>The line to draw on</p>
|
||||
*/
|
||||
private void drawNetworkSignChosenLine(boolean freeGatesColored, Sign sign, int signLineIndex) {
|
||||
ChatColor highlightColor = getHighlightColor(sign.getType());
|
||||
ChatColor mainColor = getMainColor(sign.getType());
|
||||
if (freeGatesColored) {
|
||||
Portal destination = PortalHandler.getByName(portal.getDestinationName(), portal.getNetwork());
|
||||
boolean free = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
|
||||
ChatColor nameColor = (free ? freeColor : highlightColor);
|
||||
setLine(sign, signLineIndex, nameColor + ">" + (free ? freeColor : mainColor) +
|
||||
fixColor(portal.getDestinationName()) + nameColor + "<");
|
||||
translateAllColorCodes(portal.getDestinationName()) + nameColor + "<");
|
||||
} else {
|
||||
setLine(sign, signLineIndex, highlightColor + ">" + mainColor +
|
||||
fixColor(portal.getDestinationName()) + highlightColor + "<");
|
||||
translateAllColorCodes(portal.getDestinationName()) + highlightColor + "<");
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,6 +233,7 @@ public class PortalSignDrawer {
|
||||
* @param text <p>The new text on the sign</p>
|
||||
*/
|
||||
public void setLine(Sign sign, int index, String text) {
|
||||
ChatColor mainColor = getMainColor(sign.getType());
|
||||
sign.setLine(index, mainColor + text);
|
||||
}
|
||||
|
||||
@ -216,14 +246,15 @@ public class PortalSignDrawer {
|
||||
* @param destinationIndex <p>The index of the destination to draw</p>
|
||||
*/
|
||||
private void drawNetworkSignLine(boolean freeGatesColored, Sign sign, int signLineIndex, int destinationIndex) {
|
||||
ChatColor mainColor = getMainColor(sign.getType());
|
||||
PortalActivator destinations = portal.getPortalActivator();
|
||||
String destinationName = destinations.getDestinations().get(destinationIndex);
|
||||
if (freeGatesColored) {
|
||||
Portal destination = PortalHandler.getByName(destinationName, portal.getNetwork());
|
||||
boolean free = PermissionHelper.isFree(portal.getActivePlayer(), portal, destination);
|
||||
setLine(sign, signLineIndex, (free ? freeColor : mainColor) + fixColor(destinationName));
|
||||
setLine(sign, signLineIndex, (free ? freeColor : mainColor) + translateAllColorCodes(destinationName));
|
||||
} else {
|
||||
setLine(sign, signLineIndex, mainColor + fixColor(destinationName));
|
||||
setLine(sign, signLineIndex, mainColor + translateAllColorCodes(destinationName));
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,10 +264,12 @@ public class PortalSignDrawer {
|
||||
* @param sign <p>The sign to re-draw</p>
|
||||
*/
|
||||
private void drawBungeeSign(Sign sign) {
|
||||
ChatColor highlightColor = getHighlightColor(sign.getType());
|
||||
ChatColor mainColor = getMainColor(sign.getType());
|
||||
setLine(sign, 1, Stargate.getString("bungeeSign"));
|
||||
setLine(sign, 2, highlightColor + ">" + mainColor + fixColor(portal.getDestinationName()) +
|
||||
setLine(sign, 2, highlightColor + ">" + mainColor + translateAllColorCodes(portal.getDestinationName()) +
|
||||
highlightColor + "<");
|
||||
setLine(sign, 3, highlightColor + "[" + mainColor + fixColor(portal.getNetwork()) +
|
||||
setLine(sign, 3, highlightColor + "[" + mainColor + translateAllColorCodes(portal.getNetwork()) +
|
||||
highlightColor + "]");
|
||||
}
|
||||
|
||||
@ -248,10 +281,12 @@ public class PortalSignDrawer {
|
||||
* @param sign <p>The sign to re-draw</p>
|
||||
*/
|
||||
private void drawInactiveSign(Sign sign) {
|
||||
ChatColor highlightColor = getHighlightColor(sign.getType());
|
||||
ChatColor mainColor = getMainColor(sign.getType());
|
||||
setLine(sign, 1, Stargate.getString("signRightClick"));
|
||||
setLine(sign, 2, Stargate.getString("signToUse"));
|
||||
if (!portal.getOptions().isNoNetwork()) {
|
||||
setLine(sign, 3, highlightColor + "(" + mainColor + fixColor(portal.getNetwork()) +
|
||||
setLine(sign, 3, highlightColor + "(" + mainColor + translateAllColorCodes(portal.getNetwork()) +
|
||||
highlightColor + ")");
|
||||
} else {
|
||||
setLine(sign, 3, "");
|
||||
@ -264,17 +299,20 @@ public class PortalSignDrawer {
|
||||
* @param sign <p>The sign to re-draw</p>
|
||||
*/
|
||||
private void drawFixedSign(Sign sign) {
|
||||
ChatColor highlightColor = getHighlightColor(sign.getType());
|
||||
ChatColor mainColor = getMainColor(sign.getType());
|
||||
Portal destinationPortal = PortalHandler.getByName(Portal.cleanString(portal.getDestinationName()),
|
||||
portal.getCleanNetwork());
|
||||
String destinationName = portal.getOptions().isRandom() ? Stargate.getString("signRandom") :
|
||||
(destinationPortal != null ? destinationPortal.getName() : portal.getDestinationName());
|
||||
setLine(sign, 1, highlightColor + ">" + mainColor + fixColor(destinationName) + highlightColor + "<");
|
||||
setLine(sign, 1, highlightColor + ">" + mainColor + translateAllColorCodes(destinationName) +
|
||||
highlightColor + "<");
|
||||
|
||||
if (portal.getOptions().isNoNetwork()) {
|
||||
setLine(sign, 2, "");
|
||||
} else {
|
||||
setLine(sign, 2, highlightColor + "(" + mainColor + fixColor(portal.getNetwork()) +
|
||||
highlightColor + ")");
|
||||
setLine(sign, 2, highlightColor + "(" + mainColor +
|
||||
translateAllColorCodes(portal.getNetwork()) + highlightColor + ")");
|
||||
}
|
||||
Portal destination = PortalHandler.getByName(Portal.cleanString(portal.getDestinationName()),
|
||||
portal.getNetwork());
|
||||
@ -304,13 +342,49 @@ public class PortalSignDrawer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes coloring of signs as the & character isn't translated on all servers
|
||||
* Translates all found color codes to formatting in a string
|
||||
*
|
||||
* @param text <p>The text to fix the coloring of</p>
|
||||
* @return <p>The text with the coloring fixed</p>
|
||||
* @param message <p>The string to search for color codes</p>
|
||||
* @return <p>The message with color codes translated</p>
|
||||
*/
|
||||
private String fixColor(String text) {
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
public static String translateAllColorCodes(String message) {
|
||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
Pattern pattern = Pattern.compile("(#[a-fA-F0-9]{6})");
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
while (matcher.find()) {
|
||||
message = message.replace(matcher.group(), "" + ChatColor.of(matcher.group()));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the main color to use for the given sign type
|
||||
*
|
||||
* @param signType <p>The sign type to get the main color for</p>
|
||||
* @return <p>The main color for the given sign type</p>
|
||||
*/
|
||||
private ChatColor getMainColor(Material signType) {
|
||||
ChatColor signColor = perSignMainColors.get(signType);
|
||||
if (signColor == null) {
|
||||
return mainColor;
|
||||
} else {
|
||||
return signColor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the highlight color to use for the given sign type
|
||||
*
|
||||
* @param signType <p>The sign type to get the highlight color for</p>
|
||||
* @return <p>The highlight color for the given sign type</p>
|
||||
*/
|
||||
private ChatColor getHighlightColor(Material signType) {
|
||||
ChatColor signColor = perSignHighlightColors.get(signType);
|
||||
if (signColor == null) {
|
||||
return highlightColor;
|
||||
} else {
|
||||
return signColor;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import org.bukkit.ChatColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
|
@ -49,6 +49,15 @@ gates:
|
||||
sortNetworkDestinations: false
|
||||
mainSignColor: BLACK
|
||||
highlightSignColor: WHITE
|
||||
perSignColors:
|
||||
- "ACACIA:default,default"
|
||||
- "BIRCH:default,default"
|
||||
- "CRIMSON:default,default"
|
||||
- "DARK_OAK:default,default"
|
||||
- "JUNGLE:default,default"
|
||||
- "OAK:default,default"
|
||||
- "SPRUCE:default,default"
|
||||
- "WARPED:default,default"
|
||||
integrity:
|
||||
destroyedByExplosion: false
|
||||
verifyPortals: false
|
||||
|
Loading…
x
Reference in New Issue
Block a user