From b99d447d8190bfdefba85a85fa8ca87b0692519a Mon Sep 17 00:00:00 2001 From: ucchy Date: Tue, 17 Feb 2015 01:05:06 +0900 Subject: [PATCH] LunaChat v2.7.1 : Fixed issue #125 --- .../github/ucchyocean/lc/LunaChatConfig.java | 2 +- .../github/ucchyocean/lc/channel/Channel.java | 24 ++++++++++++++ .../ucchyocean/lc/channel/ChannelImpl.java | 7 ++-- .../ucchyocean/lc/command/OptionCommand.java | 32 +++++++++++++++++++ .../ucchyocean/lc/japanize/JapanizeType.java | 8 +++-- src/main/resources/messages.yml | 1 + src/main/resources/plugin.yml | 4 +++ 7 files changed, 71 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/github/ucchyocean/lc/LunaChatConfig.java b/src/main/java/com/github/ucchyocean/lc/LunaChatConfig.java index 81ab08f..2f8ffa3 100644 --- a/src/main/java/com/github/ucchyocean/lc/LunaChatConfig.java +++ b/src/main/java/com/github/ucchyocean/lc/LunaChatConfig.java @@ -217,7 +217,7 @@ public class LunaChatConfig { enableNormalChatColorCode = config.getBoolean("enableNormalChatColorCode", true); - japanizeType = JapanizeType.fromID(config.getString("japanizeType", "kana")); + japanizeType = JapanizeType.fromID(config.getString("japanizeType"), JapanizeType.KANA); japanizeDisplayLine = config.getInt("japanizeDisplayLine", 2); if ( japanizeDisplayLine != 1 && japanizeDisplayLine != 2 ) { japanizeDisplayLine = 2; diff --git a/src/main/java/com/github/ucchyocean/lc/channel/Channel.java b/src/main/java/com/github/ucchyocean/lc/channel/Channel.java index f099bc3..8f1b615 100644 --- a/src/main/java/com/github/ucchyocean/lc/channel/Channel.java +++ b/src/main/java/com/github/ucchyocean/lc/channel/Channel.java @@ -25,6 +25,7 @@ import com.github.ucchyocean.lc.LunaChatAPI; import com.github.ucchyocean.lc.LunaChatConfig; import com.github.ucchyocean.lc.Utility; import com.github.ucchyocean.lc.event.LunaChatChannelMemberChangedEvent; +import com.github.ucchyocean.lc.japanize.JapanizeType; /** * チャンネル @@ -53,6 +54,7 @@ public abstract class Channel implements ConfigurationSerializable { private static final String KEY_BAN_EXPIRES = "ban_expires"; private static final String KEY_MUTE_EXPIRES = "mute_expires"; private static final String KEY_ALLOWCC = "allowcc"; + private static final String KEY_JAPANIZE = "japanize"; /** 参加者 */ private List members; @@ -119,6 +121,9 @@ public abstract class Channel implements ConfigurationSerializable { /** カラーコードの使用可否 */ private boolean allowcc; + /** チャンネルごとのjapanize変換設定 */ + private JapanizeType japanizeType; + /** * コンストラクタ * @param name チャンネルの名称 @@ -143,6 +148,7 @@ public abstract class Channel implements ConfigurationSerializable { this.muteExpires = new HashMap(); this.privateMessageTo = ""; this.allowcc = true; + this.japanizeType = null; LunaChatConfig config = LunaChat.getInstance().getLunaChatConfig(); if ( isPersonalChat() ) { @@ -447,6 +453,7 @@ public abstract class Channel implements ConfigurationSerializable { map.put(KEY_BAN_EXPIRES, getStringLongMap(banExpires)); map.put(KEY_MUTE_EXPIRES, getStringLongMap(muteExpires)); map.put(KEY_ALLOWCC, allowcc); + map.put(KEY_JAPANIZE, japanizeType == null ? null : japanizeType.toString()); return map; } @@ -481,6 +488,7 @@ public abstract class Channel implements ConfigurationSerializable { channel.banExpires = castToChannelPlayerLongMap(data.get(KEY_BAN_EXPIRES)); channel.muteExpires = castToChannelPlayerLongMap(data.get(KEY_MUTE_EXPIRES)); channel.allowcc = castWithDefault(data.get(KEY_ALLOWCC), true); + channel.japanizeType = JapanizeType.fromID(data.get(KEY_JAPANIZE) + "", null); return channel; } @@ -863,6 +871,22 @@ public abstract class Channel implements ConfigurationSerializable { this.allowcc = allowcc; } + /** + * Japanize変換設定を取得する + * @return japanize + */ + public JapanizeType getJapanizeType() { + return japanizeType; + } + + /** + * Japanize変換設定を再設定する + * @param japanize japanize + */ + public void setJapanizeType(JapanizeType japanize) { + this.japanizeType = japanize; + } + /** * チャンネルの情報をファイルに保存する。 * @return 保存をしたかどうか。 diff --git a/src/main/java/com/github/ucchyocean/lc/channel/ChannelImpl.java b/src/main/java/com/github/ucchyocean/lc/channel/ChannelImpl.java index d679ae1..98f937c 100644 --- a/src/main/java/com/github/ucchyocean/lc/channel/ChannelImpl.java +++ b/src/main/java/com/github/ucchyocean/lc/channel/ChannelImpl.java @@ -159,10 +159,12 @@ public class ChannelImpl extends Channel { // Japanize変換タスクを作成する boolean isIncludeSyncChat = true; DelayedJapanizeConvertTask delayedTask = null; + JapanizeType japanizeType = (getJapanizeType() == null) + ? config.getJapanizeType() : getJapanizeType(); if ( !skipJapanize && api.isPlayerJapanize(player.getName()) && - config.getJapanizeType() != JapanizeType.NONE ) { + japanizeType != JapanizeType.NONE ) { int lineType = config.getJapanizeDisplayLine(); String jpFormat; @@ -177,8 +179,7 @@ public class ChannelImpl extends Channel { // タスクを作成しておく delayedTask = new DelayedJapanizeConvertTask(maskedMessage, - config.getJapanizeType(), - this, player, jpFormat, messageFormat); + japanizeType, this, player, jpFormat, messageFormat); } if ( isIncludeSyncChat ) { diff --git a/src/main/java/com/github/ucchyocean/lc/command/OptionCommand.java b/src/main/java/com/github/ucchyocean/lc/command/OptionCommand.java index 06a8f19..b47f592 100644 --- a/src/main/java/com/github/ucchyocean/lc/command/OptionCommand.java +++ b/src/main/java/com/github/ucchyocean/lc/command/OptionCommand.java @@ -15,6 +15,7 @@ import org.bukkit.entity.Player; import com.github.ucchyocean.lc.Utility; import com.github.ucchyocean.lc.channel.Channel; import com.github.ucchyocean.lc.event.LunaChatChannelOptionChangedEvent; +import com.github.ucchyocean.lc.japanize.JapanizeType; /** * optionコマンドの実行クラス @@ -324,6 +325,37 @@ public class OptionCommand extends SubCommandAbst { } } + if ( options.containsKey("japanize") ) { + // Japanize変換設定 + + String pnode = PERMISSION_NODE + ".japanize"; + if ( !sender.hasPermission(pnode) ) { + sendResourceMessage(sender, PREERR, + "errmsgNotPermission", pnode); + } else { + + String value = options.get("japanize"); + + if ( value.equals("") ) { + channel.setJapanizeType(null); + sendResourceMessage(sender, PREINFO, + "cmdmsgOption", "japanize", "デフォルト"); + setOption = true; + } else { + JapanizeType type = JapanizeType.fromID(value, null); + if ( type == null ) { + sendResourceMessage(sender, PREERR, + "errmsgInvalidJapanizeOption", "japanize", value); + } else { + channel.setJapanizeType(type); + sendResourceMessage(sender, PREINFO, + "cmdmsgOption", "japanize", type.toString()); + setOption = true; + } + } + } + } + if ( !channel.isGlobalChannel() ) { if ( options.containsKey("password") ) { diff --git a/src/main/java/com/github/ucchyocean/lc/japanize/JapanizeType.java b/src/main/java/com/github/ucchyocean/lc/japanize/JapanizeType.java index 96d50d6..fc2cc61 100644 --- a/src/main/java/com/github/ucchyocean/lc/japanize/JapanizeType.java +++ b/src/main/java/com/github/ucchyocean/lc/japanize/JapanizeType.java @@ -38,15 +38,17 @@ public enum JapanizeType { /** * 文字列表記からJapanizeTypeを作成して返す - * @param id + * @param id ID + * @param def デフォルト * @return */ - public static JapanizeType fromID(String id) { + public static JapanizeType fromID(String id, JapanizeType def) { + if ( id == null ) return def; for ( JapanizeType type : values() ) { if ( type.id.equalsIgnoreCase(id) ) { return type; } } - return NONE; + return def; } } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 276e1cf..570b5b0 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -150,6 +150,7 @@ errmsgToolongAlias: 'チャンネル別名は %d 文字以下にしてくださ errmsgToolongPassword: 'パスワードは %d 文字以下にしてください。' errmsgInvalidBooleanOption: '%s は true/false で指定してください。' errmsgInvalidRangeOption: 'range に正しくない値が指定されました。' +errmsgInvalidJapanizeOption: '%s に指定された %s は、Japanize変換タイプとして正しくありません。' errmsgCannotOffGlobalBroadcast: 'このチャンネルはグローバルチャンネルのため、ブロードキャストをオフにできません。' errmsgFormatConstraint: '必須キーワード %s が指定されていません。' errmsgInvalidBanExpireParameter: 'BAN期限(分)の指定が正しくありません。1 から 43200 の間の数値を指定してください。' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 61c0082..13ca6b1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -190,6 +190,9 @@ permissions: lunachat.option.allowcc: description: allowccオプション設定コマンドの使用権限 default: true + lunachat.option.japanize: + description: japanizeオプション設定コマンドの使用権限 + default: true lunachat.option.*: children: lunachat.option.description: true @@ -200,6 +203,7 @@ permissions: lunachat.option.password: true lunachat.option.visible: true lunachat.option.allowcc: true + lunachat.option.japanize: true description: オプション設定の全コマンドの使用権限 lunachat-admin.mod-all-channels: