LunaChat v3-k2 : Added BungeeCord implementation.
このコミットが含まれているのは:
1 親
5ddd0959d8
コミット
3027bedb10
26ファイル変更
+1247
-244
検索条件に一致するファイルはありません
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
/**
|
||||
* Event優先度列挙子(Bukkit用)
|
||||
* @author ucchy
|
||||
*/
|
||||
public enum EventPriority {
|
||||
|
||||
LOWEST,
|
||||
|
||||
LOW,
|
||||
|
||||
NORMAL,
|
||||
|
||||
HIGH,
|
||||
|
||||
HIGHEST,
|
||||
|
||||
MONITOR,
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class LunaChat extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
|
||||
// 変数などの初期化
|
||||
config = new LunaChatConfig();
|
||||
config = new LunaChatConfig(getDataFolder(), getFile());
|
||||
manager = new ChannelManager();
|
||||
normalChatLogger = new LunaChatLogger("==normalchat");
|
||||
|
||||
@@ -171,7 +171,7 @@ public class LunaChat extends JavaPlugin {
|
||||
* このプラグインのJarファイル自身を示すFileクラスを返す。
|
||||
* @return Jarファイル
|
||||
*/
|
||||
protected static File getPluginJarFile() {
|
||||
public static File getPluginJarFile() {
|
||||
return getInstance().getFile();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
|
||||
/**
|
||||
@@ -145,28 +142,37 @@ public class LunaChatConfig {
|
||||
* 隠し設定。 */
|
||||
private int japanizeWait;
|
||||
|
||||
// === 以下、BungeeCord用設定 ===
|
||||
|
||||
/** 通常チャットを全サーバーにブロードキャストするかどうか */
|
||||
private boolean broadcastChat;
|
||||
|
||||
/** 通常チャットを全サーバーにブロードキャストする場合のフォーマット */
|
||||
private String broadcastChatFormat;
|
||||
|
||||
/** 通常チャットを全サーバーにブロードキャストする場合に、発言者サーバーのチャット内容もJapanize化するかどうか */
|
||||
private boolean broadcastChatLocalJapanize;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param dataFolder コンフィグ格納フォルダ
|
||||
* @param jarFile プラグインJarファイル
|
||||
*/
|
||||
protected LunaChatConfig() {
|
||||
reloadConfig();
|
||||
public LunaChatConfig(File dataFolder, File jarFile) {
|
||||
reloadConfig(dataFolder, jarFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* config.yml を再読み込みする
|
||||
*/
|
||||
public void reloadConfig() {
|
||||
public void reloadConfig(File dataFolder, File jarFile) {
|
||||
|
||||
File configFile = new File(
|
||||
LunaChat.getInstance().getDataFolder(), "config.yml");
|
||||
File configFile = new File(dataFolder, "config.yml");
|
||||
if ( !configFile.exists() ) {
|
||||
//LunaChat.instance.saveDefaultConfig();
|
||||
Utility.copyFileFromJar(LunaChat.getPluginJarFile(),
|
||||
configFile, "config_ja.yml", false);
|
||||
Utility.copyFileFromJar(jarFile, configFile, "config_ja.yml", false);
|
||||
}
|
||||
|
||||
LunaChat.getInstance().reloadConfig();
|
||||
FileConfiguration config = LunaChat.getInstance().getConfig();
|
||||
YamlConfig config = YamlConfig.load(configFile);
|
||||
|
||||
enableChannelChat = config.getBoolean("enableChannelChat", true);
|
||||
playerChatEventListenerPriority
|
||||
@@ -250,12 +256,23 @@ public class LunaChatConfig {
|
||||
noneJapanizeMarker = config.getString("noneJapanizeMarker", "#");
|
||||
japanizeWait = config.getInt("japanizeWait", 1);
|
||||
|
||||
broadcastChat = config.getBoolean("broadcastChat", true);
|
||||
|
||||
broadcastChatFormat =
|
||||
config.getString("broadcastChatFormat",
|
||||
"%date %time &d<%sender@%senderserver> &f%msg");
|
||||
|
||||
broadcastChatLocalJapanize =
|
||||
config.getBoolean("broadcastChatLocalJapanize", true);
|
||||
|
||||
// globalチャンネルが、使用可能なチャンネル名かどうかを調べる
|
||||
if ( globalChannel != null && !globalChannel.equals("") &&
|
||||
!globalChannel.matches("[0-9a-zA-Z\\-_]{1,20}") ) {
|
||||
String msg = String.format(
|
||||
Resources.get("errmsgCannotUseForGlobal"), globalChannel);
|
||||
LunaChat.getInstance().getLogger().warning(msg);
|
||||
|
||||
// TODO コンソールに警告を表示する
|
||||
// String msg = String.format(
|
||||
// Resources.get("errmsgCannotUseForGlobal"), globalChannel);
|
||||
// LunaChat.getInstance().getLogger().warning(msg);
|
||||
globalChannel = "";
|
||||
}
|
||||
}
|
||||
@@ -569,6 +586,30 @@ public class LunaChatConfig {
|
||||
return enableNormalChatColorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットを全サーバーにブロードキャストするかどうか
|
||||
* @return broadcastChatを返す
|
||||
*/
|
||||
public boolean isBroadcastChat() {
|
||||
return broadcastChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットを全サーバーにブロードキャストする場合のフォーマット
|
||||
* @return broadcastChatFormatを返す
|
||||
*/
|
||||
public String getBroadcastChatFormat() {
|
||||
return broadcastChatFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットを全サーバーにブロードキャストする場合に、発言者サーバーのチャット内容もJapanize化するかどうか
|
||||
* @return broadcastChatLocalJapanizeを返す
|
||||
*/
|
||||
public boolean isBroadcastChatLocalJapanize() {
|
||||
return broadcastChatLocalJapanize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された文字列から、対応するEventPriorityを返す。
|
||||
* @param value 文字列
|
||||
|
||||
@@ -60,7 +60,7 @@ public class PlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.LOWEST, ignoreCancelled=true)
|
||||
public void onAsyncPlayerChatLowest(AsyncPlayerChatEvent event) {
|
||||
if ( LunaChat.getInstance().getLunaChatConfig().getPlayerChatEventListenerPriority() == EventPriority.LOWEST ) {
|
||||
if ( matchesEventPriority(EventPriority.LOWEST) ) {
|
||||
processChatEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class PlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.LOW, ignoreCancelled=true)
|
||||
public void onAsyncPlayerChatLow(AsyncPlayerChatEvent event) {
|
||||
if ( LunaChat.getInstance().getLunaChatConfig().getPlayerChatEventListenerPriority() == EventPriority.LOW ) {
|
||||
if ( matchesEventPriority(EventPriority.LOW) ) {
|
||||
processChatEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class PlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=true)
|
||||
public void onAsyncPlayerChatNormal(AsyncPlayerChatEvent event) {
|
||||
if ( LunaChat.getInstance().getLunaChatConfig().getPlayerChatEventListenerPriority() == EventPriority.NORMAL ) {
|
||||
if ( matchesEventPriority(EventPriority.NORMAL) ) {
|
||||
processChatEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class PlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
|
||||
public void onAsyncPlayerChatHigh(AsyncPlayerChatEvent event) {
|
||||
if ( LunaChat.getInstance().getLunaChatConfig().getPlayerChatEventListenerPriority() == EventPriority.HIGH ) {
|
||||
if ( matchesEventPriority(EventPriority.HIGH) ) {
|
||||
processChatEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class PlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
|
||||
public void onAsyncPlayerChatHighest(AsyncPlayerChatEvent event) {
|
||||
if ( LunaChat.getInstance().getLunaChatConfig().getPlayerChatEventListenerPriority() == EventPriority.HIGHEST ) {
|
||||
if ( matchesEventPriority(EventPriority.HIGHEST) ) {
|
||||
processChatEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -339,7 +339,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
// 2byteコードを含むなら、Japanize変換は行わない
|
||||
String kanaTemp = Utility.stripColor(message);
|
||||
String kanaTemp = Utility.stripColorCode(message);
|
||||
if ( !skipJapanize &&
|
||||
( kanaTemp.getBytes().length > kanaTemp.length() ||
|
||||
kanaTemp.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
@@ -601,4 +601,14 @@ public class PlayerListener implements Listener {
|
||||
String msg = String.format(pre + org, args);
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたEventPriorityが、LunaChatConfigで指定されているEventPriorityと一致するかどうかを調べる
|
||||
* @param priority
|
||||
* @return 一致するかどうか
|
||||
*/
|
||||
private boolean matchesEventPriority(EventPriority priority) {
|
||||
String c = LunaChat.getInstance().getLunaChatConfig().getPlayerChatEventListenerPriority().name();
|
||||
return c.equals(priority.name());
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
/**
|
||||
@@ -23,10 +22,6 @@ import java.util.zip.ZipEntry;
|
||||
*/
|
||||
public class Utility {
|
||||
|
||||
public static final char COLOR_CHAR = '\u00A7';
|
||||
private static final Pattern STRIP_COLOR_PATTERN =
|
||||
Pattern.compile("(?i)" + String.valueOf(COLOR_CHAR) + "[0-9A-FK-OR]");
|
||||
|
||||
/**
|
||||
* jarファイルの中に格納されているファイルを、jarファイルの外にコピーするメソッド
|
||||
* @param jarFile jarファイル
|
||||
@@ -80,14 +75,7 @@ public class Utility {
|
||||
*/
|
||||
public static String replaceColorCode(String source) {
|
||||
if (source == null) return null;
|
||||
char[] b = source.toCharArray();
|
||||
for (int i = 0; i < b.length - 1; i++) {
|
||||
if (b[i] == '&' && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1) {
|
||||
b[i] = COLOR_CHAR;
|
||||
b[i + 1] = Character.toLowerCase(b[i + 1]);
|
||||
}
|
||||
}
|
||||
return new String(b);
|
||||
return source.replaceAll("&([0-9a-fk-or])", "\u00A7$1");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,9 +83,9 @@ public class Utility {
|
||||
* @param source 置き換え元の文字列
|
||||
* @return 置き換え後の文字列
|
||||
*/
|
||||
public static String stripColor(String source) {
|
||||
public static String stripColorCode(String source) {
|
||||
if (source == null) return null;
|
||||
return STRIP_COLOR_PATTERN.matcher(source).replaceAll("");
|
||||
return source.replaceAll("&([0-9a-fk-or])", "");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,9 +95,18 @@ public class Utility {
|
||||
*/
|
||||
public static boolean isColorCode(String code) {
|
||||
if (code == null) return false;
|
||||
return code.matches(COLOR_CHAR + "[0-9a-fA-F]");
|
||||
return code.matches("\u00A7[0-9a-fk-orA-FK-OR]");
|
||||
}
|
||||
|
||||
/**
|
||||
* カラーコード候補(&a)かどうかを判断する
|
||||
* @param color カラーコード候補
|
||||
* @return カラーコード候補かどうか
|
||||
*/
|
||||
public static boolean isAltColorCode(String code) {
|
||||
if (code == null) return false;
|
||||
return code.matches("&[0-9a-fk-orA-FK-OR]");
|
||||
}
|
||||
/**
|
||||
* 指定された文字数のアスタリスクの文字列を返す
|
||||
* @param length アスタリスクの個数
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Bukkit関連のユーティリティクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class UtilityBukkit {
|
||||
|
||||
/**
|
||||
* 現在接続中のプレイヤーを全て取得する
|
||||
* @return 接続中の全てのプレイヤー
|
||||
*/
|
||||
public static Collection<? extends Player> getOnlinePlayers() {
|
||||
return Bukkit.getOnlinePlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* 現在のサーバー接続人数を返します。
|
||||
* @return サーバー接続人数
|
||||
*/
|
||||
public static int getOnlinePlayersCount() {
|
||||
return getOnlinePlayers().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* ChatColorで指定可能な色かどうかを判断する
|
||||
* @param color カラー表記の文字列
|
||||
* @return 指定可能かどうか
|
||||
*/
|
||||
public static boolean isValidColor(String color) {
|
||||
if ( color == null ) return false;
|
||||
for (ChatColor c : ChatColor.values()) {
|
||||
if (c.name().equals(color.toUpperCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* カラー表記の文字列を、カラーコードに変換する
|
||||
* @param color カラー表記の文字列
|
||||
* @return カラーコード
|
||||
*/
|
||||
public static String changeToColorCode(String color) {
|
||||
|
||||
return "&" + changeToChatColor(color).getChar();
|
||||
}
|
||||
|
||||
/**
|
||||
* カラー表記の文字列を、ChatColorクラスに変換する
|
||||
* @param color カラー表記の文字列
|
||||
* @return ChatColorクラス
|
||||
*/
|
||||
public static ChatColor changeToChatColor(String color) {
|
||||
|
||||
if (isValidColor(color)) {
|
||||
return ChatColor.valueOf(color.toUpperCase());
|
||||
}
|
||||
return ChatColor.WHITE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された名前のオフラインプレイヤーを取得する
|
||||
* @param name プレイヤー名
|
||||
* @return オフラインプレイヤー
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static OfflinePlayer getOfflinePlayer(String name) {
|
||||
if (name == null) return null;
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
|
||||
if (player == null || (!player.hasPlayedBefore() && !player.isOnline()))
|
||||
return null;
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された名前のプレイヤーを取得する
|
||||
* @param name プレイヤー名
|
||||
* @return プレイヤー
|
||||
*/
|
||||
public static Player getPlayerExact(String name) {
|
||||
return Bukkit.getPlayer(Utility.stripColorCode(name));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
/**
|
||||
* Yaml設定読み書きユーティリティクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class YamlConfig {
|
||||
|
||||
private Map<String, Object> map = new HashMap<>();
|
||||
private Map<String, Object> defaults = new HashMap<>();
|
||||
|
||||
public static YamlConfig load(InputStream stream) throws IOException {
|
||||
|
||||
YamlConfig config = new YamlConfig();
|
||||
if ( stream == null ) return config;
|
||||
|
||||
Yaml yaml = new Yaml();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = yaml.loadAs(stream, Map.class);
|
||||
if ( map == null ) {
|
||||
throw new IOException("Cannot load stream as yaml.");
|
||||
}
|
||||
|
||||
config.map = map;
|
||||
return config;
|
||||
}
|
||||
|
||||
public static YamlConfig load(Reader reader) throws IOException {
|
||||
|
||||
YamlConfig config = new YamlConfig();
|
||||
if ( reader == null ) return config;
|
||||
|
||||
Yaml yaml = new Yaml();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = yaml.loadAs(reader, Map.class);
|
||||
if ( map == null ) {
|
||||
throw new IOException("Cannot load reader as yaml.");
|
||||
}
|
||||
|
||||
config.map = map;
|
||||
return config;
|
||||
}
|
||||
|
||||
public static YamlConfig load(File file) {
|
||||
try ( FileReader reader = new FileReader(file) ) {
|
||||
return load(reader);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void save(File file) throws IOException {
|
||||
|
||||
Yaml yaml = new Yaml();
|
||||
String data = yaml.dumpAsMap(map);
|
||||
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
|
||||
writer.write(data);
|
||||
}
|
||||
}
|
||||
|
||||
public String getRawData() {
|
||||
Yaml yaml = new Yaml();
|
||||
return yaml.dumpAsMap(map);
|
||||
}
|
||||
|
||||
public void set(String key, Object value) {
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
public Object get(String key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key) {
|
||||
return getBoolean(key, false);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key, boolean defaultValue) {
|
||||
Object val = map.getOrDefault(key, defaults.get(key));
|
||||
return ( val != null && val instanceof Boolean ) ? (boolean)val : defaultValue;
|
||||
}
|
||||
|
||||
public int getInt(String key) {
|
||||
return getInt(key, 0);
|
||||
}
|
||||
|
||||
public int getInt(String key, int defaultValue) {
|
||||
Object val = map.getOrDefault(key, defaults.get(key));
|
||||
return ( val != null && val instanceof Integer ) ? (int)val : defaultValue;
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
return getString(key, null);
|
||||
}
|
||||
|
||||
public String getString(String key, String defaultValue) {
|
||||
Object val = map.getOrDefault(key, defaults.get(key));
|
||||
return ( val != null ) ? val.toString() : null;
|
||||
}
|
||||
|
||||
public List<String> getStringList(String key) {
|
||||
return getStringList(key, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> getStringList(String key, ArrayList<String> defaultValue) {
|
||||
Object val = map.getOrDefault(key, defaults.get(key));
|
||||
return ( val != null && val instanceof ArrayList<?> ) ? (List<String>)val : null;
|
||||
}
|
||||
|
||||
public boolean contains(String key) {
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
public Set<String> getKeys(boolean deeps) {
|
||||
if ( !deeps ) {
|
||||
return map.keySet();
|
||||
} else {
|
||||
// TODO 未実装
|
||||
return map.keySet();
|
||||
}
|
||||
}
|
||||
|
||||
public void addDefaults(YamlConfig defaults) {
|
||||
this.defaults = defaults.map;
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class McMMOBridge implements Listener {
|
||||
}
|
||||
|
||||
// 2byteコードを含むなら、Japanize変換は行わない
|
||||
String kanaTemp = Utility.stripColor(message);
|
||||
String kanaTemp = Utility.stripColorCode(message);
|
||||
if ( !skipJapanize &&
|
||||
( kanaTemp.getBytes().length > kanaTemp.length() ||
|
||||
kanaTemp.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bungee;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
/**
|
||||
* BungeeJapanizeMessengerのdictionaryコマンド実装クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class DictionaryCommand extends Command {
|
||||
|
||||
private LunaChatBungee parent;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param parent
|
||||
* @param name コマンド
|
||||
*/
|
||||
public DictionaryCommand(LunaChatBungee parent, String name) {
|
||||
super(name);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドが実行された時に呼び出されるメソッド
|
||||
* @param sender コマンド実行者
|
||||
* @param args コマンド引数
|
||||
* @see net.md_5.bungee.api.plugin.Command#execute(net.md_5.bungee.api.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
|
||||
// パーミッションチェック
|
||||
if ( !sender.hasPermission("bungeejapanizemessenger.dictionary") ) {
|
||||
sendMessage(sender, "コマンドの実行権限がありません。");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( args.length >= 3 && args[0].equalsIgnoreCase("add") ) {
|
||||
|
||||
parent.getDictionary().put(args[1], args[2]);
|
||||
String message = String.format("[BJM日本語変換] %s を %s と覚えました。", args[1], args[2]);
|
||||
parent.getProxy().broadcast(TextComponent.fromLegacyText(message));
|
||||
return;
|
||||
|
||||
} else if ( args.length >= 2 && args[0].equalsIgnoreCase("remove") ) {
|
||||
|
||||
parent.getDictionary().remove(args[1]);
|
||||
String message = String.format("[BJM日本語変換] %s を辞書から削除しました。", args[1]);
|
||||
parent.getProxy().broadcast(TextComponent.fromLegacyText(message));
|
||||
return;
|
||||
|
||||
} else if ( args.length >= 1 && args[0].equalsIgnoreCase("view") ) {
|
||||
|
||||
HashMap<String, String> dictionary = parent.getDictionary().getDictionary();
|
||||
for ( String key : dictionary.keySet() ) {
|
||||
String value = dictionary.get(key);
|
||||
sendMessage(sender, key + ChatColor.GRAY + " -> " + ChatColor.WHITE + value);
|
||||
}
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
sendMessage(sender, "日本語変換の辞書登録コマンド:");
|
||||
sendMessage(sender, "/dic add (辞書登録する単語) (変換後の単語) - 新しい単語を登録する。");
|
||||
sendMessage(sender, "/dic remove (辞書から削除する単語) - 単語を辞書から削除する。");
|
||||
sendMessage(sender, "/dic view - 辞書に登録されている単語一覧を参照する。");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定した対象にメッセージを送信する
|
||||
* @param reciever 送信先
|
||||
* @param message メッセージ
|
||||
*/
|
||||
protected void sendMessage(CommandSender reciever, String message) {
|
||||
if ( message == null ) return;
|
||||
reciever.sendMessage(TextComponent.fromLegacyText(message));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bungee;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
||||
/**
|
||||
* Japanize変換に使用するユーザー辞書
|
||||
* @author ucchy
|
||||
*/
|
||||
public class JapanizeDictionary {
|
||||
|
||||
private LunaChatBungee parent;
|
||||
private HashMap<String, String> dictionary;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param parent
|
||||
*/
|
||||
public JapanizeDictionary(LunaChatBungee parent) {
|
||||
this.parent = parent;
|
||||
reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* ファイルから設定を読み直す
|
||||
*/
|
||||
public void reload() {
|
||||
|
||||
dictionary = new HashMap<String, String>();
|
||||
|
||||
// Fileを取得
|
||||
File folder = new File(
|
||||
parent.getProxy().getPluginsFolder(),
|
||||
"BungeeJapanizeMessenger");
|
||||
if ( !folder.exists() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
File file = new File(folder, "dictionary.yml");
|
||||
if ( !file.exists() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigurationProvider provider =
|
||||
ConfigurationProvider.getProvider(YamlConfiguration.class);
|
||||
try {
|
||||
Configuration config = provider.load(file);
|
||||
|
||||
for ( String key : config.getKeys() ) {
|
||||
dictionary.put(key, config.getString(key));
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ファイルに保存する
|
||||
*/
|
||||
public void save() {
|
||||
|
||||
Configuration config = new Configuration();
|
||||
|
||||
for ( String key : dictionary.keySet() ) {
|
||||
config.set(key, dictionary.get(key));
|
||||
}
|
||||
|
||||
File folder = new File(
|
||||
parent.getProxy().getPluginsFolder(),
|
||||
"BungeeJapanizeMessenger");
|
||||
ConfigurationProvider provider =
|
||||
ConfigurationProvider.getProvider(YamlConfiguration.class);
|
||||
try {
|
||||
provider.save(config, new File(folder, "dictionary.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 辞書に単語を登録する
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void put(String key, String value) {
|
||||
dictionary.put(key, value);
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 辞書から単語を消去する
|
||||
* @param key
|
||||
*/
|
||||
public void remove(String key) {
|
||||
dictionary.remove(key);
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 全てのデータを返す
|
||||
* @return dictionary
|
||||
*/
|
||||
public HashMap<String, String> getDictionary() {
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bungee;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.japanize.Japanizer;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
/**
|
||||
* LunaChatのBungeeCord実装
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatBungee extends Plugin implements Listener {
|
||||
|
||||
private static final String DATE_FORMAT_PATTERN = "yyyy/MM/dd";
|
||||
private static final String TIME_FORMAT_PATTERN = "HH:mm:ss";
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
|
||||
private HashMap<String, String> history;
|
||||
private LunaChatConfig config;
|
||||
private JapanizeDictionary dictionary;
|
||||
|
||||
/**
|
||||
* プラグインが有効化されたときに呼び出されるメソッド
|
||||
* @see net.md_5.bungee.api.plugin.Plugin#onEnable()
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
// 初期化
|
||||
history = new HashMap<String, String>();
|
||||
dateFormat = new SimpleDateFormat(DATE_FORMAT_PATTERN);
|
||||
timeFormat = new SimpleDateFormat(TIME_FORMAT_PATTERN);
|
||||
|
||||
// コマンド登録
|
||||
for ( String command : new String[]{
|
||||
"tell", "msg", "message", "m", "w", "t"}) {
|
||||
getProxy().getPluginManager().registerCommand(
|
||||
this, new TellCommand(this, command));
|
||||
}
|
||||
for ( String command : new String[]{"reply", "r"}) {
|
||||
getProxy().getPluginManager().registerCommand(
|
||||
this, new ReplyCommand(this, command));
|
||||
}
|
||||
for ( String command : new String[]{"dictionary", "dic"}) {
|
||||
getProxy().getPluginManager().registerCommand(
|
||||
this, new DictionaryCommand(this, command));
|
||||
}
|
||||
|
||||
// コンフィグ取得
|
||||
config = new LunaChatConfig(getDataFolder(), getFile());
|
||||
|
||||
// 辞書取得
|
||||
dictionary = new JapanizeDictionary(this);
|
||||
|
||||
// リスナー登録
|
||||
getProxy().getPluginManager().registerListener(this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* コンフィグを返す
|
||||
* @return コンフィグ
|
||||
*/
|
||||
public LunaChatConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 辞書を返す
|
||||
* @return 辞書
|
||||
*/
|
||||
public JapanizeDictionary getDictionary() {
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
/**
|
||||
* プライベートメッセージの受信履歴を記録する
|
||||
* @param reciever 受信者
|
||||
* @param sender 送信者
|
||||
*/
|
||||
protected void putHistory(String reciever, String sender) {
|
||||
history.put(reciever, sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* プライベートメッセージの受信履歴を取得する
|
||||
* @param reciever 受信者
|
||||
* @return 送信者
|
||||
*/
|
||||
protected String getHistory(String reciever) {
|
||||
return history.get(reciever);
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーがチャット発言した時に呼び出されるメソッド
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onChat(ChatEvent event) {
|
||||
|
||||
// 設定が無効なら、そのまま無視する
|
||||
if ( !config.isBroadcastChat() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// コマンド実行の場合は、そのまま無視する
|
||||
if ( event.isCommand() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// プレイヤーの発言ではない場合は、そのまま無視する
|
||||
if ( !(event.getSender() instanceof ProxiedPlayer) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 発言者と発言サーバーと発言内容の取得
|
||||
final ProxiedPlayer sender = (ProxiedPlayer)event.getSender();
|
||||
String senderServer = sender.getServer().getInfo().getName();
|
||||
String message = event.getMessage();
|
||||
|
||||
// NGワードのマスク
|
||||
message = maskNGWord(message, config.getNgwordCompiled());
|
||||
|
||||
// Japanizeの付加
|
||||
if ( message.startsWith(config.getNoneJapanizeMarker()) ) {
|
||||
|
||||
message = message.substring(config.getNoneJapanizeMarker().length());
|
||||
|
||||
} else {
|
||||
|
||||
String japanize = Japanizer.japanize(message, config.getJapanizeType(),
|
||||
dictionary.getDictionary());
|
||||
if ( japanize.length() > 0 ) {
|
||||
|
||||
// NGワードのマスク
|
||||
japanize = maskNGWord(japanize, config.getNgwordCompiled());
|
||||
|
||||
// フォーマット化してメッセージを上書きする
|
||||
String japanizeFormat = config.getJapanizeDisplayLine() == 1 ?
|
||||
config.getJapanizeLine1Format() :
|
||||
"%msg\n" + config.getJapanizeLine2Format();
|
||||
String preMessage = new String(message);
|
||||
message = japanizeFormat.replace("%msg", preMessage).replace("%japanize", japanize);
|
||||
}
|
||||
}
|
||||
|
||||
// フォーマットの置き換え処理
|
||||
String result = config.getBroadcastChatFormat();
|
||||
result = result.replace("%senderserver", senderServer);
|
||||
result = result.replace("%sender", sender.getName());
|
||||
if ( result.contains("%date") ) {
|
||||
result = result.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( result.contains("%time") ) {
|
||||
result = result.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
result = result.replace("%msg", message);
|
||||
result = Utility.replaceColorCode(result);
|
||||
|
||||
// 発言したプレイヤーがいるサーバー"以外"のサーバーに、
|
||||
// 発言内容を送信する。
|
||||
for ( String server : getProxy().getServers().keySet() ) {
|
||||
|
||||
if ( server.equals(senderServer) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ServerInfo info = getProxy().getServerInfo(server);
|
||||
for ( ProxiedPlayer player : info.getPlayers() ) {
|
||||
sendMessage(player, result);
|
||||
}
|
||||
}
|
||||
|
||||
// ローカルも置き換える処理なら、置換えを行う
|
||||
if ( config.isBroadcastChatLocalJapanize() ) {
|
||||
|
||||
// NOTE: 改行がサポートされないので、改行を含む場合は、
|
||||
// \nで分割して前半をセットし、後半は150ミリ秒後に送信する。
|
||||
if ( !message.contains("\n") ) {
|
||||
event.setMessage(Utility.stripColorCode(message));
|
||||
} else {
|
||||
int index = message.indexOf("\n");
|
||||
String pre = message.substring(0, index);
|
||||
final String post = Utility.replaceColorCode(
|
||||
message.substring(index + "\n".length()));
|
||||
event.setMessage(Utility.stripColorCode(pre));
|
||||
getProxy().getScheduler().schedule(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for ( ProxiedPlayer p : sender.getServer().getInfo().getPlayers() ) {
|
||||
sendMessage(p, post);
|
||||
}
|
||||
}
|
||||
}, 150, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
// コンソールに表示設定なら、コンソールに表示する
|
||||
if ( config.isDisplayChatOnConsole() ) {
|
||||
getLogger().info(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NGワードをマスクする
|
||||
* @param message メッセージ
|
||||
* @param ngwords NGワード
|
||||
* @return マスクされたメッセージ
|
||||
*/
|
||||
private String maskNGWord(String message, List<Pattern> ngwords) {
|
||||
for ( Pattern pattern : ngwords ) {
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
if ( matcher.find() ) {
|
||||
message = matcher.replaceAll(
|
||||
Utility.getAstariskString(matcher.group(0).length()));
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定した対象にメッセージを送信する
|
||||
* @param reciever 送信先
|
||||
* @param message メッセージ
|
||||
*/
|
||||
protected void sendMessage(CommandSender reciever, String message) {
|
||||
if ( message == null ) return;
|
||||
reciever.sendMessage(TextComponent.fromLegacyText(message));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bungee;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
/**
|
||||
* BungeeJapanizeMessengerのreplyコマンド実装クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ReplyCommand extends TellCommand {
|
||||
|
||||
private LunaChatBungee parent;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param BungeeJapanizeMessenger
|
||||
* @param name コマンド
|
||||
*/
|
||||
public ReplyCommand(LunaChatBungee parent, String name) {
|
||||
super(parent, name);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドが実行された時に呼び出されるメソッド
|
||||
* @param sender コマンド実行者
|
||||
* @param args コマンド引数
|
||||
* @see net.md_5.bungee.api.plugin.Command#execute(net.md_5.bungee.api.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
|
||||
String recieverName = parent.getHistory(sender.getName());
|
||||
|
||||
// 引数が無いときは、現在の会話相手を表示して終了する。
|
||||
if ( args.length == 0 ) {
|
||||
if ( recieverName != null ) {
|
||||
sendMessage(sender, ChatColor.LIGHT_PURPLE +
|
||||
"現在の会話相手: " + recieverName);
|
||||
} else {
|
||||
sendMessage(sender, ChatColor.LIGHT_PURPLE +
|
||||
"現在の会話相手は設定されていません。");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 送信先プレイヤーの取得。取得できないならエラーを表示して終了する。
|
||||
if ( recieverName == null ) {
|
||||
sendMessage(sender, ChatColor.RED +
|
||||
"メッセージ送信先が見つかりません。");
|
||||
return;
|
||||
}
|
||||
ProxiedPlayer reciever = parent.getProxy().getPlayer(
|
||||
parent.getHistory(sender.getName()));
|
||||
if ( reciever == null ) {
|
||||
sendMessage(sender, ChatColor.RED +
|
||||
"メッセージ送信先" + recieverName + "が見つかりません。");
|
||||
return;
|
||||
}
|
||||
|
||||
// 送信メッセージの作成
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
str.append(args[i] + " ");
|
||||
}
|
||||
String message = str.toString().trim();
|
||||
|
||||
// 送信
|
||||
sendPrivateMessage(sender, reciever, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bungee;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.japanize.Japanizer;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
/**
|
||||
* BungeeJapanizeMessengerのtellコマンド実装クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class TellCommand extends Command {
|
||||
|
||||
private LunaChatBungee parent;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param parent
|
||||
* @param name コマンド
|
||||
*/
|
||||
public TellCommand(LunaChatBungee parent, String name) {
|
||||
super(name);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドが実行された時に呼び出されるメソッド
|
||||
* @param sender コマンド実行者
|
||||
* @param args コマンド引数
|
||||
* @see net.md_5.bungee.api.plugin.Command#execute(net.md_5.bungee.api.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
|
||||
// 引数が足らないので、Usageを表示して終了する。
|
||||
if ( args.length <= 1 ) {
|
||||
sendMessage(sender, ChatColor.RED +
|
||||
"実行例: /" + this.getName() + " <player> <message>");
|
||||
return;
|
||||
}
|
||||
|
||||
// 自分自身には送信できない。
|
||||
if ( args[0].equals(sender.getName()) ) {
|
||||
sendMessage(sender, ChatColor.RED +
|
||||
"自分自身にはプライベートメッセージを送信することができません。");
|
||||
return;
|
||||
}
|
||||
|
||||
// 送信先プレイヤーの取得。取得できないならエラーを表示して終了する。
|
||||
ProxiedPlayer reciever = parent.getProxy().getPlayer(args[0]);
|
||||
if ( reciever == null ) {
|
||||
sendMessage(sender, ChatColor.RED +
|
||||
"メッセージ送信先 " + args[0] + " が見つかりません。");
|
||||
return;
|
||||
}
|
||||
|
||||
// 送信メッセージの作成
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
str.append(args[i] + " ");
|
||||
}
|
||||
String message = str.toString().trim();
|
||||
|
||||
// 送信
|
||||
sendPrivateMessage(sender, reciever, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* プライベートメッセージを送信する
|
||||
* @param sender 送信者
|
||||
* @param receiver 受信者名
|
||||
* @param message メッセージ
|
||||
*/
|
||||
protected void sendPrivateMessage(CommandSender sender, ProxiedPlayer reciever, String message) {
|
||||
|
||||
LunaChatConfig config = parent.getConfig();
|
||||
|
||||
// NGワードのマスク
|
||||
message = maskNGWord(message, config.getNgwordCompiled());
|
||||
|
||||
// Japanizeの付加
|
||||
if ( message.startsWith(config.getNoneJapanizeMarker()) ) {
|
||||
|
||||
message = message.substring(config.getNoneJapanizeMarker().length());
|
||||
|
||||
} else {
|
||||
|
||||
String japanize = Japanizer.japanize(message, config.getJapanizeType(),
|
||||
parent.getDictionary().getDictionary());
|
||||
if ( japanize.length() > 0 ) {
|
||||
|
||||
// NGワードのマスク
|
||||
japanize = maskNGWord(japanize, config.getNgwordCompiled());
|
||||
|
||||
// フォーマット化してメッセージを上書きする
|
||||
String japanizeFormat = config.getJapanizeDisplayLine() == 1 ?
|
||||
config.getJapanizeLine1Format() :
|
||||
"%msg\n" + config.getJapanizeLine2Format();
|
||||
String preMessage = new String(message);
|
||||
message = japanizeFormat.replace("%msg", preMessage).replace("%japanize", japanize);
|
||||
}
|
||||
}
|
||||
|
||||
// フォーマットの適用
|
||||
String senderServer = "";
|
||||
if ( sender instanceof ProxiedPlayer ) {
|
||||
senderServer = ((ProxiedPlayer)sender).getServer().getInfo().getName();
|
||||
}
|
||||
String result = new String(
|
||||
parent.getConfig().getDefaultFormatForPrivateMessage());
|
||||
result = result.replace("%senderserver", senderServer);
|
||||
result = result.replace("%sender", sender.getName());
|
||||
result = result.replace("%recieverserver",
|
||||
reciever.getServer().getInfo().getName());
|
||||
result = result.replace("%reciever", reciever.getName());
|
||||
result = result.replace("%msg", message);
|
||||
|
||||
// カラーコードの置き換え
|
||||
result = Utility.replaceColorCode(result);
|
||||
|
||||
// メッセージ送信
|
||||
sendMessage(sender, result);
|
||||
sendMessage(reciever, result);
|
||||
|
||||
// 送信履歴を記録
|
||||
parent.putHistory(reciever.getName(), sender.getName());
|
||||
|
||||
// コンソールに表示設定なら、コンソールに表示する
|
||||
if ( config.isDisplayChatOnConsole() ) {
|
||||
parent.getLogger().info(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NGワードをマスクする
|
||||
* @param message メッセージ
|
||||
* @param ngwords NGワード
|
||||
* @return マスクされたメッセージ
|
||||
*/
|
||||
private String maskNGWord(String message, List<Pattern> ngwords) {
|
||||
for ( Pattern pattern : ngwords ) {
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
if ( matcher.find() ) {
|
||||
message = matcher.replaceAll(
|
||||
Utility.getAstariskString(matcher.group(0).length()));
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定した対象にメッセージを送信する
|
||||
* @param reciever 送信先
|
||||
* @param message メッセージ
|
||||
*/
|
||||
protected void sendMessage(CommandSender reciever, String message) {
|
||||
if ( message == null ) return;
|
||||
reciever.sendMessage(TextComponent.fromLegacyText(message));
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ public class BukkitChannel extends Channel {
|
||||
maskedMessage = event.getNgMaskedMessage();
|
||||
|
||||
// 2byteコードを含むか、半角カタカナのみなら、Japanize変換は行わない
|
||||
String kanaTemp = Utility.stripColor(maskedMessage);
|
||||
String kanaTemp = Utility.stripColorCode(maskedMessage);
|
||||
if ( !skipJapanize &&
|
||||
( kanaTemp.getBytes().length > kanaTemp.length() ||
|
||||
kanaTemp.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.bukkit.entity.Player;
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.UtilityBukkit;
|
||||
import com.github.ucchyocean.lc.event.LunaChatChannelMemberChangedEvent;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
|
||||
@@ -395,7 +395,7 @@ public abstract class Channel implements ConfigurationSerializable {
|
||||
|
||||
// ブロードキャストチャンネルならサーバー接続人数を返す
|
||||
if ( isBroadcastChannel() ) {
|
||||
return Utility.getOnlinePlayersCount();
|
||||
return UtilityBukkit.getOnlinePlayersCount();
|
||||
}
|
||||
|
||||
// メンバーの人数を数える
|
||||
@@ -416,7 +416,7 @@ public abstract class Channel implements ConfigurationSerializable {
|
||||
|
||||
// ブロードキャストチャンネルならサーバー接続人数を返す
|
||||
if ( isBroadcastChannel() ) {
|
||||
return Utility.getOnlinePlayersCount();
|
||||
return UtilityBukkit.getOnlinePlayersCount();
|
||||
}
|
||||
|
||||
return members.size();
|
||||
@@ -695,7 +695,7 @@ public abstract class Channel implements ConfigurationSerializable {
|
||||
// 現在サーバーに接続している全プレイヤーをメンバーとして返す
|
||||
if ( isBroadcastChannel() ) {
|
||||
List<ChannelPlayer> mem = new ArrayList<ChannelPlayer>();
|
||||
for ( Player p : Utility.getOnlinePlayers() ) {
|
||||
for ( Player p : UtilityBukkit.getOnlinePlayers() ) {
|
||||
mem.add(ChannelPlayer.getChannelPlayer(p));
|
||||
}
|
||||
return mem;
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DelayedJapanizeConvertTask extends BukkitRunnable {
|
||||
LunaChat.getInstance().getLunaChatAPI().getAllDictionary();
|
||||
|
||||
// カラーコード削除、URL削除
|
||||
String deletedURL = Utility.stripColor(org.replaceAll(REGEX_URL, " "));
|
||||
String deletedURL = Utility.stripColorCode(org.replaceAll(REGEX_URL, " "));
|
||||
|
||||
// キーワードをロック
|
||||
int index = 0;
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.Resources;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.UtilityBukkit;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.channel.ChannelPlayer;
|
||||
|
||||
@@ -135,7 +135,7 @@ public class HideCommand extends SubCommandAbst {
|
||||
Channel channel = api.getChannel(cname);
|
||||
if ( !isPlayerCommand && channel != null ) {
|
||||
isChannelCommand = true;
|
||||
} else if ( Utility.getOfflinePlayer(cname) == null ) {
|
||||
} else if ( UtilityBukkit.getOfflinePlayer(cname) == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExistChannelAndPlayer");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.Resources;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.UtilityBukkit;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.channel.ChannelPlayer;
|
||||
|
||||
@@ -188,7 +188,7 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
// プレイヤー名で補完する
|
||||
String arg = args[1].toLowerCase();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
for ( Player player : Utility.getOnlinePlayers() ) {
|
||||
for ( Player player : UtilityBukkit.getOnlinePlayers() ) {
|
||||
String pname = player.getName();
|
||||
pname = pname == null ? "" : pname.toLowerCase();
|
||||
if ( pname.startsWith(arg) ) {
|
||||
@@ -226,7 +226,7 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
items.add(name);
|
||||
}
|
||||
}
|
||||
for ( Player player : Utility.getOnlinePlayers() ) {
|
||||
for ( Player player : UtilityBukkit.getOnlinePlayers() ) {
|
||||
String pname = player.getName();
|
||||
pname = pname == null ? "" : pname.toLowerCase();
|
||||
if ( pname.startsWith(arg) ) {
|
||||
@@ -249,7 +249,7 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
// プレイヤー名で補完する
|
||||
String arg = args[2].toLowerCase();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
for ( Player player : Utility.getOnlinePlayers() ) {
|
||||
for ( Player player : UtilityBukkit.getOnlinePlayers() ) {
|
||||
String pname = player.getName();
|
||||
pname = pname == null ? "" : pname.toLowerCase();
|
||||
if ( pname.startsWith(arg) ) {
|
||||
@@ -325,7 +325,7 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
// プレイヤー名で補完する
|
||||
String arg = args[2].toLowerCase();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
for ( Player player : Utility.getOnlinePlayers() ) {
|
||||
for ( Player player : UtilityBukkit.getOnlinePlayers() ) {
|
||||
String pname = player.getName();
|
||||
pname = pname == null ? "" : pname.toLowerCase();
|
||||
if ( pname.startsWith(arg) ) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.UtilityBukkit;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.event.LunaChatChannelOptionChangedEvent;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
@@ -213,10 +214,10 @@ public class OptionCommand extends SubCommandAbst {
|
||||
} else {
|
||||
|
||||
String code = options.get("color");
|
||||
if ( Utility.isValidColor(code) ) {
|
||||
code = Utility.changeToColorCode(code);
|
||||
if ( UtilityBukkit.isValidColor(code) ) {
|
||||
code = UtilityBukkit.changeToColorCode(code);
|
||||
}
|
||||
if ( Utility.isValidColorCode(code) ) {
|
||||
if ( Utility.isAltColorCode(code) ) {
|
||||
channel.setColorCode(code);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "color", options.get("color"));
|
||||
|
||||
@@ -7,6 +7,8 @@ package com.github.ucchyocean.lc.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
|
||||
/**
|
||||
* reloadコマンドの実行クラス
|
||||
* @author ucchy
|
||||
@@ -72,7 +74,7 @@ public class ReloadCommand extends SubCommandAbst {
|
||||
CommandSender sender, String label, String[] args) {
|
||||
|
||||
api.reloadAllData();
|
||||
config.reloadConfig();
|
||||
config.reloadConfig(LunaChat.getInstance().getDataFolder(), LunaChat.getPluginJarFile());
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgReload");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.github.ucchyocean.lc.command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.UtilityBukkit;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
|
||||
public class SetCommand extends SubCommandAbst {
|
||||
@@ -91,7 +91,7 @@ public class SetCommand extends SubCommandAbst {
|
||||
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgSetDefault", targetPlayer, targetChannel.getName());
|
||||
|
||||
Player target = Utility.getPlayerExact(targetPlayer);
|
||||
Player target = UtilityBukkit.getPlayerExact(targetPlayer);
|
||||
if ( target != null ) {
|
||||
sendResourceMessage(target, PREINFO, "cmdmsgSet", targetChannel.getName());
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ package com.github.ucchyocean.lc.command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.UtilityBukkit;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.channel.ChannelPlayer;
|
||||
|
||||
@@ -117,7 +117,7 @@ public class UnhideCommand extends SubCommandAbst {
|
||||
Channel channel = api.getChannel(cname);
|
||||
if ( !isPlayerCommand && channel != null ) {
|
||||
isChannelCommand = true;
|
||||
} else if ( Utility.getOfflinePlayer(cname) == null ) {
|
||||
} else if ( UtilityBukkit.getOfflinePlayer(cname) == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExistChannelAndPlayer");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2014
|
||||
*/
|
||||
package com.github.ucchyocean.lc.japanize;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* ローマ字表記を漢字変換して返すユーティリティ
|
||||
* @author ucchy
|
||||
*/
|
||||
public class Japanizer {
|
||||
|
||||
private static final String REGEX_URL = "https?://[\\w/:%#\\$&\\?\\(\\)~\\.=\\+\\-]+";
|
||||
|
||||
/**
|
||||
* メッセージの日本語化をする
|
||||
* @param org
|
||||
* @param type
|
||||
* @param dictionary
|
||||
* @return
|
||||
*/
|
||||
public static String japanize(String org, JapanizeType type,
|
||||
HashMap<String, String> dictionary) {
|
||||
|
||||
// 変換不要なら空文字列を返す
|
||||
if ( type == JapanizeType.NONE || !isNeedToJapanize(org) ) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// URL削除
|
||||
String deletedURL = org.replaceAll(REGEX_URL, " ");
|
||||
|
||||
// キーワードをロック
|
||||
HashMap<String, String> keywordMap = new HashMap<String, String>();
|
||||
int index = 0;
|
||||
String keywordLocked = deletedURL;
|
||||
for ( String dickey : dictionary.keySet() ) {
|
||||
if ( keywordLocked.contains(dickey) ) {
|
||||
index++;
|
||||
String key = "<" + makeMultibytesDigit(index) + ">";
|
||||
keywordLocked = keywordLocked.replace(dickey, key);
|
||||
keywordMap.put(key, dictionary.get(dickey));
|
||||
}
|
||||
}
|
||||
|
||||
// カナ変換
|
||||
String japanized = YukiKanaConverter.conv(keywordLocked);
|
||||
|
||||
// IME変換
|
||||
if ( type == JapanizeType.GOOGLE_IME ) {
|
||||
japanized = IMEConverter.convByGoogleIME(japanized);
|
||||
// } else if ( type == JapanizeType.SOCIAL_IME ) {
|
||||
// japanized = IMEConverter.convBySocialIME(japanized);
|
||||
}
|
||||
|
||||
// キーワードのアンロック
|
||||
for ( String key : keywordMap.keySet() ) {
|
||||
japanized = japanized.replace(key, keywordMap.get(key));
|
||||
}
|
||||
|
||||
// 返す
|
||||
return japanized.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 日本語化が必要かどうかを判定する
|
||||
* @param org
|
||||
* @return
|
||||
*/
|
||||
private static boolean isNeedToJapanize(String org) {
|
||||
return ( org.getBytes().length == org.length()
|
||||
&& !org.matches("[ \\uFF61-\\uFF9F]+") );
|
||||
}
|
||||
|
||||
/**
|
||||
* 数値を、全角文字の文字列に変換して返す
|
||||
* @param digit
|
||||
* @return
|
||||
*/
|
||||
private static String makeMultibytesDigit(int digit) {
|
||||
|
||||
String half = Integer.toString(digit);
|
||||
StringBuilder result = new StringBuilder();
|
||||
for ( int index=0; index < half.length(); index++ ) {
|
||||
switch ( half.charAt(index) ) {
|
||||
case '0' : result.append("0"); break;
|
||||
case '1' : result.append("1"); break;
|
||||
case '2' : result.append("2"); break;
|
||||
case '3' : result.append("3"); break;
|
||||
case '4' : result.append("4"); break;
|
||||
case '5' : result.append("5"); break;
|
||||
case '6' : result.append("6"); break;
|
||||
case '7' : result.append("7"); break;
|
||||
case '8' : result.append("8"); break;
|
||||
case '9' : result.append("9"); break;
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.japanize;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* ローマ字からかな文字へ変換するクラス
|
||||
* @author ucchy
|
||||
* @deprecated {@link YukiKanaConverter} を使用してください
|
||||
*/
|
||||
@Deprecated
|
||||
public class KanaConverter {
|
||||
|
||||
private static final HashMap<String, String[]> TABLE;
|
||||
static {
|
||||
TABLE = new HashMap<String, String[]>();
|
||||
TABLE.put( "", new String[]{"あ","い","う","え","お"});
|
||||
TABLE.put( "k", new String[]{"か","き","く","け","こ"});
|
||||
TABLE.put( "s", new String[]{"さ","し","す","せ","そ"});
|
||||
TABLE.put( "t", new String[]{"た","ち","つ","て","と"});
|
||||
TABLE.put( "n", new String[]{"な","に","ぬ","ね","の"});
|
||||
TABLE.put( "h", new String[]{"は","ひ","ふ","へ","ほ"});
|
||||
TABLE.put( "m", new String[]{"ま","み","む","め","も"});
|
||||
TABLE.put( "y", new String[]{"や","い","ゆ","いぇ","よ"});
|
||||
TABLE.put( "r", new String[]{"ら","り","る","れ","ろ"});
|
||||
TABLE.put( "w", new String[]{"わ","うぃ","う","うぇ","を"});
|
||||
TABLE.put( "g", new String[]{"が","ぎ","ぐ","げ","ご"});
|
||||
TABLE.put( "z", new String[]{"ざ","じ","ず","ぜ","ぞ"});
|
||||
TABLE.put( "j", new String[]{"じゃ","じ","じゅ","じぇ","じょ"});
|
||||
TABLE.put( "d", new String[]{"だ","ぢ","づ","で","ど"});
|
||||
TABLE.put( "b", new String[]{"ば","び","ぶ","べ","ぼ"});
|
||||
TABLE.put( "p", new String[]{"ぱ","ぴ","ぷ","ぺ","ぽ"});
|
||||
TABLE.put("gy", new String[]{"ぎゃ","ぎぃ","ぎゅ","ぎぇ","ぎょ"});
|
||||
TABLE.put("gw", new String[]{"ぐぁ","ぐぃ","ぐぅ","ぐぇ","ぐぉ"});
|
||||
TABLE.put("zy", new String[]{"じゃ","じぃ","じゅ","じぇ","じょ"});
|
||||
TABLE.put("jy", new String[]{"じゃ","じぃ","じゅ","じぇ","じょ"});
|
||||
TABLE.put("dy", new String[]{"ぢゃ","ぢぃ","ぢゅ","ぢぇ","ぢょ"});
|
||||
TABLE.put("dh", new String[]{"でゃ","でぃ","でゅ","でぇ","でょ"});
|
||||
TABLE.put("dw", new String[]{"どぁ","どぃ","どぅ","どぇ","どぉ"});
|
||||
TABLE.put("by", new String[]{"びゃ","びぃ","びゅ","びぇ","びょ"});
|
||||
TABLE.put("py", new String[]{"ぴゃ","ぴぃ","ぴゅ","ぴぇ","ぴょ"});
|
||||
TABLE.put( "v", new String[]{"ヴぁ","ヴぃ","ヴ","ヴぇ","ヴぉ"});
|
||||
TABLE.put("vy", new String[]{"ヴゃ","ヴぃ","ヴゅ","ヴぇ","ヴょ"});
|
||||
TABLE.put("sh", new String[]{"しゃ","し","しゅ","しぇ","しょ"});
|
||||
TABLE.put("sy", new String[]{"しゃ","し","しゅ","しぇ","しょ"});
|
||||
TABLE.put( "c", new String[]{"か","し","く","せ","こ"});
|
||||
TABLE.put("ch", new String[]{"ちゃ","ち","ちゅ","ちぇ","ちょ"});
|
||||
TABLE.put("cy", new String[]{"ちゃ","ち","ちゅ","ちぇ","ちょ"});
|
||||
TABLE.put( "f", new String[]{"ふぁ","ふぃ","ふ","ふぇ","ふぉ"});
|
||||
TABLE.put("fy", new String[]{"ふゃ","ふぃ","ふゅ","ふぇ","ふょ"});
|
||||
TABLE.put("fw", new String[]{"ふぁ","ふぃ","ふ","ふぇ","ふぉ"});
|
||||
TABLE.put( "q", new String[]{"くぁ","くぃ","く","くぇ","くぉ"});
|
||||
TABLE.put("ky", new String[]{"きゃ","きぃ","きゅ","きぇ","きょ"});
|
||||
TABLE.put("kw", new String[]{"くぁ","くぃ","く","くぇ","くぉ"});
|
||||
TABLE.put("ty", new String[]{"ちゃ","ちぃ","ちゅ","ちぇ","ちょ"});
|
||||
TABLE.put("ts", new String[]{"つぁ","つぃ","つ","つぇ","つぉ"});
|
||||
TABLE.put("th", new String[]{"てゃ","てぃ","てゅ","てぇ","てょ"});
|
||||
TABLE.put("tw", new String[]{"とぁ","とぃ","とぅ","とぇ","とぉ"});
|
||||
TABLE.put("ny", new String[]{"にゃ","にぃ","にゅ","にぇ","にょ"});
|
||||
TABLE.put("hy", new String[]{"ひゃ","ひぃ","ひゅ","ひぇ","ひょ"});
|
||||
TABLE.put("my", new String[]{"みゃ","みぃ","みゅ","みぇ","みょ"});
|
||||
TABLE.put("ry", new String[]{"りゃ","りぃ","りゅ","りぇ","りょ"});
|
||||
TABLE.put( "l", new String[]{"ぁ","ぃ","ぅ","ぇ","ぉ"});
|
||||
TABLE.put( "x", new String[]{"ぁ","ぃ","ぅ","ぇ","ぉ"});
|
||||
TABLE.put("ly", new String[]{"ゃ","ぃ","ゅ","ぇ","ょ"});
|
||||
TABLE.put("lt", new String[]{"た","ち","っ","て","と"});
|
||||
TABLE.put("lk", new String[]{"ヵ","き","く","ヶ","こ"});
|
||||
TABLE.put("xy", new String[]{"ゃ","ぃ","ゅ","ぇ","ょ"});
|
||||
TABLE.put("xt", new String[]{"た","ち","っ","て","と"});
|
||||
TABLE.put("xk", new String[]{"ヵ","き","く","ヶ","こ"});
|
||||
TABLE.put("wy", new String[]{"わ","ゐ","う","ゑ","を"});
|
||||
TABLE.put("wh", new String[]{"うぁ","うぃ","う","うぇ","うぉ"});
|
||||
};
|
||||
|
||||
private static String getKanaFromTable(String s, int n) {
|
||||
|
||||
if ( TABLE.containsKey(s) ) {
|
||||
return TABLE.get(s)[n];
|
||||
}
|
||||
return s + TABLE.get("")[n];
|
||||
}
|
||||
|
||||
/**
|
||||
* ローマ字をかな文字へ変換する
|
||||
* @param org 変換元文字列
|
||||
* @return 変換後の文字列
|
||||
*/
|
||||
public static String conv(String org) {
|
||||
|
||||
String last = "";
|
||||
StringBuilder line = new StringBuilder();
|
||||
|
||||
for ( int i=0; i<org.length(); i++ ) {
|
||||
String tmp = org.substring(i,i+1);
|
||||
|
||||
if ( tmp.equals("a") ) {
|
||||
line.append( getKanaFromTable(last, 0) );
|
||||
last = "";
|
||||
} else if ( tmp.equals("i") ) {
|
||||
line.append( getKanaFromTable(last, 1) );
|
||||
last = "";
|
||||
} else if ( tmp.equals("u") ) {
|
||||
line.append( getKanaFromTable(last, 2) );
|
||||
last = "";
|
||||
} else if ( tmp.equals("e") ) {
|
||||
line.append( getKanaFromTable(last, 3) );
|
||||
last = "";
|
||||
} else if ( tmp.equals("o") ) {
|
||||
line.append( getKanaFromTable(last, 4) );
|
||||
last = "";
|
||||
} else {
|
||||
if ( last.equals("n") && !(tmp.equals("y")) ) {
|
||||
line.append("ん");
|
||||
last = "";
|
||||
if ( tmp.equals("n") ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( Character.isLetter(tmp.charAt(0)) ) {
|
||||
if ( Character.isUpperCase(tmp.charAt(0)) ) {
|
||||
line.append(last + tmp);
|
||||
last = "";
|
||||
} else if ( last.equals(tmp) ) {
|
||||
line.append("っ");
|
||||
last = tmp;
|
||||
} else {
|
||||
last = last + tmp;
|
||||
}
|
||||
} else {
|
||||
if ( tmp.equals("-") ) {
|
||||
line.append(last + "ー");
|
||||
last = "";
|
||||
} else if ( tmp.equals(".") ) {
|
||||
line.append(last + "。");
|
||||
last = "";
|
||||
} else if ( tmp.equals(",") ) {
|
||||
line.append(last + "、");
|
||||
last = "";
|
||||
} else if ( tmp.equals("?") ) {
|
||||
line.append(last + "?");
|
||||
last = "";
|
||||
} else if ( tmp.equals("!") ) {
|
||||
line.append(last + "!");
|
||||
last = "";
|
||||
} else if ( tmp.equals("[") ) {
|
||||
line.append(last + "「");
|
||||
last = "";
|
||||
} else if ( tmp.equals("]") ) {
|
||||
line.append(last + "」");
|
||||
last = "";
|
||||
} else if ( tmp.equals("<") ) {
|
||||
line.append(last + "<");
|
||||
last = "";
|
||||
} else if ( tmp.equals(">") ) {
|
||||
line.append(last + ">");
|
||||
last = "";
|
||||
} else if ( tmp.equals("&") ) {
|
||||
line.append(last + "&");
|
||||
last = "";
|
||||
} else if ( tmp.equals("\"") ) {
|
||||
line.append(last + "”");
|
||||
last = "";
|
||||
} else if ( tmp.equals("(") || tmp.equals(")") ) {
|
||||
line.append(last);
|
||||
last = "";
|
||||
} else {
|
||||
line.append(last + tmp);
|
||||
last = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
line.append(last);
|
||||
|
||||
return line.toString();
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする