LunaChat v3.0.2 : Fixed issue #176.

このコミットが含まれているのは:
ucchy committed 2020-06-28 00:49:54 +09:00
1 親 f0fe3f02e6
コミット 881d3504b6
8ファイル変更
+180 -44

検索条件に一致するファイルはありません

+1 -1
ファイルの表示
@@ -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チャンネルが、使用可能なチャンネル名かどうかを調べる
+5 -2
ファイルの表示
@@ -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("&", "&"));
}
}
}
+95 -26
ファイルの表示
@@ -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;
}
}
+24 -9
ファイルの表示
@@ -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());
}