diff --git a/pom.xml b/pom.xml index ba3d73b..5aa718d 100644 --- a/pom.xml +++ b/pom.xml @@ -143,15 +143,24 @@ - org.bukkit - bukkit - 1.15.2-R0.1-SNAPSHOT + org.spigotmc + spigot-api + 1.16.1-R0.1-SNAPSHOT + true provided net.md-5 bungeecord-api - 1.15-SNAPSHOT + 1.16-R0.2-SNAPSHOT + true + provided + + + net.md-5 + bungeecord-chat + 1.16-R0.1 + true provided @@ -160,6 +169,12 @@ 1.7 true provided + + + org.bukkit + bukkit + + org.dynmap @@ -167,6 +182,12 @@ 2.0 true provided + + + org.bukkit + bukkit + + com.onarandombox.multiversecore diff --git a/src/main/java/com/github/ucchyocean/lc3/LunaChatConfig.java b/src/main/java/com/github/ucchyocean/lc3/LunaChatConfig.java index d985dcf..fd27efb 100644 --- a/src/main/java/com/github/ucchyocean/lc3/LunaChatConfig.java +++ b/src/main/java/com/github/ucchyocean/lc3/LunaChatConfig.java @@ -250,7 +250,7 @@ public class LunaChatConfig { japanizeLine1Format = config.getString("japanizeLine1Format", "%msg &6(%japanize)"); japanizeLine2Format = config.getString("japanizeLine2Format", "&6[JP] %japanize"); japanizeIgnorePlayerName = config.getBoolean("japanizeIgnorePlayerName", true); - noneJapanizeMarker = config.getString("noneJapanizeMarker", "#"); + noneJapanizeMarker = config.getString("noneJapanizeMarker", "$"); japanizeWait = config.getInt("japanizeWait", 1); // globalチャンネルが、使用可能なチャンネル名かどうかを調べる diff --git a/src/main/java/com/github/ucchyocean/lc3/command/OptionCommand.java b/src/main/java/com/github/ucchyocean/lc3/command/OptionCommand.java index d4c949e..1e8913c 100644 --- a/src/main/java/com/github/ucchyocean/lc3/command/OptionCommand.java +++ b/src/main/java/com/github/ucchyocean/lc3/command/OptionCommand.java @@ -198,16 +198,19 @@ public class OptionCommand extends LunaChatSubCommand { } else { String code = options.get("color"); + String colorForMsg = options.get("color").replace("&", "&").replace("#", "#"); if ( Utility.isValidColor(code) ) { code = Utility.changeToColorCode(code); } if ( Utility.isAltColorCode(code) ) { channel.setColorCode(code); - sender.sendMessage(Messages.cmdmsgOption("color", options.get("color"))); + sender.sendMessage(Messages.cmdmsgOption("color", colorForMsg) + .replace("#", "#").replace("&", "&")); setOption = true; } else { - sender.sendMessage(Messages.errmsgInvalidColorCode(options.get("color"))); + sender.sendMessage(Messages.errmsgInvalidColorCode(colorForMsg) + .replace("#", "#").replace("&", "&")); } } } diff --git a/src/main/java/com/github/ucchyocean/lc3/util/ChatColor.java b/src/main/java/com/github/ucchyocean/lc3/util/ChatColor.java index e5de779..8b44f66 100644 --- a/src/main/java/com/github/ucchyocean/lc3/util/ChatColor.java +++ b/src/main/java/com/github/ucchyocean/lc3/util/ChatColor.java @@ -6,35 +6,36 @@ package com.github.ucchyocean.lc3.util; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * チャットカラー * @author ucchy */ -public enum ChatColor { +public final class ChatColor { - BLACK('0', 0x00), - DARK_BLUE('1', 0x1), - DARK_GREEN('2', 0x2), - DARK_AQUA('3', 0x3), - DARK_RED('4', 0x4), - DARK_PURPLE('5', 0x5), - GOLD('6', 0x6), - GRAY('7', 0x7), - DARK_GRAY('8', 0x8), - BLUE('9', 0x9), - GREEN('a', 0xA), - AQUA('b', 0xB), - RED('c', 0xC), - LIGHT_PURPLE('d', 0xD), - YELLOW('e', 0xE), - WHITE('f', 0xF), - MAGIC('k', 0x10, true), - BOLD('l', 0x11, true), - STRIKETHROUGH('m', 0x12, true), - UNDERLINE('n', 0x13, true), - ITALIC('o', 0x14, true), - RESET('r', 0x15); + public static final ChatColor BLACK = new ChatColor("BLACK", '0', 0x00); + public static final ChatColor DARK_BLUE = new ChatColor("DARK_BLUE", '1', 0x1); + public static final ChatColor DARK_GREEN = new ChatColor("DARK_GREEN", '2', 0x2); + public static final ChatColor DARK_AQUA = new ChatColor("DARK_AQUA", '3', 0x3); + public static final ChatColor DARK_RED = new ChatColor("DARK_RED", '4', 0x4); + public static final ChatColor DARK_PURPLE = new ChatColor("DARK_PURPLE", '5', 0x5); + public static final ChatColor GOLD = new ChatColor("GOLD", '6', 0x6); + public static final ChatColor GRAY = new ChatColor("GRAY", '7', 0x7); + public static final ChatColor DARK_GRAY = new ChatColor("DARK_GRAY", '8', 0x8); + public static final ChatColor BLUE = new ChatColor("BLUE", '9', 0x9); + public static final ChatColor GREEN = new ChatColor("GREEN", 'a', 0xA); + public static final ChatColor AQUA = new ChatColor("AQUA", 'b', 0xB); + public static final ChatColor RED = new ChatColor("RED", 'c', 0xC); + public static final ChatColor LIGHT_PURPLE = new ChatColor("LIGHT_PURPLE", 'd', 0xD); + public static final ChatColor YELLOW = new ChatColor("YELLOW", 'e', 0xE); + public static final ChatColor WHITE = new ChatColor("WHITE", 'f', 0xF); + public static final ChatColor MAGIC = new ChatColor("MAGIC", 'k', 0x10, true); + public static final ChatColor BOLD = new ChatColor("BOLD", 'l', 0x11, true); + public static final ChatColor STRIKETHROUGH = new ChatColor("STRIKETHROUGH", 'm', 0x12, true); + public static final ChatColor UNDERLINE = new ChatColor("UNDERLINE", 'n', 0x13, true); + public static final ChatColor ITALIC = new ChatColor("ITALIC", 'o', 0x14, true); + public static final ChatColor RESET = new ChatColor("RESET", 'r', 0x15); public static final char COLOR_CHAR = '\u00A7'; @@ -43,18 +44,32 @@ public enum ChatColor { private final char code; private final boolean isFormat; private final String toString; + private final String name; - private ChatColor(char code, int intCode) { - this(code, intCode, false); + private ChatColor(String name, char code, int intCode) { + this(name, code, intCode, false); } - private ChatColor(char code, int intCode, boolean isFormat) { + private ChatColor(String name, char code, int intCode, boolean isFormat) { + this.name = name; this.code = code; this.intCode = intCode; this.isFormat = isFormat; this.toString = new String(new char[] {COLOR_CHAR, code}); } + private ChatColor(String name, String toString) { + this.name = name; + this.toString = toString; + this.isFormat = false; + this.code = 'c'; + this.intCode =0xFF; + } + + public String name() { + return name; + } + public char getChar() { return code; } @@ -68,4 +83,58 @@ public enum ChatColor { public boolean isFormat() { return isFormat; } + + public static @Nullable ChatColor getChatColorFromWebColor(String code) { + if ( code == null ) return null; + if ( code.matches("#[0-9a-fA-F]{3}") ) { + return new ChatColor(code, code.replaceAll( + "#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])", + "\u00A7x\u00A7$1\u00A7$1\u00A7$2\u00A7$2\u00A7$3\u00A7$3")); + } else if ( code.matches("#[0-9a-fA-F]{6}") ) { + return new ChatColor(code, code.replaceAll( + "#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])", + "\u00A7x\u00A7$1\u00A7$2\u00A7$3\u00A7$4\u00A7$5\u00A7$6")); + } + return null; + } + + public static ChatColor[] values() { + return new ChatColor[] { + BLACK, + DARK_BLUE, + DARK_GREEN, + DARK_AQUA, + DARK_RED, + DARK_PURPLE, + GOLD, + GRAY, + DARK_GRAY, + BLUE, + GREEN, + AQUA, + RED, + LIGHT_PURPLE, + YELLOW, + WHITE, + MAGIC, + BOLD, + STRIKETHROUGH, + UNDERLINE, + ITALIC, + RESET, + }; + } + + public static ChatColor valueOf(String code) { + if ( code.matches("#[0-9a-fA-F]{6}") ) { + return new ChatColor(code, code.replaceAll( + "#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])", + "\u00A7x\u00A7$1\u00A7$2\u00A7$3\u00A7$4\u00A7$5\u00A7$6")); + } else { + for ( ChatColor v : values() ) { + if ( v.name.equals(code) ) return v; + } + } + return null; + } } diff --git a/src/main/java/com/github/ucchyocean/lc3/util/Utility.java b/src/main/java/com/github/ucchyocean/lc3/util/Utility.java index ac6abce..7a274d1 100644 --- a/src/main/java/com/github/ucchyocean/lc3/util/Utility.java +++ b/src/main/java/com/github/ucchyocean/lc3/util/Utility.java @@ -79,7 +79,23 @@ public class Utility { */ public static String replaceColorCode(String source) { if (source == null) return null; - return source.replaceAll("&([0-9a-fk-or])", "\u00A7$1"); + return replaceWebColorCode(source) + .replaceAll("&([0-9a-fk-orA-FK-OR])", "\u00A7$1"); + } + + /** + * Webカラーコード(#99AABBなど)を、カラーコードに置き換えする + * @param source 置き換え元の文字列 + * @return 置き換え後の文字列 + */ + private static String replaceWebColorCode(String source) { + return source + .replaceAll( + "#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])", + "\u00A7x\u00A7$1\u00A7$2\u00A7$3\u00A7$4\u00A7$5\u00A7$6") + .replaceAll( + "#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])", + "\u00A7x\u00A7$1\u00A7$1\u00A7$2\u00A7$2\u00A7$3\u00A7$3"); } /** @@ -89,7 +105,7 @@ public class Utility { */ public static String stripColorCode(String source) { if (source == null) return null; - return stripAltColorCode(source).replaceAll("\u00A7([0-9a-fk-or])", "").replaceAll("&([0-9a-fk-or])", ""); + return stripAltColorCode(source).replaceAll("\u00A7([0-9a-fk-orxA-FK-ORX])", ""); } /** @@ -99,7 +115,8 @@ public class Utility { */ public static String stripAltColorCode(String source) { if (source == null) return null; - return source.replaceAll("&([0-9a-fk-or])", ""); + source = source.replaceAll("#[0-9a-fA-F]{6}", "").replaceAll("#[0-9a-fA-F]{3}", ""); + return source.replaceAll("&([0-9a-fk-orxA-FK-ORX])", ""); } /** @@ -109,7 +126,7 @@ public class Utility { */ public static boolean isColorCode(String code) { if (code == null) return false; - return code.matches("\u00A7[0-9a-fk-orA-FK-OR]"); + return code.matches("\u00A7[0-9a-fk-orxA-FK-ORX]"); } /** @@ -119,7 +136,7 @@ public class Utility { */ public static boolean isAltColorCode(String code) { if (code == null) return false; - return code.matches("&[0-9a-fk-orA-FK-OR]"); + return code.matches("(&[0-9a-fk-orA-FK-OR]|#[0-9a-fA-F]{3}|#[0-9a-fA-F]{6})"); } /** @@ -138,12 +155,11 @@ public class Utility { } /** - * カラー表記の文字列を、カラーコードに変換する + * カラー表記の文字列(REDとかGREENとか)を、カラーコード候補(&a)に変換する * @param color カラー表記の文字列 - * @return カラーコード + * @return カラーコード候補 */ public static String changeToColorCode(String color) { - return "&" + changeToChatColor(color).getChar(); } @@ -153,7 +169,6 @@ public class Utility { * @return ChatColorクラス */ public static ChatColor changeToChatColor(String color) { - if (isValidColor(color)) { return ChatColor.valueOf(color.toUpperCase()); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 777eb86..ebba587 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -203,4 +203,4 @@ japanizeIgnorePlayerName: true # Non-Japanese marker. # If this is at the beginning of your remark, do not temporarily perform Japanize conversion. -noneJapanizeMarker: '#' +noneJapanizeMarker: '$' diff --git a/src/main/resources/config_ja.yml b/src/main/resources/config_ja.yml index 063ee99..279e695 100644 --- a/src/main/resources/config_ja.yml +++ b/src/main/resources/config_ja.yml @@ -213,6 +213,6 @@ japanizeIgnorePlayerName: true # ノンジャパナイズマーカー。 # これが発言の頭に入っている場合は、一時的にJapanize変換を実行しない。 -noneJapanizeMarker: '#' +noneJapanizeMarker: '$' diff --git a/src/test/java/com/github/ucchyocean/lc3/util/UtilityTester.java b/src/test/java/com/github/ucchyocean/lc3/util/UtilityTester.java new file mode 100644 index 0000000..3611b04 --- /dev/null +++ b/src/test/java/com/github/ucchyocean/lc3/util/UtilityTester.java @@ -0,0 +1,28 @@ +/* + * @author ucchy + * @license LGPLv3 + * @copyright Copyright ucchy 2020 + */ +package com.github.ucchyocean.lc3.util; + +import junit.framework.TestCase; + +/** + * + * @author ucchy + */ +public class UtilityTester extends TestCase { + + public void testColorCode() { + + String testee = "#FFEEDDtesuto#112233aiueo"; + System.out.println(Utility.replaceColorCode(testee)); + + assertTrue("§x§F§F§E§E§D§Dtesuto§x§1§1§2§2§3§3aiueo".equals(Utility.replaceColorCode(testee))); + + testee = "#FEDtesuto#123aiueo"; + System.out.println(Utility.replaceColorCode(testee)); + + assertTrue("§x§F§F§E§E§D§Dtesuto§x§1§1§2§2§3§3aiueo".equals(Utility.replaceColorCode(testee))); + } +}