diff --git a/pom.xml b/pom.xml index 9fee439..7f172c7 100644 --- a/pom.xml +++ b/pom.xml @@ -4,6 +4,7 @@ LunaChat 3.0.0 A powerfull chat channel plugin with IME (Kana-Kanji conversion) support + https://github.com/ucchyocean/LunaChat diff --git a/src/main/java/com/github/ucchyocean/lc3/LunaChatConfig.java b/src/main/java/com/github/ucchyocean/lc3/LunaChatConfig.java index 39d8783..0561274 100644 --- a/src/main/java/com/github/ucchyocean/lc3/LunaChatConfig.java +++ b/src/main/java/com/github/ucchyocean/lc3/LunaChatConfig.java @@ -8,6 +8,7 @@ package com.github.ucchyocean.lc3; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; import java.util.regex.Pattern; import com.github.ucchyocean.lc3.japanize.JapanizeType; @@ -267,10 +268,10 @@ public class LunaChatConfig { if ( globalChannel != null && !globalChannel.equals("") && !globalChannel.matches("[0-9a-zA-Z\\-_]{1,20}") ) { - // TODO コンソールに警告を表示する -// String msg = String.format( -// Resources.get("errmsgCannotUseForGlobal"), globalChannel); -// LunaChat.getInstance().getLogger().warning(msg); + // コンソールに警告を表示する + String msg = String.format( + Messages.get("errmsgCannotUseForGlobal"), globalChannel); + LunaChat.getPlugin().log(Level.WARNING, msg); globalChannel = ""; } } diff --git a/src/main/java/com/github/ucchyocean/lc3/PluginInterface.java b/src/main/java/com/github/ucchyocean/lc3/PluginInterface.java index e68218b..a117142 100644 --- a/src/main/java/com/github/ucchyocean/lc3/PluginInterface.java +++ b/src/main/java/com/github/ucchyocean/lc3/PluginInterface.java @@ -6,6 +6,8 @@ package com.github.ucchyocean.lc3; import java.io.File; +import java.util.Set; +import java.util.logging.Level; /** * プラグインインターフェイス @@ -42,4 +44,17 @@ public interface PluginInterface { * @return normalChatLogger */ public LunaChatLogger getNormalChatLogger(); + + /** + * オンラインのプレイヤー名一覧を取得する + * @return オンラインのプレイヤー名一覧 + */ + public Set getOnlinePlayerNames(); + + /** + * このプラグインのログを記録する + * @param level ログレベル + * @param msg ログメッセージ + */ + public void log(Level level, String msg); } diff --git a/src/main/java/com/github/ucchyocean/lc3/Utility.java b/src/main/java/com/github/ucchyocean/lc3/Utility.java index d04b5ff..7f42205 100644 --- a/src/main/java/com/github/ucchyocean/lc3/Utility.java +++ b/src/main/java/com/github/ucchyocean/lc3/Utility.java @@ -84,6 +84,16 @@ public class Utility { * @return 置き換え後の文字列 */ public static String stripColorCode(String source) { + if (source == null) return null; + return stripAltColorCode(source).replaceAll("\u00A7([0-9a-fk-or])", ""); + } + + /** + * 文字列に含まれているカラーコード候補(&a)を除去して返す + * @param source 置き換え元の文字列 + * @return 置き換え後の文字列 + */ + public static String stripAltColorCode(String source) { if (source == null) return null; return source.replaceAll("&([0-9a-fk-or])", ""); } @@ -107,6 +117,45 @@ public class Utility { if (code == null) return false; return code.matches("&[0-9a-fk-orA-FK-OR]"); } + + /** + * ChatColorで指定可能な色(REDとかGREENとか)かどうかを判断する + * @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 length アスタリスクの個数 diff --git a/src/main/java/com/github/ucchyocean/lc3/UtilityBukkit.java b/src/main/java/com/github/ucchyocean/lc3/UtilityBukkit.java index 301bd9b..fa46c43 100644 --- a/src/main/java/com/github/ucchyocean/lc3/UtilityBukkit.java +++ b/src/main/java/com/github/ucchyocean/lc3/UtilityBukkit.java @@ -8,7 +8,6 @@ package com.github.ucchyocean.lc3; import java.util.Collection; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -34,44 +33,6 @@ public class UtilityBukkit { 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 プレイヤー名 diff --git a/src/main/java/com/github/ucchyocean/lc3/YamlConfig.java b/src/main/java/com/github/ucchyocean/lc3/YamlConfig.java index 5591e65..0b6cfa5 100644 --- a/src/main/java/com/github/ucchyocean/lc3/YamlConfig.java +++ b/src/main/java/com/github/ucchyocean/lc3/YamlConfig.java @@ -7,10 +7,11 @@ package com.github.ucchyocean.lc3; import java.io.BufferedWriter; import java.io.File; -import java.io.FileReader; +import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.Reader; import java.util.ArrayList; import java.util.HashMap; @@ -64,7 +65,7 @@ public class YamlConfig { } public static YamlConfig load(File file) { - try ( FileReader reader = new FileReader(file) ) { + try ( InputStreamReader reader = new InputStreamReader(new FileInputStream(file), "UTF-8") ) { return load(reader); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/com/github/ucchyocean/lc3/bukkit/BukkitEventListener.java b/src/main/java/com/github/ucchyocean/lc3/bukkit/BukkitEventListener.java index 0680acd..f2183f1 100644 --- a/src/main/java/com/github/ucchyocean/lc3/bukkit/BukkitEventListener.java +++ b/src/main/java/com/github/ucchyocean/lc3/bukkit/BukkitEventListener.java @@ -159,7 +159,6 @@ public class BukkitEventListener implements Listener { if ( channel.isPersonalChat() && cname.contains(pname) ) { boolean isAllOffline = true; for ( ChannelMember cp : channel.getMembers() ) { - // TODO if ( cp.isOnline() ) { isAllOffline = false; } diff --git a/src/main/java/com/github/ucchyocean/lc3/bukkit/LunaChatBukkit.java b/src/main/java/com/github/ucchyocean/lc3/bukkit/LunaChatBukkit.java index 877ccf6..17ee55f 100644 --- a/src/main/java/com/github/ucchyocean/lc3/bukkit/LunaChatBukkit.java +++ b/src/main/java/com/github/ucchyocean/lc3/bukkit/LunaChatBukkit.java @@ -6,11 +6,15 @@ package com.github.ucchyocean.lc3.bukkit; import java.io.File; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.logging.Level; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -239,4 +243,27 @@ public class LunaChatBukkit extends JavaPlugin implements PluginInterface { protected void setNormalChatLogger(LunaChatLogger normalChatLogger) { this.normalChatLogger = normalChatLogger; } + + /** + * オンラインのプレイヤー名一覧を取得する + * @return オンラインのプレイヤー名一覧 + */ + @Override + public Set getOnlinePlayerNames() { + Set list = new HashSet<>(); + for ( Player p : Bukkit.getOnlinePlayers() ) { + list.add(p.getName()); + } + return list; + } + + /** + * このプラグインのログを記録する + * @param level ログレベル + * @param msg ログメッセージ + */ + @Override + public void log(Level level, String msg) { + getLogger().log(level, msg); + } } diff --git a/src/main/java/com/github/ucchyocean/lc3/bungee/BungeeEventListener.java b/src/main/java/com/github/ucchyocean/lc3/bungee/BungeeEventListener.java index abe1c61..8f0fcf8 100644 --- a/src/main/java/com/github/ucchyocean/lc3/bungee/BungeeEventListener.java +++ b/src/main/java/com/github/ucchyocean/lc3/bungee/BungeeEventListener.java @@ -168,7 +168,6 @@ public class BungeeEventListener implements Listener { if ( channel.isPersonalChat() && cname.contains(pname) ) { boolean isAllOffline = true; for ( ChannelMember cp : channel.getMembers() ) { - // TODO if ( cp.isOnline() ) { isAllOffline = false; } diff --git a/src/main/java/com/github/ucchyocean/lc3/bungee/LunaChatBungee.java b/src/main/java/com/github/ucchyocean/lc3/bungee/LunaChatBungee.java index 1c56fa1..507350b 100644 --- a/src/main/java/com/github/ucchyocean/lc3/bungee/LunaChatBungee.java +++ b/src/main/java/com/github/ucchyocean/lc3/bungee/LunaChatBungee.java @@ -7,6 +7,9 @@ package com.github.ucchyocean.lc3.bungee; import java.io.File; import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; +import java.util.logging.Level; import com.github.ucchyocean.lc3.LunaChat; import com.github.ucchyocean.lc3.LunaChatAPI; @@ -17,6 +20,7 @@ import com.github.ucchyocean.lc3.PluginInterface; import com.github.ucchyocean.lc3.channel.ChannelManager; import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Plugin; /** @@ -143,4 +147,27 @@ public class LunaChatBungee extends Plugin implements PluginInterface { public LunaChatLogger getNormalChatLogger() { return normalChatLogger; } + + /** + * オンラインのプレイヤー名一覧を取得する + * @return オンラインのプレイヤー名一覧 + */ + @Override + public Set getOnlinePlayerNames() { + Set list = new HashSet<>(); + for ( ProxiedPlayer p : ProxyServer.getInstance().getPlayers() ) { + list.add(p.getName()); + } + return list; + } + + /** + * このプラグインのログを記録する + * @param level ログレベル + * @param msg ログメッセージ + */ + @Override + public void log(Level level, String msg) { + getLogger().log(level, msg); + } } diff --git a/src/main/java/com/github/ucchyocean/lc3/channel/JapanizeConvertTask.java b/src/main/java/com/github/ucchyocean/lc3/channel/JapanizeConvertTask.java index 7f9c508..9617209 100644 --- a/src/main/java/com/github/ucchyocean/lc3/channel/JapanizeConvertTask.java +++ b/src/main/java/com/github/ucchyocean/lc3/channel/JapanizeConvertTask.java @@ -55,10 +55,7 @@ public class JapanizeConvertTask { HashMap keywordMap = new HashMap(); ArrayList keywords = new ArrayList(); if ( LunaChat.getConfig().isJapanizeIgnorePlayerName() ) { - // TODO -// for ( Player player : Bukkit.getOnlinePlayers() ) { -// keywords.add(player.getName()); -// } + keywords.addAll(LunaChat.getPlugin().getOnlinePlayerNames()); } HashMap dictionary = LunaChat.getAPI().getAllDictionary(); diff --git a/src/main/java/com/github/ucchyocean/lc3/command/OptionCommand.java b/src/main/java/com/github/ucchyocean/lc3/command/OptionCommand.java index 7c72ece..1fa8bdd 100644 --- a/src/main/java/com/github/ucchyocean/lc3/command/OptionCommand.java +++ b/src/main/java/com/github/ucchyocean/lc3/command/OptionCommand.java @@ -9,7 +9,6 @@ import java.util.ArrayList; import java.util.HashMap; import com.github.ucchyocean.lc3.Utility; -import com.github.ucchyocean.lc3.UtilityBukkit; import com.github.ucchyocean.lc3.channel.Channel; import com.github.ucchyocean.lc3.japanize.JapanizeType; import com.github.ucchyocean.lc3.member.ChannelMember; @@ -205,9 +204,8 @@ public class OptionCommand extends SubCommandAbst { String code = options.get("color"); - // TODO Bukkit依存になってしまっているので、実装修正を検討する - if ( UtilityBukkit.isValidColor(code) ) { - code = UtilityBukkit.changeToColorCode(code); + if ( Utility.isValidColor(code) ) { + code = Utility.changeToColorCode(code); } if ( Utility.isAltColorCode(code) ) { channel.setColorCode(code); diff --git a/src/main/java/com/github/ucchyocean/lc3/command/SetCommand.java b/src/main/java/com/github/ucchyocean/lc3/command/SetCommand.java index 01ab9c1..1f730cd 100644 --- a/src/main/java/com/github/ucchyocean/lc3/command/SetCommand.java +++ b/src/main/java/com/github/ucchyocean/lc3/command/SetCommand.java @@ -87,11 +87,11 @@ public class SetCommand extends SubCommandAbst { sendResourceMessage(sender, PREINFO, "cmdmsgSetDefault", targetPlayer, targetChannel.getName()); - // TODO setされる相手のプレイヤーにも通知する -// Player target = Utility.getPlayerExact(targetPlayer); -// if ( target != null ) { -// sendResourceMessage(new CommandSenderBukkit(target), PREINFO, "cmdmsgSet", targetChannel.getName()); -// } + // setされる相手のプレイヤーにも通知する + ChannelMember target = ChannelMember.getChannelMember(targetPlayer); + if ( target != null ) { + sendResourceMessage(target, PREINFO, "cmdmsgSet", targetChannel.getName()); + } return true; } diff --git a/src/main/java/com/github/ucchyocean/lc3/member/ChannelMemberProxiedPlayer.java b/src/main/java/com/github/ucchyocean/lc3/member/ChannelMemberProxiedPlayer.java index 726182f..cc306c9 100644 --- a/src/main/java/com/github/ucchyocean/lc3/member/ChannelMemberProxiedPlayer.java +++ b/src/main/java/com/github/ucchyocean/lc3/member/ChannelMemberProxiedPlayer.java @@ -9,7 +9,6 @@ import java.util.UUID; import org.jetbrains.annotations.Nullable; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -49,25 +48,13 @@ public class ChannelMemberProxiedPlayer extends ChannelMemberBungee { if ( nameOrUuid.startsWith("$") ) { return new ChannelMemberProxiedPlayer(UUID.fromString(nameOrUuid.substring(1))); } else { + // TODO オフラインのプレイヤー取得について検討する ProxiedPlayer player = ProxyServer.getInstance().getPlayer(nameOrUuid); if ( player != null ) return new ChannelMemberProxiedPlayer(player.getUniqueId()); } return null; } - /** - * CommandSenderから、ChannelMemberProxiedPlayerを作成して返す - * @param sender - * @return ChannelMemberProxiedPlayer - */ - public static ChannelMemberProxiedPlayer getChannelPlayer(CommandSender sender) { - if ( sender instanceof ProxiedPlayer ) { - return new ChannelMemberProxiedPlayer(((ProxiedPlayer)sender).getUniqueId()); - } - // TODO BungeeCordのCommandSenderを実装するクラスは、ProxiedPlayer以外にないはず。コンソールは? - return null; - } - /** * オンラインかどうか * @return オンラインかどうか diff --git a/src/main/java/com/github/ucchyocean/lc3/standalone/LunaChatStandalone.java b/src/main/java/com/github/ucchyocean/lc3/standalone/LunaChatStandalone.java index 12faf43..5c3de8f 100644 --- a/src/main/java/com/github/ucchyocean/lc3/standalone/LunaChatStandalone.java +++ b/src/main/java/com/github/ucchyocean/lc3/standalone/LunaChatStandalone.java @@ -7,6 +7,8 @@ package com.github.ucchyocean.lc3.standalone; import java.io.File; import java.net.URISyntaxException; +import java.util.Set; +import java.util.logging.Level; import com.github.ucchyocean.lc3.LunaChat; import com.github.ucchyocean.lc3.LunaChatAPI; @@ -72,4 +74,18 @@ public class LunaChatStandalone implements PluginInterface { public LunaChatLogger getNormalChatLogger() { return null; } + + /** + * オンラインのプレイヤー名一覧を取得する + * @return オンラインのプレイヤー名一覧 + */ + public Set getOnlinePlayerNames() { + return null; + } + + @Override + public void log(Level level, String msg) { + // TODO 未実装 + } + } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 21e5d0a..c1afc41 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: ${project.name} -main: com.github.ucchyocean.lc3.LunaChat +main: com.github.ucchyocean.lc3.bukkit.LunaChatBukkit version: ${project.version} authors: [ucchy, YukiLeafX, LazyGon] description: ${project.description}