From b4ef7c073380624f52e712f154807ecaa2558fa1 Mon Sep 17 00:00:00 2001 From: ucchyocean Date: Thu, 23 May 2013 01:35:37 +0900 Subject: [PATCH] LunaChat v2.0.0 : Fixed issue #20. --- .../com/github/ucchyocean/lc/Channel.java | 27 +++++++++- .../github/ucchyocean/lc/LunaChatCommand.java | 18 +++++++ .../com/github/ucchyocean/lc/Utility.java | 53 +++++++++++++++++++ src/main/resources/messages.yml | 3 +- 4 files changed, 99 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/ucchyocean/lc/Channel.java b/src/main/java/com/github/ucchyocean/lc/Channel.java index 4f6c405..19b7578 100644 --- a/src/main/java/com/github/ucchyocean/lc/Channel.java +++ b/src/main/java/com/github/ucchyocean/lc/Channel.java @@ -59,6 +59,7 @@ public class Channel implements ConfigurationSerializable { private static final String KEY_MODERATOR = "moderator"; private static final String KEY_PASSWORD = "password"; private static final String KEY_VISIBLE = "visible"; + private static final String KEY_COLOR = "color"; /** 参加者 */ private List members; @@ -81,13 +82,17 @@ public class Channel implements ConfigurationSerializable { /** チャンネルリストに表示されるかどうか */ private boolean visible; + /** チャンネルのカラー */ + private String colorCode; + /** メッセージフォーマット
* 指定可能なキーワードは下記のとおり
* %ch - チャンネル名
* %username - ユーザー名
* %msg - メッセージ
* %prefix - PermissionsExに設定するprefix
- * %suffix - PermissionsExに設定するsuffix + * %suffix - PermissionsExに設定するsuffix
+ * %chcolor - チャンネルのカラーコード * */ private String format; @@ -104,6 +109,7 @@ public class Channel implements ConfigurationSerializable { this.moderator = new ArrayList(); this.password = ""; this.visible = true; + this.colorCode = ""; } /** @@ -369,6 +375,7 @@ public class Channel implements ConfigurationSerializable { String msg = format.replace("%ch", name); msg = msg.replace("%msg", message); + msg = msg.replace("%chcolor", colorCode); if ( player != null ) { msg = msg.replace("%username", player.getDisplayName()); @@ -442,6 +449,7 @@ public class Channel implements ConfigurationSerializable { map.put(KEY_MODERATOR, moderator); map.put(KEY_PASSWORD, password); map.put(KEY_VISIBLE, visible); + map.put(KEY_COLOR, colorCode); return map; } @@ -470,6 +478,7 @@ public class Channel implements ConfigurationSerializable { channel.moderator = castToStringList(data.get(KEY_MODERATOR)); channel.password = castWithDefault(data.get(KEY_PASSWORD), ""); channel.visible = castWithDefault(data.get(KEY_VISIBLE), true); + channel.colorCode = castWithDefault(data.get(KEY_COLOR), ""); return channel; } @@ -601,6 +610,22 @@ public class Channel implements ConfigurationSerializable { return name; } + /** + * チャンネルのカラーコードを返す + * @return チャンネルのカラーコード + */ + public String getColorCode() { + return colorCode; + } + + /** + * チャンネルのカラーコードを設定する + * @param colorCode カラーコード + */ + public void setColorCode(String colorCode) { + this.colorCode = colorCode; + } + /** * チャンネルの情報をファイルに保存する。 * @return 保存をしたかどうか。 diff --git a/src/main/java/com/github/ucchyocean/lc/LunaChatCommand.java b/src/main/java/com/github/ucchyocean/lc/LunaChatCommand.java index 816779c..93f4271 100644 --- a/src/main/java/com/github/ucchyocean/lc/LunaChatCommand.java +++ b/src/main/java/com/github/ucchyocean/lc/LunaChatCommand.java @@ -998,11 +998,29 @@ public class LunaChatCommand implements CommandExecutor { // 設定する boolean setOption = false; if ( options.containsKey("description") ) { + // チャンネル説明文 + // TODO: チャンネル説明文は30文字制限をした方がいい。 channel.setDescription(options.get("description")); sendResourceMessage(sender, PREINFO, "cmdmsgOption", "description", options.get("description")); setOption = true; } + if ( options.containsKey("color") ) { + // チャンネルカラー + String code = options.get("color"); + if ( Utility.isValidColor(code) ) { + code = Utility.changeToColorCode(code); + } + if ( Utility.isValidColorCode(code) ) { + channel.setColorCode(code); + sendResourceMessage(sender, PREINFO, + "cmdmsgOption", "color", options.get("color")); + setOption = true; + } else { + sendResourceMessage(sender, PREERR, + "errmsgInvalidColorCode", options.get("color")); + } + } if ( !LunaChat.config.globalChannel.equals(channel.getName()) ) { if ( options.containsKey("password") ) { channel.setPassword(options.get("password")); diff --git a/src/main/java/com/github/ucchyocean/lc/Utility.java b/src/main/java/com/github/ucchyocean/lc/Utility.java index 7ff73b6..f3d894c 100644 --- a/src/main/java/com/github/ucchyocean/lc/Utility.java +++ b/src/main/java/com/github/ucchyocean/lc/Utility.java @@ -17,6 +17,8 @@ import java.io.OutputStreamWriter; import java.util.jar.JarFile; import java.util.zip.ZipEntry; +import org.bukkit.ChatColor; + /** * @author ucchy * ユーティリティクラス @@ -128,4 +130,55 @@ public class Utility { } return buf.toString(); } + + /** + * カラー表記の文字列を、ChatColorクラスに変換する + * @param color カラー表記の文字列 + * @return ChatColorクラス + */ + public static ChatColor changeToChatColor(String color) { + + if ( isValidColor(color) ) { + return ChatColor.valueOf(color.toUpperCase()); + } + return ChatColor.WHITE; + } + + /** + * カラー表記の文字列を、カラーコードに変換する + * @param color カラー表記の文字列 + * @return カラーコード + */ + public static String changeToColorCode(String color) { + + return "&" + changeToChatColor(color).getChar(); + } + + /** + * ChatColorで指定可能な色かどうかを判断する + * @param color カラー表記の文字列 + * @return 指定可能かどうか + */ + public static boolean isValidColor(String color) { + + for ( ChatColor c : ChatColor.values() ) { + if ( c.name().equals(color.toUpperCase()) ) { + return true; + } + } + return false; + } + + /** + * カラーコードかどうかを判断する + * @param color カラー表記の文字列 + * @return 指定可能かどうか + */ + public static boolean isValidColorCode(String code) { + + if ( code == null ) { + return false; + } + return code.matches("&[0-9a-f]"); + } } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 5e62eaf..02f5710 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -1,4 +1,4 @@ -defaultFormat: '&a[%ch]%prefix%username%suffix&a: %msg' +defaultFormat: '&a[%ch]%prefix%username%suffix&a:&f %chcolor%msg' joinMessage: '&a[%ch]&7%username さんがチャンネルチャットに参加しました。' quitMessage: '&a[%ch]&7%username さんがチャンネルチャットから退出しました。' @@ -70,6 +70,7 @@ errmsgNotfoundPM: 'あなたが受信したプライベートメッセージが errmsgCannotSendPMSelf: '自分自身にプライベートメッセージを送ることはできません。' errmsgCannotUseForChannel: '%s はチャンネル名に使用できない文字を含んでいます。' errmsgCannotUseForGlobal: '%s はグローバルチャンネル名に使用できない文字を含んでいます。' +errmsgInvalidColorCode: '%s はカラーコードとして正しくありません。' ngwordPrefix: 'NGワード発言により、'