LunaChat v2.6.8 : Fixed issue #104
このコミットが含まれているのは:
1 親
26ceb8db45
コミット
1fe273fa58
8ファイル変更
+312
検索条件に一致するファイルはありません
@@ -6,6 +6,7 @@
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@@ -115,6 +116,25 @@ public interface LunaChatAPI {
|
||||
*/
|
||||
public void removeTemplate(String id);
|
||||
|
||||
/**
|
||||
* 辞書データを全て取得する
|
||||
* @return 辞書データ
|
||||
*/
|
||||
public HashMap<String, String> getAllDictionary();
|
||||
|
||||
/**
|
||||
* 新しい辞書データを追加する
|
||||
* @param key キー
|
||||
* @param value 値
|
||||
*/
|
||||
public void setDictionary(String key, String value);
|
||||
|
||||
/**
|
||||
* 指定したキーの辞書データを削除する
|
||||
* @param key キー
|
||||
*/
|
||||
public void removeDictionary(String key);
|
||||
|
||||
/**
|
||||
* Japanize変換を行う
|
||||
* @param message 変換するメッセージ
|
||||
|
||||
@@ -33,14 +33,17 @@ public class ChannelManager implements LunaChatAPI {
|
||||
private static final String FILE_NAME_DCHANNELS = "defaults.yml";
|
||||
private static final String FILE_NAME_TEMPLATES = "templates.yml";
|
||||
private static final String FILE_NAME_JAPANIZE = "japanize.yml";
|
||||
private static final String FILE_NAME_DICTIONARY = "dictionary.yml";
|
||||
|
||||
private File fileDefaults;
|
||||
private File fileTemplates;
|
||||
private File fileJapanize;
|
||||
private File fileDictionary;
|
||||
private HashMap<String, Channel> channels;
|
||||
private HashMap<String, String> defaultChannels;
|
||||
private HashMap<String, String> templates;
|
||||
private HashMap<String, Boolean> japanize;
|
||||
private HashMap<String, String> dictionary;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
@@ -118,6 +121,26 @@ public class ChannelManager implements LunaChatAPI {
|
||||
japanize.put(key, configJapanize.getBoolean(key));
|
||||
}
|
||||
|
||||
// dictionaryのロード
|
||||
fileDictionary = new File(
|
||||
LunaChat.getInstance().getDataFolder(), FILE_NAME_DICTIONARY);
|
||||
if ( !fileDictionary.exists() ) {
|
||||
YamlConfiguration conf = new YamlConfiguration();
|
||||
try {
|
||||
conf.save(fileDictionary);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
YamlConfiguration configDictionary =
|
||||
YamlConfiguration.loadConfiguration(fileDictionary);
|
||||
|
||||
dictionary = new HashMap<String, String>();
|
||||
for ( String key : configDictionary.getKeys(false) ) {
|
||||
dictionary.put(key, configDictionary.getString(key));
|
||||
}
|
||||
|
||||
// チャンネル設定のロード
|
||||
channels = Channel.loadAllChannels();
|
||||
}
|
||||
@@ -191,6 +214,25 @@ public class ChannelManager implements LunaChatAPI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dictionary設定を保存する
|
||||
* @return 保存したかどうか
|
||||
*/
|
||||
private boolean saveDictionary() {
|
||||
|
||||
try {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
for ( String key : dictionary.keySet() ) {
|
||||
config.set(key, dictionary.get(key));
|
||||
}
|
||||
config.save(fileDictionary);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* デフォルトチャンネル設定を全て削除する
|
||||
*/
|
||||
@@ -436,6 +478,32 @@ public class ChannelManager implements LunaChatAPI {
|
||||
saveTemplates();
|
||||
}
|
||||
|
||||
/**
|
||||
* 辞書データを全て取得する
|
||||
* @return 辞書データ
|
||||
*/
|
||||
public HashMap<String, String> getAllDictionary() {
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新しい辞書データを追加する
|
||||
* @param key キー
|
||||
* @param value 値
|
||||
*/
|
||||
public void setDictionary(String key, String value) {
|
||||
dictionary.put(key, value);
|
||||
saveDictionary();
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定したキーの辞書データを削除する
|
||||
* @param key キー
|
||||
*/
|
||||
public void removeDictionary(String key) {
|
||||
dictionary.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize変換を行う
|
||||
* @param message 変換するメッセージ
|
||||
|
||||
@@ -94,6 +94,8 @@ public class DelayedJapanizeConvertTask extends BukkitRunnable {
|
||||
keywords.add(player.getName());
|
||||
}
|
||||
}
|
||||
HashMap<String, String> dictionary =
|
||||
LunaChat.getInstance().getLunaChatAPI().getAllDictionary();
|
||||
|
||||
// カラーコード削除、URL削除
|
||||
String deletedURL = Utility.stripColor(org.replaceAll(REGEX_URL, " "));
|
||||
@@ -109,6 +111,14 @@ public class DelayedJapanizeConvertTask extends BukkitRunnable {
|
||||
keywordMap.put(key, keyword);
|
||||
}
|
||||
}
|
||||
for ( String dickey : dictionary.keySet() ) {
|
||||
if ( keywordLocked.contains(dickey) ) {
|
||||
index++;
|
||||
String key = "<" + index + ">";
|
||||
keywordLocked = keywordLocked.replace(dickey, key);
|
||||
keywordMap.put(key, dictionary.get(dickey));
|
||||
}
|
||||
}
|
||||
|
||||
// カナ変換
|
||||
String japanized = KanaConverter.conv(keywordLocked);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2014
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* dictionaryコマンドのエイリアス実行クラス、名前のみが異なるが、他は全て一緒。
|
||||
* @author ucchy
|
||||
*/
|
||||
public class DicCommand extends DictionaryCommand {
|
||||
|
||||
private static final String COMMAND_NAME = "dic";
|
||||
private static final String USAGE_KEY = "usageDic";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @return コマンド
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#getCommandName()
|
||||
*/
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return COMMAND_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
CommandSender sender, String label) {
|
||||
sendResourceMessage(sender, "", USAGE_KEY, label);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2014
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* dictionaryコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class DictionaryCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "dictionary";
|
||||
private static final String PERMISSION_NODE = "lunachat-admin." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageDictionary";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @return コマンド
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#getCommandName()
|
||||
*/
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return COMMAND_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* パーミッションノードを取得します。
|
||||
* @return パーミッションノード
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#getPermissionNode()
|
||||
*/
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return PERMISSION_NODE;
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドの種別を取得します。
|
||||
* @return コマンド種別
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#getCommandType()
|
||||
*/
|
||||
@Override
|
||||
public CommandType getCommandType() {
|
||||
return CommandType.ADMIN;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
CommandSender sender, String label) {
|
||||
sendResourceMessage(sender, "", USAGE_KEY, label);
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドを実行します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @param args 実行時の引数
|
||||
* @return コマンドが実行されたかどうか
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#runCommand(java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean runCommand(CommandSender sender, String label, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
// このコマンドは、コンソールでも実行できる
|
||||
if ( args.length <= 1 ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
sendUsageMessage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !args[1].equalsIgnoreCase("add") &&
|
||||
!args[1].equalsIgnoreCase("remove") &&
|
||||
!args[1].equalsIgnoreCase("view") ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
sendUsageMessage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( args[1].equalsIgnoreCase("add") ) {
|
||||
|
||||
// addの場合は、さらに2つ引数が必要
|
||||
if ( args.length <= 3 ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
sendUsageMessage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
String key = args[2];
|
||||
String value = args[3];
|
||||
api.setDictionary(key, value);
|
||||
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgDictionaryAdd", key, value);
|
||||
return true;
|
||||
|
||||
} else if ( args[1].equalsIgnoreCase("remove") ) {
|
||||
|
||||
// removeの場合は、さらに1つ引数が必要
|
||||
if ( args.length <= 2 ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
sendUsageMessage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
String key = args[2];
|
||||
api.removeDictionary(key);
|
||||
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgDictionaryRemove", key);
|
||||
return true;
|
||||
|
||||
} else if ( args[1].equalsIgnoreCase("view") ) {
|
||||
|
||||
HashMap<String, String> dic = api.getAllDictionary();
|
||||
for ( String key : dic.keySet() ) {
|
||||
String value = dic.get(key);
|
||||
sender.sendMessage(key + ChatColor.GRAY + " -> " + ChatColor.WHITE + value);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -57,6 +57,8 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
commands.add(new FormatCommand());
|
||||
commands.add(new ModeratorCommand());
|
||||
commands.add(new ModCommand());
|
||||
commands.add(new DictionaryCommand());
|
||||
commands.add(new DicCommand());
|
||||
commands.add(new OptionCommand());
|
||||
commands.add(new TemplateCommand());
|
||||
commands.add(new CheckCommand());
|
||||
@@ -160,6 +162,32 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
}
|
||||
return items;
|
||||
|
||||
} else if ( args.length == 2 &&
|
||||
(args[0].equalsIgnoreCase("dic") || args[0].equalsIgnoreCase("dictionary")) ) {
|
||||
// add、remove、viewで補完する
|
||||
String arg = args[1].toLowerCase();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
for ( String name : new String[]{"add", "remove", "view"} ) {
|
||||
if ( name.toLowerCase().startsWith(arg) ) {
|
||||
items.add(name);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
|
||||
} else if ( args.length == 3 &&
|
||||
(args[0].equalsIgnoreCase("dic") || args[0].equalsIgnoreCase("dictionary")) &&
|
||||
args[1].equalsIgnoreCase("remove") ) {
|
||||
// 辞書に登録されているワードで補完する
|
||||
String arg = args[2].toLowerCase();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
for ( String name :
|
||||
LunaChat.getInstance().getLunaChatAPI().getAllDictionary().keySet() ) {
|
||||
if ( name.toLowerCase().startsWith(arg) ) {
|
||||
items.add(name);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする