From 8503f4742455aa3cd7e9ddea4e87a4ec26a14781 Mon Sep 17 00:00:00 2001 From: ucchyocean Date: Mon, 3 Jun 2013 01:41:21 +0900 Subject: [PATCH] LunaChat v2.1.0 : issue #31 (wip...) --- .../com/github/ucchyocean/lc/Channel.java | 69 +++++++++++++-- .../github/ucchyocean/lc/LunaChatCommand.java | 88 ++++++++++++++++--- src/main/resources/messages.yml | 4 + 3 files changed, 143 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/github/ucchyocean/lc/Channel.java b/src/main/java/com/github/ucchyocean/lc/Channel.java index 794db96..20b3ee9 100644 --- a/src/main/java/com/github/ucchyocean/lc/Channel.java +++ b/src/main/java/com/github/ucchyocean/lc/Channel.java @@ -67,6 +67,9 @@ public class Channel implements ConfigurationSerializable { private static final String KEY_PASSWORD = "password"; private static final String KEY_VISIBLE = "visible"; private static final String KEY_COLOR = "color"; + private static final String KEY_BROADCAST = "broadcast"; + private static final String KEY_WORLD = "world"; + private static final String KEY_RANGE = "range"; private static final SimpleDateFormat dformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -106,6 +109,15 @@ public class Channel implements ConfigurationSerializable { * */ private String format; + /** ブロードキャストチャンネルかどうか */ + private boolean broadcastChannel; + + /** ワールドチャットかどうか */ + private boolean isWorldRange; + + /** チャットの可聴範囲 0は無制限 */ + private int chatRange; + /** ロガー */ private Logger logger; @@ -122,6 +134,9 @@ public class Channel implements ConfigurationSerializable { this.password = ""; this.visible = true; this.colorCode = ""; + this.broadcastChannel = false; + this.isWorldRange = false; + this.chatRange = 0; if ( isPersonalChat() ) { this.format = DEFAULT_FORMAT_FOR_PERSONAL; @@ -138,11 +153,18 @@ public class Channel implements ConfigurationSerializable { return name.contains(">"); } +// /** +// * @return グローバルチャットチャンネルかどうか +// */ +// private boolean isGlobalChat() { +// return name.equals(LunaChat.config.globalChannel); +// } + /** - * @return グローバルチャットチャンネルかどうか + * @return ブロードキャストチャンネルかどうか */ - private boolean isGlobalChat() { - return name.equals(LunaChat.config.globalChannel); + private boolean isBroadcastChannel() { + return (name.equals(LunaChat.config.globalChannel) || broadcastChannel); } /** @@ -332,12 +354,13 @@ public class Channel implements ConfigurationSerializable { */ public void sendInformation(String message) { - if ( isGlobalChat() ) { + if ( isBroadcastChannel() ) { + // ブロードキャストチャンネル - // グローバルチャンネルは、そのままブロードキャスト Bukkit.broadcastMessage(message); } else { + // 通常チャンネル // オンラインのプレイヤーに送信する for ( String member : members ) { @@ -365,7 +388,7 @@ public class Channel implements ConfigurationSerializable { Utility.replaceColorCode(LIST_FORMAT), name, getOnlineNum(), getTotalNum(), description) ); - if ( !isGlobalChat() ) { + if ( !isBroadcastChannel() ) { // メンバーを、5人ごとに表示する StringBuffer buf = new StringBuffer(); for ( int i=0; i MAX_LENGTH_DESCRIPTION ) { + sendResourceMessage(sender, PREERR, + "errmsgToolongDescription", MAX_LENGTH_DESCRIPTION); + } else { + channel.setDescription(desc); + sendResourceMessage(sender, PREINFO, + "cmdmsgOption", "description", desc); + setOption = true; + } } + if ( options.containsKey("color") ) { // チャンネルカラー String code = options.get("color"); @@ -1024,15 +1035,72 @@ public class LunaChatCommand implements CommandExecutor { "errmsgInvalidColorCode", options.get("color")); } } + + if ( options.containsKey("broadcast") ) { + // ブロードキャストチャンネル + String value = options.get("broadcast"); + + if ( value.equals("") || value.equalsIgnoreCase("false") ) { + channel.setBroadcast(false); + sendResourceMessage(sender, PREINFO, + "cmdmsgOption", "broadcast", "false"); + setOption = true; + } else if ( value.equalsIgnoreCase("true") ) { + channel.setBroadcast(true); + sendResourceMessage(sender, PREINFO, + "cmdmsgOption", "broadcast", "true"); + setOption = true; + } else { + sendResourceMessage(sender, PREERR, + "errmsgInvalidBooleanOption", "broadcast"); + } + } + + if ( options.containsKey("range") ) { + // レンジ + String value = options.get("range"); + + if ( value.equals("") ) { + channel.setWorldRange(false); + channel.setRange(0); + sendResourceMessage(sender, PREINFO, + "cmdmsgOption", "range", "無効"); + setOption = true; + } else if ( value.equalsIgnoreCase("world") ) { + channel.setWorldRange(true); + channel.setRange(0); + sendResourceMessage(sender, PREINFO, + "cmdmsgOption", "range", "world"); + setOption = true; + } else if ( value.matches("[0-9]+") ) { + channel.setWorldRange(true); + channel.setRange(Integer.parseInt(value)); + sendResourceMessage(sender, PREINFO, + "cmdmsgOption", "range", value); + setOption = true; + } else { + sendResourceMessage(sender, PREERR, + "errmsgInvalidRangeOption"); + } + } + if ( !LunaChat.config.globalChannel.equals(channel.getName()) ) { + if ( options.containsKey("password") ) { // パスワード - // TODO: パスワードは10文字制限をした方がいい。 - channel.setPassword(options.get("password")); - sendResourceMessage(sender, PREINFO, - "cmdmsgOption", "password", options.get("password")); - setOption = true; + String password = options.get("password"); + // パスワードは10文字制限をした方がいい。 + if ( password.length() > MAX_LENGTH_PASSWORD ) { + sendResourceMessage(sender, PREERR, + "errmsgToolongPassword", MAX_LENGTH_PASSWORD); + } else { + channel.setPassword(password); + sendResourceMessage(sender, PREINFO, + "cmdmsgOption", "password", password); + setOption = true; + } } + if ( options.containsKey("visible") ) { String temp = options.get("visible"); if ( temp.equalsIgnoreCase("false") ) { diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 0004c31..5dc26c5 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -75,6 +75,10 @@ errmsgCannotUseForChannel: '%s はチャンネル名に使用できない文字 errmsgCannotUseForGlobal: '%s はグローバルチャンネル名に使用できない文字を含んでいます。' errmsgInvalidColorCode: '%s はカラーコードとして正しくありません。' errmsgInvalidTemplateNumber: 'テンプレート番号は、0から9までの数字を指定してください。' +errmsgToolongDescription: '説明文は %d 文字以下にしてください。' +errmsgToolongPassword: 'パスワードは %d 文字以下にしてください。' +errmsgInvalidBooleanOption: '%s は true/false で指定してください。' +errmsgInvalidRangeOption: 'range に正しくない値が指定されました。' ngwordPrefix: 'NGワード発言により、'