LunaChat v3-k2 : BungeeCord implementation. (WIP)
このコミットが含まれているのは:
1 親
330fb0aaab
コミット
6202f00729
98ファイル変更
+1149
-715
検索条件に一致するファイルはありません
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* @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,
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* LunaChat
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChat {
|
||||
|
||||
private static PluginInterface instance;
|
||||
private static LunaChatMode mode;
|
||||
|
||||
public static void setPlugin(PluginInterface plugin) {
|
||||
instance = plugin;
|
||||
}
|
||||
|
||||
public static PluginInterface getPlugin() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void setMode(LunaChatMode _mode) {
|
||||
mode = _mode;
|
||||
}
|
||||
|
||||
public static LunaChatMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
|
||||
// public static EventSenderInterface getEventSender() {
|
||||
// // TODO 未実装
|
||||
// return null;
|
||||
// }
|
||||
|
||||
public static File getDataFolder() {
|
||||
return instance.getDataFolder();
|
||||
}
|
||||
|
||||
public static File getPluginJarFile() {
|
||||
return instance.getPluginJarFile();
|
||||
}
|
||||
|
||||
public static LunaChatConfig getConfig() {
|
||||
return instance.getLunaChatConfig();
|
||||
}
|
||||
|
||||
public static LunaChatAPI getAPI() {
|
||||
return instance.getLunaChatAPI();
|
||||
}
|
||||
|
||||
public static LunaChatLogger getNormalChatLogger() {
|
||||
return instance.getNormalChatLogger();
|
||||
}
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* LunaChat APIクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public interface LunaChatAPI {
|
||||
|
||||
/**
|
||||
* 指定したチャンネル名が存在するかどうかを返す
|
||||
* @param channelName チャンネル名
|
||||
* @return 存在するかどうか
|
||||
*/
|
||||
public boolean isExistChannel(String channelName);
|
||||
|
||||
/**
|
||||
* 全てのチャンネルを返す
|
||||
* @return 全てのチャンネル
|
||||
*/
|
||||
public Collection<Channel> getChannels();
|
||||
|
||||
/**
|
||||
* プレイヤーが参加しているチャンネルを返す
|
||||
* @param playerName プレイヤー名
|
||||
* @return チャンネル
|
||||
*/
|
||||
public Collection<Channel> getChannelsByPlayer(String playerName);
|
||||
|
||||
/**
|
||||
* プレイヤーが参加しているデフォルトのチャンネルを返す
|
||||
* @param playerName プレイヤー
|
||||
* @return チャンネル
|
||||
*/
|
||||
public Channel getDefaultChannel(String playerName);
|
||||
|
||||
/**
|
||||
* プレイヤーのデフォルトチャンネルを設定する
|
||||
* @param playerName プレイヤー
|
||||
* @param channelName チャンネル名
|
||||
*/
|
||||
public void setDefaultChannel(String playerName, String channelName);
|
||||
|
||||
/**
|
||||
* 指定した名前のプレイヤーに設定されている、デフォルトチャンネルを削除する
|
||||
* @param playerName プレイヤー名
|
||||
*/
|
||||
public void removeDefaultChannel(String playerName);
|
||||
|
||||
/**
|
||||
* チャンネルを取得する
|
||||
* @param channelName チャンネル名
|
||||
* @return チャンネル
|
||||
*/
|
||||
public Channel getChannel(String channelName);
|
||||
|
||||
/**
|
||||
* 新しいチャンネルを作成する
|
||||
* @param channelName チャンネル名
|
||||
* @return 作成されたチャンネル
|
||||
*/
|
||||
public Channel createChannel(String channelName);
|
||||
|
||||
// /**
|
||||
// * 新しいチャンネルを作成する
|
||||
// * @param channelName チャンネル名
|
||||
// * @param sender チャンネルを作成した人
|
||||
// * @return 作成されたチャンネル
|
||||
// */
|
||||
// public Channel createChannel(String channelName, CommandSender sender);
|
||||
|
||||
/**
|
||||
* チャンネルを削除する
|
||||
* @param channelName 削除するチャンネル名
|
||||
* @return 削除したかどうか
|
||||
*/
|
||||
public boolean removeChannel(String channelName);
|
||||
|
||||
// /**
|
||||
// * チャンネルを削除する
|
||||
// * @param channelName 削除するチャンネル名
|
||||
// * @param sender チャンネルを削除した人
|
||||
// * @return 削除したかどうか
|
||||
// */
|
||||
// public boolean removeChannel(String channelName, CommandSender sender);
|
||||
|
||||
/**
|
||||
* テンプレートを取得する
|
||||
* @param id テンプレートID
|
||||
* @return テンプレート
|
||||
*/
|
||||
public String getTemplate(String id);
|
||||
|
||||
/**
|
||||
* テンプレートを登録する
|
||||
* @param id テンプレートID
|
||||
* @param template テンプレート
|
||||
*/
|
||||
public void setTemplate(String id, String template);
|
||||
|
||||
/**
|
||||
* テンプレートを削除する
|
||||
* @param id テンプレートID
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 該当のプレイヤーに関連するhidelistを取得する。
|
||||
* @param key プレイヤー
|
||||
* @return 指定されたプレイヤーをhideしているプレイヤー(非null)
|
||||
*/
|
||||
public List<ChannelMember> getHidelist(ChannelMember key);
|
||||
|
||||
/**
|
||||
* 該当のプレイヤーがhideしているプレイヤーのリストを返す。
|
||||
* @param player プレイヤー
|
||||
* @return 指定したプレイヤーがhideしているプレイヤーのリスト
|
||||
*/
|
||||
public ArrayList<ChannelMember> getHideinfo(ChannelMember player);
|
||||
|
||||
/**
|
||||
* 指定されたプレイヤーが、指定されたプレイヤーをhideするように設定する。
|
||||
* @param player hideする側のプレイヤー
|
||||
* @param hided hideされる側のプレイヤー
|
||||
*/
|
||||
public void addHidelist(ChannelMember player, ChannelMember hided);
|
||||
|
||||
/**
|
||||
* 指定されたプレイヤーが、指定されたプレイヤーのhideを解除するように設定する。
|
||||
* @param player hideしていた側のプレイヤー
|
||||
* @param hided hideされていた側のプレイヤー
|
||||
*/
|
||||
public void removeHidelist(ChannelMember player, ChannelMember hided);
|
||||
|
||||
/**
|
||||
* Japanize変換を行う
|
||||
* @param message 変換するメッセージ
|
||||
* @param type 変換タイプ
|
||||
* @return 変換後のメッセージ、ただしイベントでキャンセルされた場合はnullが返されるので注意
|
||||
*/
|
||||
public String japanize(String message, JapanizeType type);
|
||||
|
||||
/**
|
||||
* 該当プレイヤーのJapanize変換をオン/オフする
|
||||
* @param playerName 設定するプレイヤー名
|
||||
* @param doJapanize Japanize変換するかどうか
|
||||
*/
|
||||
public void setPlayersJapanize(String playerName, boolean doJapanize);
|
||||
|
||||
/**
|
||||
* プレイヤーのJapanize設定を返す
|
||||
* @param playerName プレイヤー名
|
||||
* @return Japanize設定
|
||||
*/
|
||||
public boolean isPlayerJapanize(String playerName);
|
||||
|
||||
/**
|
||||
* LunaChatの全データを再読み込みする
|
||||
*/
|
||||
public void reloadAllData();
|
||||
}
|
||||
@@ -1,635 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
|
||||
/**
|
||||
* LunaChatのコンフィグクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatConfig {
|
||||
|
||||
/** チャンネルチャット機能を利用可能にするかどうか */
|
||||
private boolean enableChannelChat;
|
||||
|
||||
/** チャットイベントの処理優先度 */
|
||||
private EventPriority playerChatEventListenerPriority;
|
||||
|
||||
/** チャンネルチャットに入っていない人の発言を、グローバルとして扱うかどうか */
|
||||
private boolean noJoinAsGlobal;
|
||||
|
||||
/** チャンネルチャットの発言内容を、ログに残すかどうか */
|
||||
private boolean loggingChat;
|
||||
|
||||
/** チャンネルチャットの発言内容を、HawkEyeに記録するかどうか */
|
||||
private boolean loggingChatToHawkEye;
|
||||
|
||||
/** チャンネルチャットの発言内容を、Prismに記録するかどうか */
|
||||
private boolean loggingChatToPrism;
|
||||
|
||||
/** チャンネルチャットの発言内容を、コンソールに表示するかどうか */
|
||||
private boolean displayChatOnConsole;
|
||||
|
||||
/** グローバルマーカー これが発言の頭に入っている場合は、強制的にグローバル発言になる */
|
||||
private String globalMarker;
|
||||
|
||||
/** 全てのメンバーが退出したときに、チャンネルを削除するかどうか */
|
||||
private boolean zeroMemberRemove;
|
||||
|
||||
/** ログイン時に、参加中チャンネルを表示するかどうか */
|
||||
private boolean showListOnJoin;
|
||||
|
||||
/** /ch join コマンドで存在しないチャンネルを指定したときに、
|
||||
* チャンネルを新規作成して入室するかどうか */
|
||||
private boolean createChannelOnJoinCommand;
|
||||
|
||||
/** サーバーに初参加したユーザーを参加させる、既定のチャンネル。<br/>
|
||||
* 参加させない場合は、から文字列 "" を指定すること。 */
|
||||
private String globalChannel;
|
||||
|
||||
/** サーバーに参加したユーザーに必ず参加させるチャンネル。<br/>
|
||||
* グローバルチャンネルとは別で指定できる。 */
|
||||
private List<String> forceJoinChannels;
|
||||
|
||||
/** formatコマンド実行時に、必ず含まれる必要があるキーワード。 */
|
||||
private List<String> formatConstraint;
|
||||
|
||||
/** チャンネルを作成したときに、デフォルトで設定されるフォーマット */
|
||||
private String defaultFormat;
|
||||
|
||||
/** プライベートメッセージを送信するときに、適用されるフォーマット */
|
||||
private String defaultFormatForPrivateMessage;
|
||||
|
||||
/** OPの画面に、全チャンネルの発言内容を表示するかどうか */
|
||||
private boolean opListenAllChannel;
|
||||
|
||||
/** チャンネルを新規作成するときに、チャンネル名が満たさなければならない、最低文字列長 */
|
||||
private int minChannelNameLength;
|
||||
|
||||
/** チャンネルを新規作成するときに、チャンネル名が満たさなければならない、最大文字列長 */
|
||||
private int maxChannelNameLength;
|
||||
|
||||
/** クイックチャンネルチャット機能を有効化するかどうか */
|
||||
private boolean enableQuickChannelChat;
|
||||
|
||||
/** クイックチャンネルチャット機能に使用する記号 */
|
||||
private String quickChannelChatSeparator;
|
||||
|
||||
/** ブロードキャストチャンネルの発言内容を、dynmapに送信するかどうか。<br/>
|
||||
* dynmapがロードされていない場合は、この設定は無視される(false扱い)。 */
|
||||
private boolean sendBroadcastChannelChatToDynmap;
|
||||
|
||||
/** dynmapへ送信するときに、チャンネルのフォーマットを反映して送信するかどうか。*/
|
||||
private boolean sendFormattedMessageToDynmap;
|
||||
|
||||
/** dynmapのWebUIから発言された発言内容を表示するチャンネル。 */
|
||||
private String dynmapChannel;
|
||||
|
||||
/** NGワードの設定 */
|
||||
private List<String> ngword;
|
||||
|
||||
/** NGワードを発言した人に対して実行するアクション<br/>
|
||||
* mask = マスクするのみ<br/>
|
||||
* kick = マスクしてチャンネルからキックする<br/>
|
||||
* ban = マスクしてチャンネルからBANする */
|
||||
private NGWordAction ngwordAction;
|
||||
|
||||
/** NGワードの設定、正規表現マッチング用にコンパイルされたもの */
|
||||
private List<Pattern> ngwordCompiled;
|
||||
|
||||
/** 通常チャット(非チャンネルチャット)の装飾を、LunaChatから行うかどうか */
|
||||
private boolean enableNormalChatMessageFormat;
|
||||
|
||||
/** 通常チャットの装飾フォーマット */
|
||||
private String normalChatMessageFormat;
|
||||
|
||||
/** 通常チャットで、カラーコードを使用可能にするかどうか */
|
||||
private boolean enableNormalChatColorCode;
|
||||
|
||||
/** Japanize変換のタイプ<br/>
|
||||
* none = 日本語変換をしない<br/>
|
||||
* kana = カナ変換のみする<br/>
|
||||
* googleime = カナ変換後、GoogleIMEで漢字変換する */
|
||||
private JapanizeType japanizeType;
|
||||
|
||||
/** Japanize変換の1行表示と2行表示の切り替え<br/>
|
||||
* 1 = 1行表示<br/>
|
||||
* 2 = 2行表示 */
|
||||
private int japanizeDisplayLine;
|
||||
|
||||
/** Japanize変換の1行表示時のフォーマット */
|
||||
private String japanizeLine1Format;
|
||||
|
||||
/** Japanize変換の2行表示時の2行目のフォーマット */
|
||||
private String japanizeLine2Format;
|
||||
|
||||
/** 発言に含まれているプレイヤー名を、Japanize変換から除外するかどうか */
|
||||
private boolean japanizeIgnorePlayerName;
|
||||
|
||||
/** ノンジャパナイズマーカー これが発言の頭に入っている場合は、一時的にjapanizeを実行しない */
|
||||
private String noneJapanizeMarker;
|
||||
|
||||
/** 通常チャットで、JapanizeDisplayLine=2のとき、Japanize変換したあと表示するまでのウェイト(tick)
|
||||
* 隠し設定。 */
|
||||
private int japanizeWait;
|
||||
|
||||
// === 以下、BungeeCord用設定 ===
|
||||
|
||||
/** 通常チャットを全サーバーにブロードキャストするかどうか */
|
||||
private boolean broadcastChat;
|
||||
|
||||
/** 通常チャットを全サーバーにブロードキャストする場合のフォーマット */
|
||||
private String broadcastChatFormat;
|
||||
|
||||
/** 通常チャットを全サーバーにブロードキャストする場合に、発言者サーバーのチャット内容もJapanize化するかどうか */
|
||||
private boolean broadcastChatLocalJapanize;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param dataFolder コンフィグ格納フォルダ
|
||||
* @param jarFile プラグインJarファイル
|
||||
*/
|
||||
public LunaChatConfig(File dataFolder, File jarFile) {
|
||||
reloadConfig(dataFolder, jarFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* config.yml を再読み込みする
|
||||
*/
|
||||
public void reloadConfig(File dataFolder, File jarFile) {
|
||||
|
||||
File configFile = new File(dataFolder, "config.yml");
|
||||
if ( !configFile.exists() ) {
|
||||
Utility.copyFileFromJar(jarFile, configFile, "config_ja.yml", false);
|
||||
}
|
||||
|
||||
YamlConfig config = YamlConfig.load(configFile);
|
||||
|
||||
enableChannelChat = config.getBoolean("enableChannelChat", true);
|
||||
playerChatEventListenerPriority
|
||||
= getEventPriority(config.getString("playerChatEventListenerPriority"), EventPriority.HIGH);
|
||||
noJoinAsGlobal = config.getBoolean("noJoinAsGlobal", true);
|
||||
loggingChat = config.getBoolean("loggingChat", true);
|
||||
loggingChatToHawkEye = config.getBoolean("loggingChatToHawkEye", true);
|
||||
loggingChatToPrism = config.getBoolean("loggingChatToPrism", true);
|
||||
displayChatOnConsole = config.getBoolean("displayChatOnConsole", true);
|
||||
globalMarker = config.getString("globalMarker", "!");
|
||||
zeroMemberRemove = config.getBoolean("zeroMemberRemove", false);
|
||||
showListOnJoin = config.getBoolean("showListOnJoin", false);
|
||||
createChannelOnJoinCommand =
|
||||
config.getBoolean("createChannelOnJoinCommand", false);
|
||||
|
||||
// チャンネルチャット有効のときだけ、globalChannel設定を読み込む
|
||||
// (see issue #58)
|
||||
if ( enableChannelChat ) {
|
||||
globalChannel = config.getString("globalChannel", "");
|
||||
} else {
|
||||
globalChannel = "";
|
||||
}
|
||||
// チャンネルチャット有効のときだけ、forceJoinChannels設定を読み込む
|
||||
// (see issue #58)
|
||||
if ( enableChannelChat ) {
|
||||
forceJoinChannels = config.getStringList("forceJoinChannels");
|
||||
} else {
|
||||
forceJoinChannels = new ArrayList<String>();
|
||||
}
|
||||
|
||||
if ( config.contains("formatConstraint") ) {
|
||||
formatConstraint = config.getStringList("formatConstraint");
|
||||
} else {
|
||||
formatConstraint = new ArrayList<String>();
|
||||
formatConstraint.add("%username");
|
||||
formatConstraint.add("%msg");
|
||||
}
|
||||
|
||||
defaultFormat = config.getString("defaultFormat",
|
||||
"&f[%color%ch&f]%prefix%username%suffix&a:&f %msg");
|
||||
defaultFormatForPrivateMessage =
|
||||
config.getString("defaultFormatForPrivateMessage",
|
||||
"&7[%player -> %to]&f %msg");
|
||||
|
||||
opListenAllChannel = config.getBoolean("opListenAllChannel", false);
|
||||
|
||||
minChannelNameLength = config.getInt("minChannelNameLength", 4);
|
||||
maxChannelNameLength = config.getInt("maxChannelNameLength", 20);
|
||||
|
||||
enableQuickChannelChat = config.getBoolean("enableQuickChannelChat", true);
|
||||
quickChannelChatSeparator = config.getString("quickChannelChatSeparator", ":");
|
||||
|
||||
sendBroadcastChannelChatToDynmap =
|
||||
config.getBoolean("sendBroadcastChannelChatToDynmap", true);
|
||||
sendFormattedMessageToDynmap =
|
||||
config.getBoolean("sendFormattedMessageToDynmap", false);
|
||||
dynmapChannel = config.getString("dynmapChannel", "");
|
||||
ngword = config.getStringList("ngword");
|
||||
ngwordAction = NGWordAction.fromID(config.getString("ngwordAction", "mask"));
|
||||
|
||||
ngwordCompiled = new ArrayList<Pattern>();
|
||||
for ( String word : ngword ) {
|
||||
ngwordCompiled.add(Pattern.compile(word));
|
||||
}
|
||||
|
||||
enableNormalChatMessageFormat =
|
||||
config.getBoolean("enableNormalChatMessageFormat", true);
|
||||
normalChatMessageFormat =
|
||||
config.getString("normalChatMessageFormat", "&f%prefix%username%suffix&a:&f %msg");
|
||||
enableNormalChatColorCode =
|
||||
config.getBoolean("enableNormalChatColorCode", true);
|
||||
|
||||
japanizeType = JapanizeType.fromID(config.getString("japanizeType"), JapanizeType.KANA);
|
||||
japanizeDisplayLine = config.getInt("japanizeDisplayLine", 2);
|
||||
if ( japanizeDisplayLine != 1 && japanizeDisplayLine != 2 ) {
|
||||
japanizeDisplayLine = 2;
|
||||
}
|
||||
japanizeLine1Format = config.getString("japanizeLine1Format", "%msg &6(%japanize)");
|
||||
japanizeLine2Format = config.getString("japanizeLine2Format", "&6[JP] %japanize");
|
||||
japanizeIgnorePlayerName = config.getBoolean("japanizeIgnorePlayerName", true);
|
||||
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}") ) {
|
||||
|
||||
// TODO コンソールに警告を表示する
|
||||
// String msg = String.format(
|
||||
// Resources.get("errmsgCannotUseForGlobal"), globalChannel);
|
||||
// LunaChat.getInstance().getLogger().warning(msg);
|
||||
globalChannel = "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルチャット機能を利用可能にするかどうか
|
||||
* @return enableChannelChatを返す
|
||||
*/
|
||||
public boolean isEnableChannelChat() {
|
||||
return enableChannelChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットイベントの処理優先度
|
||||
* @return playerChatEventListenerPriorityを返す
|
||||
*/
|
||||
public EventPriority getPlayerChatEventListenerPriority() {
|
||||
return playerChatEventListenerPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルチャットに入っていない人の発言を、グローバルとして扱うかどうか
|
||||
* @return noJoinAsGlobalを返す
|
||||
*/
|
||||
public boolean isNoJoinAsGlobal() {
|
||||
return noJoinAsGlobal;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルチャットの発言内容を、ログに残すかどうか
|
||||
* @return loggingChatを返す
|
||||
*/
|
||||
public boolean isLoggingChat() {
|
||||
return loggingChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルチャットの発言内容を、HawkEyeに記録するかどうか
|
||||
* @return loggingChatToHawkEye
|
||||
*/
|
||||
public boolean isLoggingChatToHawkEye() {
|
||||
return loggingChatToHawkEye;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルチャットの発言内容を、Prismに記録するかどうか
|
||||
* @return loggingChatToPrism
|
||||
*/
|
||||
public boolean isLoggingChatToPrism() {
|
||||
return loggingChatToPrism;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルチャットの発言内容を、コンソールに表示するかどうか
|
||||
* @return displayChatOnConsoleを返す
|
||||
*/
|
||||
public boolean isDisplayChatOnConsole() {
|
||||
return displayChatOnConsole;
|
||||
}
|
||||
|
||||
/**
|
||||
* グローバルマーカー これが発言の頭に入っている場合は、強制的にグローバル発言になる
|
||||
* @return globalMarkerを返す
|
||||
*/
|
||||
public String getGlobalMarker() {
|
||||
return globalMarker;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全てのメンバーが退出したときに、チャンネルを削除するかどうか
|
||||
* @return zeroMemberRemoveを返す
|
||||
*/
|
||||
public boolean isZeroMemberRemove() {
|
||||
return zeroMemberRemove;
|
||||
}
|
||||
|
||||
/**
|
||||
* ログイン時に、参加中チャンネルを表示するかどうか
|
||||
* @return showListOnJoinを返す
|
||||
*/
|
||||
public boolean isShowListOnJoin() {
|
||||
return showListOnJoin;
|
||||
}
|
||||
|
||||
/**
|
||||
* /ch join コマンドで存在しないチャンネルを指定したときに、チャンネルを新規作成して入室するかどうか
|
||||
* @return createChannelOnJoinCommandを返す
|
||||
*/
|
||||
public boolean isCreateChannelOnJoinCommand() {
|
||||
return createChannelOnJoinCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* サーバーに初参加したユーザーを参加させる、既定のチャンネル。<br/>
|
||||
* 参加させない場合は、から文字列 "" を指定すること。
|
||||
* @return globalChannelを返す
|
||||
*/
|
||||
public String getGlobalChannel() {
|
||||
return globalChannel;
|
||||
}
|
||||
|
||||
/**
|
||||
* サーバーに参加したユーザーに必ず参加させるチャンネル。<br/>
|
||||
* グローバルチャンネルとは別で指定できる。
|
||||
* @return globalChannelを返す
|
||||
*/
|
||||
public List<String> getForceJoinChannels() {
|
||||
return forceJoinChannels;
|
||||
}
|
||||
|
||||
/**
|
||||
* formatコマンド実行時に、必ず含まれる必要があるキーワード。
|
||||
* @return formatConstraintを返す
|
||||
*/
|
||||
public List<String> getFormatConstraint() {
|
||||
return formatConstraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルを作成したときに、デフォルトで設定されるフォーマット。
|
||||
* @return defaultFormatを返す
|
||||
*/
|
||||
public String getDefaultFormat() {
|
||||
return defaultFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* プライベートメッセージを送信するときに、適用されるフォーマット。
|
||||
* @return defaultFormatForPrivateMessageを返す
|
||||
*/
|
||||
public String getDefaultFormatForPrivateMessage() {
|
||||
return defaultFormatForPrivateMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* OPの画面に、全チャンネルの発言内容を表示するかどうか
|
||||
* @return opListenAllChannel opListenAllChannelを返す
|
||||
*/
|
||||
public boolean isOpListenAllChannel() {
|
||||
return opListenAllChannel;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルを新規作成するときに、チャンネル名が満たさなければならない、最低文字列長
|
||||
* @return minChannelNameLength
|
||||
*/
|
||||
public int getMinChannelNameLength() {
|
||||
return minChannelNameLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルを新規作成するときに、チャンネル名が満たさなければならない、最大文字列長
|
||||
* @return maxChannelNameLength
|
||||
*/
|
||||
public int getMaxChannelNameLength() {
|
||||
return maxChannelNameLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* クイックチャンネルチャット機能を有効化するかどうかを取得する
|
||||
* @return enableQuickChannelChat
|
||||
*/
|
||||
public boolean isEnableQuickChannelChat() {
|
||||
return enableQuickChannelChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* クイックチャンネルチャット機能に使用する記号
|
||||
* @return quickChannelChatSeparator
|
||||
*/
|
||||
public String getQuickChannelChatSeparator() {
|
||||
return quickChannelChatSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* NGワード
|
||||
* @return ngwordを返す
|
||||
* @deprecated 全て正規表現に変更するため、getNgwordCompiledを使用してください
|
||||
*/
|
||||
@Deprecated
|
||||
public List<String> getNgword() {
|
||||
return ngword;
|
||||
}
|
||||
|
||||
/**
|
||||
* NGワードを発言した人に対して実行するアクション<br/>
|
||||
* mask = マスクするのみ<br/>
|
||||
* kick = マスクしてチャンネルからキックする<br/>
|
||||
* ban = マスクしてチャンネルからBANする
|
||||
* @return ngwordActionを返す
|
||||
*/
|
||||
public NGWordAction getNgwordAction() {
|
||||
return ngwordAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* コンパイルされたNGワード
|
||||
* @return ngwordCompiledを返す
|
||||
*/
|
||||
public List<Pattern> getNgwordCompiled() {
|
||||
return ngwordCompiled;
|
||||
}
|
||||
|
||||
/**
|
||||
* ブロードキャストチャンネルの発言内容を、dynmapに送信するかどうか。<br/>
|
||||
* dynmapがロードされていない場合は、この設定は無視される(false扱い)。
|
||||
* @return sendBroadcastChannelChatToDynmapを返す
|
||||
*/
|
||||
public boolean isSendBroadcastChannelChatToDynmap() {
|
||||
return sendBroadcastChannelChatToDynmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* dynmapへ送信するときに、チャンネルのフォーマットを反映して送信するかどうか。
|
||||
* @return sendFormattedMessageToDynmapを返す
|
||||
*/
|
||||
public boolean isSendFormattedMessageToDynmap() {
|
||||
return sendFormattedMessageToDynmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* dynmapのWebUIから発言された発言内容を表示するチャンネル。
|
||||
* @return dynmapChannel dynmapの発言を表示するチャンネル名を返す
|
||||
*/
|
||||
public String getDynmapChannel() {
|
||||
return dynmapChannel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャット(非チャンネルチャット)の装飾を、LunaChatから行うかどうか
|
||||
* @return enableNormalChatMessageFormatを返す
|
||||
*/
|
||||
public boolean isEnableNormalChatMessageFormat() {
|
||||
return enableNormalChatMessageFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットの装飾フォーマット
|
||||
* @return normalChatMessageFormatを返す
|
||||
*/
|
||||
public String getNormalChatMessageFormat() {
|
||||
return normalChatMessageFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize変換のタイプ<br/>
|
||||
* none = 日本語変換をしない<br/>
|
||||
* kana = カナ変換のみする<br/>
|
||||
* googleime = カナ変換後、GoogleIMEで漢字変換する
|
||||
* @return japanizeTypeを返す
|
||||
*/
|
||||
public JapanizeType getJapanizeType() {
|
||||
return japanizeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize変換の1行表示と2行表示の切り替え<br/>
|
||||
* 1 = 1行表示<br/>
|
||||
* 2 = 2行表示<br/>
|
||||
* @return japanizeDisplayLineを返す
|
||||
*/
|
||||
public int getJapanizeDisplayLine() {
|
||||
return japanizeDisplayLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize変換の1行表示時のフォーマット
|
||||
* @return japanizeLine1Formatを返す
|
||||
*/
|
||||
public String getJapanizeLine1Format() {
|
||||
return japanizeLine1Format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize変換の2行表示時の2行目のフォーマット
|
||||
* @return japanizeLine2Formatを返す
|
||||
*/
|
||||
public String getJapanizeLine2Format() {
|
||||
return japanizeLine2Format;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言に含まれているプレイヤー名を、Japanize変換から除外するかどうか
|
||||
* @return japanizeIgnorePlayerName
|
||||
*/
|
||||
public boolean isJapanizeIgnorePlayerName() {
|
||||
return japanizeIgnorePlayerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* ノンジャパナイズマーカー これが発言の頭に入っている場合は、一時的にjapanizeを実行しない
|
||||
* @return noneJapanizeMarkerを返す
|
||||
*/
|
||||
public String getNoneJapanizeMarker() {
|
||||
return noneJapanizeMarker;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットで、JapanizeDisplayLine=2のとき、Japanize変換したあと表示するまでのウェイト(tick)
|
||||
* @return japanizeWaitを返す
|
||||
*/
|
||||
public int getJapanizeWait() {
|
||||
return japanizeWait;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットで、カラーコードを使用可能にするかどうか
|
||||
* @return enableNormalChatColorCodeを返す
|
||||
*/
|
||||
public boolean isEnableNormalChatColorCode() {
|
||||
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 文字列
|
||||
* @param def デフォルト
|
||||
* @return EventPriority
|
||||
*/
|
||||
private static EventPriority getEventPriority(String value, EventPriority def) {
|
||||
|
||||
if ( value == null ) return def;
|
||||
|
||||
if ( value.equalsIgnoreCase("LOWEST") ) {
|
||||
return EventPriority.LOWEST;
|
||||
} else if ( value.equalsIgnoreCase("LOW") ) {
|
||||
return EventPriority.LOW;
|
||||
} else if ( value.equalsIgnoreCase("NORMAL") ) {
|
||||
return EventPriority.NORMAL;
|
||||
} else if ( value.equalsIgnoreCase("HIGH") ) {
|
||||
return EventPriority.HIGH;
|
||||
} else if ( value.equalsIgnoreCase("HIGHEST") ) {
|
||||
return EventPriority.HIGHEST;
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
}
|
||||
@@ -1,251 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* LunaChatロガー
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatLogger {
|
||||
|
||||
private SimpleDateFormat lformat;
|
||||
private SimpleDateFormat dformat;
|
||||
|
||||
private SimpleDateFormat logYearDateFormat;
|
||||
|
||||
private File file;
|
||||
private String dirPath;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param name ログ名
|
||||
*/
|
||||
public LunaChatLogger(String name) {
|
||||
|
||||
lformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
dformat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
logYearDateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
|
||||
this.name = name;
|
||||
checkDir();
|
||||
}
|
||||
|
||||
/**
|
||||
* ログを出力する
|
||||
* @param message ログ内容
|
||||
* @param player 発言者名
|
||||
*/
|
||||
public synchronized void log(final String message, final String player) {
|
||||
|
||||
checkDir();
|
||||
|
||||
// 以降の処理を、発言処理の負荷軽減のため、非同期実行にする。(see issue #40.)
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
String msg = ChatColor.stripColor(message);
|
||||
if ( msg == null ) msg = "";
|
||||
msg = msg.replace(",", ",");
|
||||
FileWriter writer = null;
|
||||
try {
|
||||
writer = new FileWriter(file, true);
|
||||
String str = lformat.format(new Date()) +
|
||||
"," + msg + "," + player;
|
||||
writer.write(str + "\r\n");
|
||||
writer.flush();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if ( writer != null ) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
// do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* ログファイルを読み込んで、ログデータを取得する
|
||||
* @param player プレイヤー名、フィルタしないならnullを指定すること
|
||||
* @param filter フィルタ、フィルタしないならnullを指定すること
|
||||
* @param date 日付、今日のデータを取得するならnullを指定すること
|
||||
* @param reverse 逆順取得
|
||||
* @return ログデータ
|
||||
*/
|
||||
public ArrayList<String> getLog(
|
||||
String player, String filter, String date, boolean reverse) {
|
||||
|
||||
// 指定された日付のログを取得する
|
||||
File f = getLogFile(date);
|
||||
if ( f == null ) {
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
// ログファイルの読み込み
|
||||
ArrayList<String> data = readAllLines(f);
|
||||
|
||||
// プレイヤー指定なら、一致するプレイヤー名が含まれているログに絞る
|
||||
if ( player != null ) {
|
||||
ArrayList<String> temp = new ArrayList<String>(data);
|
||||
data = new ArrayList<String>();
|
||||
for ( String t : temp ) {
|
||||
String[] line = t.split(",");
|
||||
if ( line.length >= 3 && line[2].contains(player) ) {
|
||||
data.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// フィルタ指定なら、指定のキーワードが含まれているログに絞る
|
||||
if ( filter != null ) {
|
||||
ArrayList<String> temp = new ArrayList<String>(data);
|
||||
data = new ArrayList<String>();
|
||||
for ( String t : temp ) {
|
||||
String[] line = t.split(",");
|
||||
if ( line.length >= 2 && line[1].contains(filter) ) {
|
||||
data.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 逆順が指定されているなら、逆順に並び替える
|
||||
if ( reverse ) {
|
||||
Collections.reverse(data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* テキストファイルの内容を読み出す。
|
||||
* @param file ファイル
|
||||
* @return 内容
|
||||
*/
|
||||
private ArrayList<String> readAllLines(File file) {
|
||||
|
||||
ArrayList<String> data = new ArrayList<String>();
|
||||
|
||||
BufferedReader reader = null;
|
||||
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while ( (line = reader.readLine()) != null ) {
|
||||
line = line.trim();
|
||||
if ( line.length() > 0 ) {
|
||||
data.add(line);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if ( reader != null ) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された日付のログファイルを取得します。
|
||||
* 取得できない場合は、nullを返します。
|
||||
* @param date 日付
|
||||
* @return 指定された日付のログファイル
|
||||
*/
|
||||
private File getLogFile(String date) {
|
||||
|
||||
if ( date == null ) {
|
||||
return file;
|
||||
}
|
||||
|
||||
Date d;
|
||||
try {
|
||||
if ( date.matches("[0-9]{4}") ) {
|
||||
date = Calendar.getInstance().get(Calendar.YEAR) + date;
|
||||
}
|
||||
if ( date.matches("[0-9]{8}") ) {
|
||||
d = logYearDateFormat.parse(date);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
File folder = new File(getFolderPath(d));
|
||||
if ( !folder.exists() || !folder.isDirectory() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File f = new File(folder, name + ".log");
|
||||
if ( !f.exists() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* ログの出力先フォルダをチェックし、変更されるなら更新する。
|
||||
*/
|
||||
private void checkDir() {
|
||||
|
||||
String temp = getFolderPath(new Date());
|
||||
if ( temp.equals(dirPath) ) {
|
||||
return;
|
||||
}
|
||||
dirPath = temp;
|
||||
|
||||
File dir = new File(dirPath);
|
||||
if ( !dir.exists() || !dir.isDirectory() ) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
file = new File(dir, name + ".log");
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された日付のログファイル名を生成して返します。
|
||||
* @param date 日付
|
||||
* @return ログファイル名
|
||||
*/
|
||||
private String getFolderPath(Date date) {
|
||||
|
||||
return LunaChat.getDataFolder() +
|
||||
File.separator + "logs" +
|
||||
File.separator + dformat.format(date);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
/**
|
||||
* LunaChatの動作モード
|
||||
* @author ucchy
|
||||
*/
|
||||
public enum LunaChatMode {
|
||||
BUKKIT,
|
||||
BUNGEE,
|
||||
STANDALONE,
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* プラグインのメッセージリソース管理クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class Messages {
|
||||
|
||||
private static final String BASE_NAME = "messages";
|
||||
private static final String FILE_NAME = BASE_NAME + ".yml";
|
||||
|
||||
private static YamlConfig resources;
|
||||
|
||||
/**
|
||||
* 初期化する
|
||||
*/
|
||||
protected static void initialize() {
|
||||
|
||||
File file = new File(
|
||||
LunaChat.getDataFolder() +
|
||||
File.separator + FILE_NAME);
|
||||
|
||||
if ( !file.exists() ) {
|
||||
Utility.copyFileFromJar(LunaChat.getPluginJarFile(),
|
||||
file, FILE_NAME, false);
|
||||
}
|
||||
|
||||
resources = YamlConfig.load(file);
|
||||
resources.addDefaults(loadDefaultMessages());
|
||||
}
|
||||
|
||||
/**
|
||||
* リソースを取得する
|
||||
* @param key リソースキー
|
||||
* @return リソース
|
||||
*/
|
||||
public static String get(String key) {
|
||||
|
||||
if ( resources == null ) {
|
||||
initialize();
|
||||
}
|
||||
return Utility.replaceColorCode(resources.getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Jarファイル内から直接 messages.yml を読み込み、YamlConfigにして返すメソッド
|
||||
* @return
|
||||
*/
|
||||
private static YamlConfig loadDefaultMessages() {
|
||||
try {
|
||||
return YamlConfig.load(getResourceInputStream());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Jarファイル内を検索して、現在のlanguageやcountryになるべく一致するリソースを見つけて、InputStreamで返す
|
||||
* @return InputStream
|
||||
*/
|
||||
private static InputStream getResourceInputStream() {
|
||||
|
||||
String baseName = BASE_NAME;
|
||||
Locale locale = Locale.getDefault();
|
||||
|
||||
ArrayList<String> candidates = new ArrayList<String>();
|
||||
candidates.add(String.format("/%s_%s_%s.yaml", baseName, locale.getLanguage(), locale.getCountry()));
|
||||
candidates.add(String.format("/%s_%s_%s.yml", baseName, locale.getLanguage(), locale.getCountry()));
|
||||
candidates.add(String.format("/%s_%s.yaml", baseName, locale.getLanguage()));
|
||||
candidates.add(String.format("/%s_%s.yml", baseName, locale.getLanguage()));
|
||||
candidates.add("/" + baseName + ".yaml");
|
||||
candidates.add("/" + baseName + ".yml");
|
||||
|
||||
for ( String name : candidates ) {
|
||||
InputStream stream = Messages.class.getResourceAsStream(name);
|
||||
if ( stream != null ) return stream;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
|
||||
/**
|
||||
* NGワードを発言した人に与えるアクションの設定の種類
|
||||
* @author ucchy
|
||||
*/
|
||||
public enum NGWordAction {
|
||||
|
||||
/** マスクするのみ */
|
||||
MASK("mask"),
|
||||
|
||||
/** マスクしつつ、チャンネルからMuteする */
|
||||
MUTE("mute"),
|
||||
|
||||
/** マスクしつつ、チャンネルからキックする */
|
||||
KICK("kick"),
|
||||
|
||||
/** マスクしつつ、チャンネルからBANする */
|
||||
BAN("ban");
|
||||
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param id ID
|
||||
*/
|
||||
NGWordAction(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 識別文字列を返す
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 識別文字列から、NGWordActionを作成して返す。
|
||||
* 無効な文字列が指定された場合は、nullが返される。
|
||||
* @param id 識別文字列
|
||||
* @return 対応したNGWordAction
|
||||
*/
|
||||
public static NGWordAction fromID(String id) {
|
||||
if ( id == null ) {
|
||||
return null;
|
||||
}
|
||||
for (NGWordAction value : values()) {
|
||||
if (id.equalsIgnoreCase(value.id)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* プラグインインターフェイス
|
||||
* @author ucchy
|
||||
*/
|
||||
public interface PluginInterface {
|
||||
|
||||
/**
|
||||
* このプラグインのJarファイル自身を示すFileクラスを返す。
|
||||
* @return Jarファイル
|
||||
*/
|
||||
public File getPluginJarFile();
|
||||
|
||||
/**
|
||||
* LunaChatConfigを取得する
|
||||
* @return LunaChatConfig
|
||||
*/
|
||||
public LunaChatConfig getLunaChatConfig();
|
||||
|
||||
/**
|
||||
* LunaChatAPIを取得する
|
||||
* @return LunaChatAPI
|
||||
*/
|
||||
public LunaChatAPI getLunaChatAPI();
|
||||
|
||||
/**
|
||||
* プラグインのデータ格納フォルダを取得する
|
||||
* @return データ格納フォルダ
|
||||
*/
|
||||
public File getDataFolder();
|
||||
|
||||
/**
|
||||
* 通常チャット用のロガーを返す
|
||||
* @return normalChatLogger
|
||||
*/
|
||||
public LunaChatLogger getNormalChatLogger();
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
/**
|
||||
* ユーティリティクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class Utility {
|
||||
|
||||
/**
|
||||
* jarファイルの中に格納されているファイルを、jarファイルの外にコピーするメソッド
|
||||
* @param jarFile jarファイル
|
||||
* @param targetFile コピー先
|
||||
* @param sourceFilePath コピー元
|
||||
* @param isBinary バイナリファイルかどうか
|
||||
*/
|
||||
public static void copyFileFromJar(
|
||||
File jarFile, File targetFile, String sourceFilePath, boolean isBinary) {
|
||||
|
||||
File parent = targetFile.getParentFile();
|
||||
if (!parent.exists()) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
|
||||
try ( JarFile jar = new JarFile(jarFile) ) {
|
||||
ZipEntry zipEntry = jar.getEntry(sourceFilePath);
|
||||
InputStream is = jar.getInputStream(zipEntry);
|
||||
|
||||
try ( FileOutputStream fos = new FileOutputStream(targetFile) ) {
|
||||
|
||||
if (isBinary) {
|
||||
byte[] buf = new byte[8192];
|
||||
int len;
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
fos.write(buf, 0, len);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
try ( BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")) ) {
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列内のカラーコード候補(&a)を、カラーコード(§a)に置き換えする
|
||||
* @param source 置き換え元の文字列
|
||||
* @return 置き換え後の文字列
|
||||
*/
|
||||
public static String replaceColorCode(String source) {
|
||||
if (source == null) return null;
|
||||
return source.replaceAll("&([0-9a-fk-or])", "\u00A7$1");
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列に含まれているカラーコード(§a)を除去して返す
|
||||
* @param source 置き換え元の文字列
|
||||
* @return 置き換え後の文字列
|
||||
*/
|
||||
public static String stripColorCode(String source) {
|
||||
if (source == null) return null;
|
||||
return source.replaceAll("&([0-9a-fk-or])", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* カラーコード(§a)かどうかを判断する
|
||||
* @param code カラーコード
|
||||
* @return カラーコードかどうか
|
||||
*/
|
||||
public static boolean isColorCode(String code) {
|
||||
if (code == null) return false;
|
||||
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 アスタリスクの個数
|
||||
* @return 指定された文字数のアスタリスク
|
||||
*/
|
||||
public static String getAstariskString(int length) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (int i = 0; i < length; i++) {
|
||||
buf.append("*");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された名前のプレイヤーが接続したことがあるかどうかを検索する
|
||||
* @param name プレイヤー名
|
||||
* @return 接続したことがあるかどうか
|
||||
*/
|
||||
public static boolean existsOfflinePlayer(String name) {
|
||||
// TODO 未実装
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* @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));
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bridge;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.dynmap.DynmapAPI;
|
||||
import org.dynmap.DynmapWebChatEvent;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
|
||||
/**
|
||||
* dynmap連携クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class DynmapBridge implements Listener {
|
||||
|
||||
/** dynmap-apiクラス */
|
||||
private DynmapAPI dynmap;
|
||||
|
||||
/** コンストラクタは使用不可 */
|
||||
private DynmapBridge() {
|
||||
}
|
||||
|
||||
/**
|
||||
* dynmap-apiをロードする
|
||||
* @param plugin dynmap-apiのプラグインインスタンス
|
||||
* @param ロードしたかどうか
|
||||
*/
|
||||
public static DynmapBridge load(Plugin plugin) {
|
||||
|
||||
if ( plugin instanceof DynmapAPI ) {
|
||||
DynmapBridge bridge = new DynmapBridge();
|
||||
bridge.dynmap = (DynmapAPI)plugin;
|
||||
return bridge;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dynmapにプレイヤーのチャットを流す
|
||||
* @param player プレイヤー
|
||||
* @param message 発言内容
|
||||
*/
|
||||
public void chat(Player player, String message) {
|
||||
|
||||
dynmap.postPlayerMessageToWeb(player, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* dynmapにブロードキャストメッセージを流す
|
||||
* @param message メッセージ
|
||||
*/
|
||||
public void broadcast(String message) {
|
||||
|
||||
dynmap.sendBroadcastToWeb(null, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* DynmapのWebUIからチャット発言されたときのイベント
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onDynmapWebChat(DynmapWebChatEvent event) {
|
||||
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
String dchannel = config.getDynmapChannel();
|
||||
Channel channel = null;
|
||||
|
||||
if ( !dchannel.equals("") ) {
|
||||
// dynmapChannelが設定されている場合
|
||||
channel = api.getChannel(dchannel);
|
||||
|
||||
} else {
|
||||
String gchannel = config.getGlobalChannel();
|
||||
if ( !gchannel.equals("") ) {
|
||||
// dynmapChannelが設定されていなくて、
|
||||
// globalChannelが設定されている場合
|
||||
channel = api.getChannel(gchannel);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( channel != null ) {
|
||||
// チャンネルへ送信
|
||||
channel.chatFromOtherSource(
|
||||
event.getName(), event.getSource(), event.getMessage());
|
||||
event.setProcessed();
|
||||
dynmap.sendBroadcastToWeb(null, event.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bridge;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
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.bukkit.LunaChatBukkit;
|
||||
import com.github.ucchyocean.lc.channel.DelayedJapanizeRecipientChatTask;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
import com.gmail.nossr50.api.PartyAPI;
|
||||
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
|
||||
|
||||
/**
|
||||
* mcMMO連携クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class McMMOBridge implements Listener {
|
||||
|
||||
/**
|
||||
* mcMMOのパーティチャットが発生したときのイベント
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onMcMMOPartyChatEvent(McMMOPartyChatEvent event) {
|
||||
|
||||
// mcMMOから、パーティのメンバーを取得する
|
||||
List<Player> recipients = PartyAPI.getOnlineMembers(event.getParty());
|
||||
|
||||
String message = event.getMessage();
|
||||
ChannelMember player = ChannelMember.getChannelMember(event.getSender());
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
// NGワード発言をマスク
|
||||
for ( Pattern pattern : config.getNgwordCompiled() ) {
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
if ( matcher.find() ) {
|
||||
message = matcher.replaceAll(
|
||||
Utility.getAstariskString(matcher.group(0).length()));
|
||||
}
|
||||
}
|
||||
|
||||
// カラーコード置き換え
|
||||
// 置き換え設定になっていて、発言者がパーミッションを持っているなら、置き換えする
|
||||
if ( config.isEnableNormalChatColorCode() &&
|
||||
player.hasPermission("lunachat.allowcc") ) {
|
||||
message = Utility.replaceColorCode(message);
|
||||
}
|
||||
|
||||
// 一時的にJapanizeスキップ設定かどうかを確認する
|
||||
boolean skipJapanize = false;
|
||||
String marker = config.getNoneJapanizeMarker();
|
||||
if ( !marker.equals("") && message.startsWith(marker) ) {
|
||||
skipJapanize = true;
|
||||
message = message.substring(marker.length());
|
||||
}
|
||||
|
||||
// 2byteコードを含むなら、Japanize変換は行わない
|
||||
String kanaTemp = Utility.stripColorCode(message);
|
||||
if ( !skipJapanize &&
|
||||
( kanaTemp.getBytes().length > kanaTemp.length() ||
|
||||
kanaTemp.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
skipJapanize = true;
|
||||
}
|
||||
|
||||
// Japanize変換と、発言処理
|
||||
if ( !skipJapanize &&
|
||||
LunaChat.getAPI().isPlayerJapanize(player.getName()) &&
|
||||
config.getJapanizeType() != JapanizeType.NONE ) {
|
||||
|
||||
int lineType = config.getJapanizeDisplayLine();
|
||||
|
||||
if ( lineType == 1 ) {
|
||||
|
||||
String taskFormat = Utility.replaceColorCode(config.getJapanizeLine1Format());
|
||||
|
||||
String japanized = api.japanize(
|
||||
kanaTemp, config.getJapanizeType());
|
||||
if ( japanized != null ) {
|
||||
String temp = taskFormat.replace("%msg", message);
|
||||
message = temp.replace("%japanize", japanized);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
String taskFormat = Utility.replaceColorCode(config.getJapanizeLine2Format());
|
||||
|
||||
DelayedJapanizeRecipientChatTask task = new DelayedJapanizeRecipientChatTask(
|
||||
message, config.getJapanizeType(), player, taskFormat, recipients);
|
||||
|
||||
// 発言処理を必ず先に実施させるため、遅延を入れてタスクを実行する。
|
||||
int wait = config.getJapanizeWait();
|
||||
task.runTaskLater(LunaChatBukkit.getInstance(), wait);
|
||||
}
|
||||
}
|
||||
|
||||
// 発言内容の設定
|
||||
event.setMessage(message);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bridge;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.Core;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
|
||||
/**
|
||||
* MultiverseCore連携クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class MultiverseCoreBridge {
|
||||
|
||||
/** MultiverseCore API クラス */
|
||||
private Core mvc;
|
||||
|
||||
/** コンストラクタは使用不可 */
|
||||
private MultiverseCoreBridge() {
|
||||
}
|
||||
|
||||
/**
|
||||
* MultiverseCore-apiをロードする
|
||||
* @param plugin MultiverseCoreのプラグインインスタンス
|
||||
* @param ロードしたかどうか
|
||||
*/
|
||||
public static MultiverseCoreBridge load(Plugin plugin) {
|
||||
|
||||
if ( plugin instanceof MultiverseCore ) {
|
||||
MultiverseCoreBridge bridge = new MultiverseCoreBridge();
|
||||
bridge.mvc = (Core)plugin;
|
||||
return bridge;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたワールドのエイリアス名を取得する
|
||||
* @param worldName ワールド名
|
||||
* @return エイリアス名、取得できない場合はnullが返される
|
||||
*/
|
||||
public String getWorldAlias(String worldName) {
|
||||
|
||||
MultiverseWorld mvworld = mvc.getMVWorldManager().getMVWorld(worldName);
|
||||
if ( mvworld != null ) {
|
||||
return mvworld.getColoredWorldString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたワールドのエイリアス名を取得する
|
||||
* @param world ワールド
|
||||
* @return エイリアス名、取得できない場合はnullが返される
|
||||
*/
|
||||
public String getWorldAlias(World world) {
|
||||
|
||||
MultiverseWorld mvworld = mvc.getMVWorldManager().getMVWorld(world);
|
||||
if ( mvworld != null ) {
|
||||
return mvworld.getColoredWorldString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bridge;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
|
||||
/**
|
||||
* Vault-Chat連携クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class VaultChatBridge {
|
||||
|
||||
/** vault-chatクラス */
|
||||
private Chat chatPlugin;
|
||||
|
||||
/** コンストラクタは使用不可 */
|
||||
private VaultChatBridge() {
|
||||
}
|
||||
|
||||
/**
|
||||
* vault-chatをロードする
|
||||
* @param plugin vaultのプラグインインスタンス
|
||||
* @return ロードしたブリッジのインスタンス
|
||||
*/
|
||||
public static VaultChatBridge load(Plugin plugin) {
|
||||
|
||||
RegisteredServiceProvider<Chat> chatProvider =
|
||||
Bukkit.getServicesManager().getRegistration(Chat.class);
|
||||
if ( chatProvider != null ) {
|
||||
VaultChatBridge bridge = new VaultChatBridge();
|
||||
bridge.chatPlugin = chatProvider.getProvider();
|
||||
return bridge;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのprefixを取得します。
|
||||
* @param player プレイヤー
|
||||
* @return プレイヤーのprefix
|
||||
*/
|
||||
public String getPlayerPrefix(Player player) {
|
||||
return chatPlugin.getPlayerPrefix(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのsuffixを取得します。
|
||||
* @param player プレイヤー
|
||||
* @return プレイヤーのsuffix
|
||||
*/
|
||||
public String getPlayerSuffix(Player player) {
|
||||
return chatPlugin.getPlayerSuffix(player);
|
||||
}
|
||||
}
|
||||
@@ -1,617 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bukkit;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc.Messages;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.bridge.VaultChatBridge;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.channel.DelayedJapanizeNormalChatTask;
|
||||
import com.github.ucchyocean.lc.event.LunaChatPreChatEvent;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc.member.ChannelMemberBukkit;
|
||||
|
||||
/**
|
||||
* Bukkit関連のイベントを監視するリスナ
|
||||
* @author ucchy
|
||||
*/
|
||||
public class BukkitEventListener implements Listener {
|
||||
|
||||
private static final String MOTD_FIRSTLINE = Messages.get("motdFirstLine");
|
||||
private static final String LIST_ENDLINE = Messages.get("listEndLine");
|
||||
private static final String LIST_FORMAT = Messages.get("listFormat");
|
||||
private static final String PREERR = Messages.get("errorPrefix");
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
*/
|
||||
public BukkitEventListener() {
|
||||
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
timeFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーがチャット発言したときに呼び出されるメソッド
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.LOWEST, ignoreCancelled=true)
|
||||
public void onAsyncPlayerChatLowest(AsyncPlayerChatEvent event) {
|
||||
if ( matchesEventPriority(EventPriority.LOWEST) ) {
|
||||
processChatEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーがチャット発言したときに呼び出されるメソッド
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.LOW, ignoreCancelled=true)
|
||||
public void onAsyncPlayerChatLow(AsyncPlayerChatEvent event) {
|
||||
if ( matchesEventPriority(EventPriority.LOW) ) {
|
||||
processChatEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーがチャット発言したときに呼び出されるメソッド
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=true)
|
||||
public void onAsyncPlayerChatNormal(AsyncPlayerChatEvent event) {
|
||||
if ( matchesEventPriority(EventPriority.NORMAL) ) {
|
||||
processChatEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーがチャット発言したときに呼び出されるメソッド
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
|
||||
public void onAsyncPlayerChatHigh(AsyncPlayerChatEvent event) {
|
||||
if ( matchesEventPriority(EventPriority.HIGH) ) {
|
||||
processChatEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーがチャット発言したときに呼び出されるメソッド
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
|
||||
public void onAsyncPlayerChatHighest(AsyncPlayerChatEvent event) {
|
||||
if ( matchesEventPriority(EventPriority.HIGHEST) ) {
|
||||
processChatEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのサーバー参加ごとに呼び出されるメソッド
|
||||
* @param event プレイヤー参加イベント
|
||||
*/
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
// 強制参加チャンネル設定を確認し、参加させる
|
||||
forceJoinToForceJoinChannels(player);
|
||||
|
||||
// グローバルチャンネル設定がある場合
|
||||
if ( !config.getGlobalChannel().equals("") ) {
|
||||
tryJoinToGlobalChannel(player);
|
||||
}
|
||||
|
||||
// チャンネルチャット情報を表示する
|
||||
if ( config.isShowListOnJoin() ) {
|
||||
ArrayList<String> list = getListForMotd(player);
|
||||
for ( String msg : list ) {
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのサーバー退出ごとに呼び出されるメソッド
|
||||
* @param event プレイヤー退出イベント
|
||||
*/
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
String pname = player.getName();
|
||||
|
||||
// お互いがオフラインになるPMチャンネルがある場合は
|
||||
// チャンネルをクリアする
|
||||
ArrayList<Channel> deleteList = new ArrayList<Channel>();
|
||||
|
||||
for ( Channel channel : LunaChat.getAPI().getChannels() ) {
|
||||
String cname = channel.getName();
|
||||
if ( channel.isPersonalChat() && cname.contains(pname) ) {
|
||||
boolean isAllOffline = true;
|
||||
for ( ChannelMember cp : channel.getMembers() ) {
|
||||
// TODO
|
||||
if ( cp.isOnline() ) {
|
||||
isAllOffline = false;
|
||||
}
|
||||
}
|
||||
if ( isAllOffline ) {
|
||||
deleteList.add(channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( Channel channel : deleteList ) {
|
||||
LunaChat.getAPI().removeChannel(channel.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのチャットごとに呼び出されるメソッド
|
||||
* @param event チャットイベント
|
||||
*/
|
||||
private void processChatEvent(AsyncPlayerChatEvent event) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
// 頭にglobalMarkerが付いている場合は、グローバル発言にする
|
||||
if ( config.getGlobalMarker() != null &&
|
||||
!config.getGlobalMarker().equals("") &&
|
||||
event.getMessage().startsWith(config.getGlobalMarker()) &&
|
||||
event.getMessage().length() > config.getGlobalMarker().length() ) {
|
||||
|
||||
int offset = config.getGlobalMarker().length();
|
||||
event.setMessage( event.getMessage().substring(offset) );
|
||||
chatGlobal(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// クイックチャンネルチャット機能が有効で、専用の記号が含まれるなら、
|
||||
// クイックチャンネルチャットとして処理する。
|
||||
if ( config.isEnableQuickChannelChat() ) {
|
||||
String separator = config.getQuickChannelChatSeparator();
|
||||
if ( event.getMessage().contains(separator) ) {
|
||||
String[] temp = event.getMessage().split(separator, 2);
|
||||
String name = temp[0];
|
||||
String value = "";
|
||||
if ( temp.length > 0 ) {
|
||||
value = temp[1];
|
||||
}
|
||||
|
||||
Channel channel = api.getChannel(name);
|
||||
if ( channel != null && !channel.isPersonalChat() ) {
|
||||
ChannelMember player =
|
||||
ChannelMember.getChannelMember(event.getPlayer());
|
||||
if ( !channel.getMembers().contains(player) ) {
|
||||
// 指定されたチャンネルに参加していないなら、エラーを表示して何も発言せずに終了する。
|
||||
sendResourceMessage(event.getPlayer(), PREERR, "errmsgNomember");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// 指定されたチャンネルに発言して終了する。
|
||||
chatToChannelWithEvent(player, channel, value);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ChannelMember player =
|
||||
ChannelMember.getChannelMember(event.getPlayer());
|
||||
Channel channel = api.getDefaultChannel(player.getName());
|
||||
|
||||
// デフォルトの発言先が無い場合
|
||||
if ( channel == null ) {
|
||||
if ( config.isNoJoinAsGlobal() ) {
|
||||
// グローバル発言にする
|
||||
chatGlobal(event);
|
||||
return;
|
||||
|
||||
} else {
|
||||
// 発言をキャンセルして終了する
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
chatToChannelWithEvent(player, channel, event.getMessage());
|
||||
|
||||
// もとのイベントをキャンセル
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* イベントをグローバルチャット発言として処理する
|
||||
* @param event 処理するイベント
|
||||
*/
|
||||
private void chatGlobal(AsyncPlayerChatEvent event) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
ChannelMember player =
|
||||
ChannelMember.getChannelMember(event.getPlayer());
|
||||
|
||||
if ( !config.getGlobalChannel().equals("") ) {
|
||||
// グローバルチャンネル設定がある場合
|
||||
|
||||
// グローバルチャンネルの取得、無ければ作成
|
||||
Channel global = api.getChannel(config.getGlobalChannel());
|
||||
if ( global == null ) {
|
||||
global = api.createChannel(config.getGlobalChannel());
|
||||
}
|
||||
|
||||
// LunaChatPreChatEvent イベントコール
|
||||
LunaChatPreChatEvent preChatEvent = new LunaChatPreChatEvent(
|
||||
global.getName(), player, event.getMessage());
|
||||
Bukkit.getPluginManager().callEvent(preChatEvent);
|
||||
if ( preChatEvent.isCancelled() ) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Channel alt = preChatEvent.getChannel();
|
||||
if ( alt != null ) {
|
||||
global = alt;
|
||||
}
|
||||
String message = preChatEvent.getMessage();
|
||||
|
||||
// デフォルト発言先が無いなら、グローバルチャンネルに設定する
|
||||
Channel dchannel = api.getDefaultChannel(player.getName());
|
||||
if ( dchannel == null ) {
|
||||
api.setDefaultChannel(player.getName(), global.getName());
|
||||
}
|
||||
|
||||
// チャンネルチャット発言
|
||||
chatToChannelWithEvent(player, global, message);
|
||||
|
||||
// もとのイベントをキャンセル
|
||||
event.setCancelled(true);
|
||||
|
||||
return;
|
||||
|
||||
} else {
|
||||
// グローバルチャンネル設定が無い場合
|
||||
|
||||
String message = event.getMessage();
|
||||
// NGワード発言をマスク
|
||||
for ( Pattern pattern : config.getNgwordCompiled() ) {
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
if ( matcher.find() ) {
|
||||
message = matcher.replaceAll(
|
||||
Utility.getAstariskString(matcher.group(0).length()));
|
||||
}
|
||||
}
|
||||
|
||||
// チャットフォーマット装飾の適用
|
||||
if ( config.isEnableNormalChatMessageFormat() ) {
|
||||
String format = config.getNormalChatMessageFormat();
|
||||
format = replaceNormalChatFormatKeywords(format, event.getPlayer());
|
||||
event.setFormat(format);
|
||||
}
|
||||
|
||||
// カラーコード置き換え
|
||||
// 置き換え設定になっていて、発言者がパーミッションを持っているなら、置き換えする
|
||||
if ( config.isEnableNormalChatColorCode() &&
|
||||
event.getPlayer().hasPermission("lunachat.allowcc") ) {
|
||||
message = Utility.replaceColorCode(message);
|
||||
}
|
||||
|
||||
// hideされているプレイヤーを、recipientから抜く
|
||||
for ( ChannelMember cp : api.getHidelist(player) ) {
|
||||
Player p = ((ChannelMemberBukkit)cp).getPlayer();
|
||||
if ( p != null ) {
|
||||
event.getRecipients().remove(p);
|
||||
}
|
||||
}
|
||||
|
||||
// 一時的にJapanizeスキップ設定かどうかを確認する
|
||||
boolean skipJapanize = false;
|
||||
String marker = config.getNoneJapanizeMarker();
|
||||
if ( !marker.equals("") && message.startsWith(marker) ) {
|
||||
skipJapanize = true;
|
||||
message = message.substring(marker.length());
|
||||
}
|
||||
|
||||
// 2byteコードを含むなら、Japanize変換は行わない
|
||||
String kanaTemp = Utility.stripColorCode(message);
|
||||
if ( !skipJapanize &&
|
||||
( kanaTemp.getBytes().length > kanaTemp.length() ||
|
||||
kanaTemp.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
skipJapanize = true;
|
||||
}
|
||||
|
||||
// Japanize変換と、発言処理
|
||||
if ( !skipJapanize &&
|
||||
LunaChat.getAPI().isPlayerJapanize(player.getName()) &&
|
||||
config.getJapanizeType() != JapanizeType.NONE ) {
|
||||
|
||||
int lineType = config.getJapanizeDisplayLine();
|
||||
|
||||
if ( lineType == 1 ) {
|
||||
|
||||
String taskFormat = Utility.replaceColorCode(config.getJapanizeLine1Format());
|
||||
|
||||
String japanized = api.japanize(
|
||||
kanaTemp, config.getJapanizeType());
|
||||
if ( japanized != null ) {
|
||||
String temp = taskFormat.replace("%msg", message);
|
||||
message = temp.replace("%japanize", japanized);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
String taskFormat = Utility.replaceColorCode(config.getJapanizeLine2Format());
|
||||
|
||||
DelayedJapanizeNormalChatTask task = new DelayedJapanizeNormalChatTask(
|
||||
message, config.getJapanizeType(), player, taskFormat, event);
|
||||
|
||||
// 発言処理を必ず先に実施させるため、遅延を入れてタスクを実行する。
|
||||
int wait = config.getJapanizeWait();
|
||||
task.runTaskLater(LunaChatBukkit.getInstance(), wait);
|
||||
}
|
||||
}
|
||||
|
||||
// 発言内容の設定
|
||||
event.setMessage(message);
|
||||
|
||||
// ロギング
|
||||
logNormalChat(message, player.getName());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 既定のチャンネルへの参加を試みる。
|
||||
* @param player プレイヤー
|
||||
* @return 参加できたかどうか
|
||||
*/
|
||||
private boolean tryJoinToGlobalChannel(Player player) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
String gcName = config.getGlobalChannel();
|
||||
|
||||
// チャンネルが存在しない場合は作成する
|
||||
Channel global = api.getChannel(gcName);
|
||||
if ( global == null ) {
|
||||
global = api.createChannel(gcName);
|
||||
}
|
||||
|
||||
// デフォルト発言先が無いなら、グローバルチャンネルに設定する
|
||||
Channel dchannel = api.getDefaultChannel(player.getName());
|
||||
if ( dchannel == null ) {
|
||||
api.setDefaultChannel(player.getName(), gcName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 強制参加チャンネルへ参加させる
|
||||
* @param player プレイヤー
|
||||
*/
|
||||
private void forceJoinToForceJoinChannels(Player player) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
List<String> forceJoinChannels = config.getForceJoinChannels();
|
||||
|
||||
for ( String cname : forceJoinChannels ) {
|
||||
|
||||
// チャンネルが存在しない場合は作成する
|
||||
Channel channel = api.getChannel(cname);
|
||||
if ( channel == null ) {
|
||||
channel = api.createChannel(cname);
|
||||
}
|
||||
|
||||
// チャンネルのメンバーでないなら、参加する
|
||||
ChannelMember cp = ChannelMember.getChannelMember(player);
|
||||
if ( !channel.getMembers().contains(cp) ) {
|
||||
channel.addMember(cp);
|
||||
}
|
||||
|
||||
// デフォルト発言先が無いなら、グローバルチャンネルに設定する
|
||||
Channel dchannel = api.getDefaultChannel(player.getName());
|
||||
if ( dchannel == null ) {
|
||||
api.setDefaultChannel(player.getName(), cname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットのフォーマット設定のキーワードを置き換えして返す
|
||||
* @param org フォーマット設定
|
||||
* @param player 発言プレイヤー
|
||||
* @return キーワード置き換え済みの文字列
|
||||
*/
|
||||
private String replaceNormalChatFormatKeywords(String org, Player player) {
|
||||
|
||||
String format = org;
|
||||
format = format.replace("%username", "%1$s");
|
||||
format = format.replace("%msg", "%2$s");
|
||||
format = format.replace("%player", player.getName());
|
||||
|
||||
if ( format.contains("%date") ) {
|
||||
format = format.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( format.contains("%time") ) {
|
||||
format = format.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( format.contains("%prefix") || format.contains("%suffix") ) {
|
||||
|
||||
String prefix = "";
|
||||
String suffix = "";
|
||||
VaultChatBridge vaultchat = LunaChatBukkit.getInstance().getVaultChat();
|
||||
if ( vaultchat != null ) {
|
||||
prefix = vaultchat.getPlayerPrefix(player);
|
||||
suffix = vaultchat.getPlayerSuffix(player);
|
||||
}
|
||||
format = format.replace("%prefix", prefix);
|
||||
format = format.replace("%suffix", suffix);
|
||||
}
|
||||
|
||||
if ( format.contains("%world") ) {
|
||||
|
||||
String worldname = null;
|
||||
if ( LunaChatBukkit.getInstance().getMultiverseCore() != null ) {
|
||||
worldname = LunaChatBukkit.getInstance().getMultiverseCore().getWorldAlias(player.getWorld());
|
||||
}
|
||||
if ( worldname == null || worldname.equals("") ) {
|
||||
worldname = player.getWorld().getName();
|
||||
}
|
||||
format = format.replace("%world", worldname);
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(format);
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのサーバー参加時用の参加チャンネルリストを返す
|
||||
* @param player プレイヤー
|
||||
* @return リスト
|
||||
*/
|
||||
private ArrayList<String> getListForMotd(Player player) {
|
||||
|
||||
ChannelMember cp = ChannelMember.getChannelMember(player);
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
Channel dc = api.getDefaultChannel(cp.getName());
|
||||
String dchannel = "";
|
||||
if ( dc != null ) {
|
||||
dchannel = dc.getName().toLowerCase();
|
||||
}
|
||||
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
items.add(MOTD_FIRSTLINE);
|
||||
for ( Channel channel : api.getChannels() ) {
|
||||
|
||||
// BANされているチャンネルは表示しない
|
||||
if ( channel.getBanned().contains(cp) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 個人チャットはリストに表示しない
|
||||
if ( channel.isPersonalChat() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 参加していないチャンネルは、グローバルチャンネルを除き表示しない
|
||||
if ( !channel.getMembers().contains(cp) &&
|
||||
!channel.isGlobalChannel() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String disp = ChatColor.WHITE + channel.getName();
|
||||
if ( channel.getName().equals(dchannel) ) {
|
||||
disp = ChatColor.RED + channel.getName();
|
||||
}
|
||||
String desc = channel.getDescription();
|
||||
int onlineNum = channel.getOnlineNum();
|
||||
int memberNum = channel.getTotalNum();
|
||||
String item = String.format(
|
||||
LIST_FORMAT, disp, onlineNum, memberNum, desc);
|
||||
items.add(item);
|
||||
}
|
||||
items.add(LIST_ENDLINE);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルに発言処理を行う
|
||||
* @param player プレイヤー
|
||||
* @param channel チャンネル
|
||||
* @param message 発言内容
|
||||
* @return イベントでキャンセルされたかどうか
|
||||
*/
|
||||
private boolean chatToChannelWithEvent(ChannelMember player, Channel channel, String message) {
|
||||
|
||||
// LunaChatPreChatEvent イベントコール
|
||||
LunaChatPreChatEvent preChatEvent = new LunaChatPreChatEvent(
|
||||
channel.getName(), player, message);
|
||||
Bukkit.getPluginManager().callEvent(preChatEvent);
|
||||
if ( preChatEvent.isCancelled() ) {
|
||||
return true;
|
||||
}
|
||||
Channel alt = preChatEvent.getChannel();
|
||||
if ( alt != null ) {
|
||||
channel = alt;
|
||||
}
|
||||
message = preChatEvent.getMessage();
|
||||
|
||||
// チャンネルチャット発言
|
||||
channel.chat(player, message);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットの発言をログファイルへ記録する
|
||||
* @param message
|
||||
* @param player
|
||||
*/
|
||||
private void logNormalChat(String message, String player) {
|
||||
LunaChat.getNormalChatLogger().log(message, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージリソースのメッセージを、カラーコード置き換えしつつ、senderに送信する
|
||||
* @param sender メッセージの送り先
|
||||
* @param pre プレフィックス
|
||||
* @param key リソースキー
|
||||
* @param args リソース内の置き換え対象キーワード
|
||||
*/
|
||||
private void sendResourceMessage(
|
||||
CommandSender sender, String pre, String key, Object... args) {
|
||||
|
||||
String org = Messages.get(key);
|
||||
if ( org == null || org.equals("") ) {
|
||||
return;
|
||||
}
|
||||
String msg = String.format(pre + org, args);
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたEventPriorityが、LunaChatConfigで指定されているEventPriorityと一致するかどうかを調べる
|
||||
* @param priority
|
||||
* @return 一致するかどうか
|
||||
*/
|
||||
private boolean matchesEventPriority(EventPriority priority) {
|
||||
String c = LunaChat.getConfig().getPlayerChatEventListenerPriority().name();
|
||||
return c.equals(priority.name());
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bukkit;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
|
||||
/**
|
||||
* 各チャンネルの期限付きBANや期限付きMuteを、1分間隔で確認しに行くタスク
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ExpireCheckTask extends BukkitRunnable {
|
||||
|
||||
/**
|
||||
* 1分ごとに呼び出されるメソッド
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
for ( Channel channel : LunaChat.getAPI().getChannels() ) {
|
||||
channel.checkExpires();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,242 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc.LunaChatLogger;
|
||||
import com.github.ucchyocean.lc.LunaChatMode;
|
||||
import com.github.ucchyocean.lc.PluginInterface;
|
||||
import com.github.ucchyocean.lc.bridge.DynmapBridge;
|
||||
import com.github.ucchyocean.lc.bridge.McMMOBridge;
|
||||
import com.github.ucchyocean.lc.bridge.MultiverseCoreBridge;
|
||||
import com.github.ucchyocean.lc.bridge.VaultChatBridge;
|
||||
import com.github.ucchyocean.lc.channel.ChannelManager;
|
||||
import com.github.ucchyocean.lc.command.LunaChatCommandBukkit;
|
||||
import com.github.ucchyocean.lc.command.LunaChatJapanizeCommand;
|
||||
import com.github.ucchyocean.lc.command.LunaChatMessageCommand;
|
||||
import com.github.ucchyocean.lc.command.LunaChatReplyCommand;
|
||||
|
||||
/**
|
||||
* LunaChatのBukkit実装
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatBukkit extends JavaPlugin implements PluginInterface {
|
||||
|
||||
private static LunaChatBukkit instance;
|
||||
|
||||
private LunaChatConfig config;
|
||||
private ChannelManager manager;
|
||||
|
||||
private VaultChatBridge vaultchat;
|
||||
private DynmapBridge dynmap;
|
||||
private MultiverseCoreBridge multiverse;
|
||||
|
||||
private ExpireCheckTask expireCheckerTask;
|
||||
private LunaChatLogger normalChatLogger;
|
||||
|
||||
private LunaChatCommandBukkit lunachatCommand;
|
||||
private LunaChatMessageCommand messageCommand;
|
||||
private LunaChatReplyCommand replyCommand;
|
||||
private LunaChatJapanizeCommand lcjapanizeCommand;
|
||||
|
||||
/**
|
||||
* プラグインが有効化されたときに呼び出されるメソッド
|
||||
* @see org.bukkit.plugin.java.JavaPlugin#onEnable()
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
LunaChat.setPlugin(this);
|
||||
LunaChat.setMode(LunaChatMode.BUKKIT);
|
||||
|
||||
// 変数などの初期化
|
||||
config = new LunaChatConfig(getDataFolder(), getFile());
|
||||
manager = new ChannelManager();
|
||||
normalChatLogger = new LunaChatLogger("==normalchat");
|
||||
|
||||
// チャンネルチャット無効なら、デフォルト発言先をクリアする(see issue #59)
|
||||
if ( !config.isEnableChannelChat() ) {
|
||||
manager.removeAllDefaultChannels();
|
||||
}
|
||||
|
||||
// Vault のロード
|
||||
Plugin temp = getServer().getPluginManager().getPlugin("Vault");
|
||||
if ( temp != null ) {
|
||||
vaultchat = VaultChatBridge.load(temp);
|
||||
}
|
||||
|
||||
// Dynmap のロード
|
||||
temp = getServer().getPluginManager().getPlugin("dynmap");
|
||||
if ( temp != null ) {
|
||||
dynmap = DynmapBridge.load(temp);
|
||||
if ( dynmap != null ) {
|
||||
getServer().getPluginManager().registerEvents(dynmap, this);
|
||||
}
|
||||
}
|
||||
|
||||
// MultiverseCore のロード
|
||||
temp = getServer().getPluginManager().getPlugin("Multiverse-Core");
|
||||
if ( temp != null ) {
|
||||
multiverse = MultiverseCoreBridge.load(temp);
|
||||
}
|
||||
|
||||
// mcMMOのロード
|
||||
if ( getServer().getPluginManager().isPluginEnabled("mcMMO") ) {
|
||||
getServer().getPluginManager().registerEvents(new McMMOBridge(), this);
|
||||
}
|
||||
|
||||
// リスナーの登録
|
||||
getServer().getPluginManager().registerEvents(new BukkitEventListener(), this);
|
||||
|
||||
// コマンドの登録
|
||||
lunachatCommand = new LunaChatCommandBukkit();
|
||||
messageCommand = new LunaChatMessageCommand();
|
||||
replyCommand = new LunaChatReplyCommand();
|
||||
lcjapanizeCommand = new LunaChatJapanizeCommand();
|
||||
|
||||
// 期限チェッカータスクの起動
|
||||
expireCheckerTask = new ExpireCheckTask();
|
||||
expireCheckerTask.runTaskTimerAsynchronously(this, 100, 600);
|
||||
}
|
||||
|
||||
/**
|
||||
* プラグインが無効化されたときに呼び出されるメソッド
|
||||
* @see org.bukkit.plugin.java.JavaPlugin#onDisable()
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
// 期限チェッカータスクの停止
|
||||
if ( expireCheckerTask != null ) {
|
||||
expireCheckerTask.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンド実行時に呼び出されるメソッド
|
||||
* @see org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(
|
||||
CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if ( command.getName().equals("lunachat") ) {
|
||||
return lunachatCommand.onCommand(sender, command, label, args);
|
||||
} else if ( command.getName().equals("tell") ) {
|
||||
return messageCommand.onCommand(sender, command, label, args);
|
||||
} else if ( command.getName().equals("reply") ) {
|
||||
return replyCommand.onCommand(sender, command, label, args);
|
||||
} else if ( command.getName().equals("lcjapanize") ) {
|
||||
return lcjapanizeCommand.onCommand(sender, command, label, args);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* TABキー補完が実行されたときに呼び出されるメソッド
|
||||
* @see org.bukkit.plugin.java.JavaPlugin#onTabComplete(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTabComplete(
|
||||
CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
List<String> completeList = null;
|
||||
if ( command.getName().equals("lunachat") ) {
|
||||
completeList = lunachatCommand.onTabComplete(sender, command, label, args);
|
||||
}
|
||||
if ( completeList != null ) {
|
||||
return completeList;
|
||||
}
|
||||
return super.onTabComplete(sender, command, label, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* LunaChatのインスタンスを返す
|
||||
* @return LunaChat
|
||||
*/
|
||||
public static LunaChatBukkit getInstance() {
|
||||
if ( instance == null ) {
|
||||
instance = (LunaChatBukkit)Bukkit.getPluginManager().getPlugin("LunaChat");
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* このプラグインのJarファイル自身を示すFileクラスを返す。
|
||||
* @return Jarファイル
|
||||
*/
|
||||
public File getPluginJarFile() {
|
||||
return getFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* LunaChatAPIを取得する
|
||||
* @return LunaChatAPI
|
||||
*/
|
||||
public LunaChatAPI getLunaChatAPI() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* LunaChatConfigを取得する
|
||||
* @return LunaChatConfig
|
||||
*/
|
||||
public LunaChatConfig getLunaChatConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* VaultChat連携クラスを返す
|
||||
* @return VaultChatBridge
|
||||
*/
|
||||
public VaultChatBridge getVaultChat() {
|
||||
return vaultchat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynmap連携クラスを返す
|
||||
* @return DynmapBridge
|
||||
*/
|
||||
public DynmapBridge getDynmap() {
|
||||
return dynmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* MultiverseCore連携クラスを返す
|
||||
* @return MultiverseCoreBridge
|
||||
*/
|
||||
public MultiverseCoreBridge getMultiverseCore() {
|
||||
return multiverse;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャット用のロガーを返す
|
||||
* @return normalChatLogger
|
||||
*/
|
||||
public LunaChatLogger getNormalChatLogger() {
|
||||
return normalChatLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャット用のロガーを設定する
|
||||
* @param normalChatLogger normalChatLogger
|
||||
*/
|
||||
protected void setNormalChatLogger(LunaChatLogger normalChatLogger) {
|
||||
this.normalChatLogger = normalChatLogger;
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
/*
|
||||
* @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.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
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.event.EventHandler;
|
||||
|
||||
/**
|
||||
* BungeeCordのイベントを監視するリスナークラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class BungeeEventListener 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 LunaChatBungee parent;
|
||||
private LunaChatConfig config;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param parent LunaChatBungeeのインスタンス
|
||||
*/
|
||||
protected BungeeEventListener(LunaChatBungee parent) {
|
||||
this.parent = parent;
|
||||
config = parent.getConfig();
|
||||
dateFormat = new SimpleDateFormat(DATE_FORMAT_PATTERN);
|
||||
timeFormat = new SimpleDateFormat(TIME_FORMAT_PATTERN);
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーがチャット発言した時に呼び出されるメソッド
|
||||
* @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(),
|
||||
LunaChat.getAPI().getAllDictionary());
|
||||
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 : parent.getProxy().getServers().keySet() ) {
|
||||
|
||||
if ( server.equals(senderServer) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ServerInfo info = parent.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));
|
||||
parent.getProxy().getScheduler().schedule(parent, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for ( ProxiedPlayer p : sender.getServer().getInfo().getPlayers() ) {
|
||||
sendMessage(p, post);
|
||||
}
|
||||
}
|
||||
}, 150, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
// コンソールに表示設定なら、コンソールに表示する
|
||||
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 メッセージ
|
||||
*/
|
||||
private void sendMessage(CommandSender reciever, String message) {
|
||||
if ( message == null ) return;
|
||||
reciever.sendMessage(TextComponent.fromLegacyText(message));
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bungee;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* LunaChatのdictionaryコマンド実装クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class DictionaryCommand extends Command {
|
||||
|
||||
private LunaChatBungee parent;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param parent
|
||||
* @param name コマンド
|
||||
* @param permission パーミッション
|
||||
* @param aliases エイリアス
|
||||
*/
|
||||
public DictionaryCommand(LunaChatBungee parent, String name, String permission, String... aliases) {
|
||||
super(name, permission, aliases);
|
||||
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") ) {
|
||||
|
||||
LunaChat.getAPI().setDictionary(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") ) {
|
||||
|
||||
LunaChat.getAPI().removeDictionary(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 = LunaChat.getAPI().getAllDictionary();
|
||||
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 メッセージ
|
||||
*/
|
||||
private void sendMessage(CommandSender reciever, String message) {
|
||||
if ( message == null ) return;
|
||||
reciever.sendMessage(TextComponent.fromLegacyText(message));
|
||||
}
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bungee;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc.LunaChatLogger;
|
||||
import com.github.ucchyocean.lc.LunaChatMode;
|
||||
import com.github.ucchyocean.lc.PluginInterface;
|
||||
import com.github.ucchyocean.lc.channel.ChannelManager;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* LunaChatのBungeeCord実装
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatBungee extends Plugin implements PluginInterface {
|
||||
|
||||
private static LunaChatBungee instance;
|
||||
|
||||
private HashMap<String, String> history;
|
||||
private LunaChatConfig config;
|
||||
private ChannelManager manager;
|
||||
private LunaChatLogger normalChatLogger;
|
||||
|
||||
/**
|
||||
* プラグインが有効化されたときに呼び出されるメソッド
|
||||
* @see net.md_5.bungee.api.plugin.Plugin#onEnable()
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
LunaChat.setPlugin(this);
|
||||
LunaChat.setMode(LunaChatMode.BUNGEE);
|
||||
|
||||
// 初期化
|
||||
config = new LunaChatConfig(getDataFolder(), getFile());
|
||||
history = new HashMap<String, String>();
|
||||
|
||||
manager = new ChannelManager();
|
||||
normalChatLogger = new LunaChatLogger("==normalchat");
|
||||
|
||||
// チャンネルチャット無効なら、デフォルト発言先をクリアする
|
||||
if ( !config.isEnableChannelChat() ) {
|
||||
manager.removeAllDefaultChannels();
|
||||
}
|
||||
|
||||
// コマンド登録
|
||||
getProxy().getPluginManager().registerCommand(this,
|
||||
new LunaChatCommand("lunachat", "", "lc", "ch"));
|
||||
getProxy().getPluginManager().registerCommand(this,
|
||||
new TellCommand(this, "tell", "", "msg", "message", "m", "w", "t"));
|
||||
getProxy().getPluginManager().registerCommand(this,
|
||||
new ReplyCommand(this, "reply", "", "r"));
|
||||
getProxy().getPluginManager().registerCommand(this,
|
||||
new DictionaryCommand(this, "dictionary", "", "dic"));
|
||||
|
||||
// リスナー登録
|
||||
getProxy().getPluginManager().registerListener(this, new BungeeEventListener(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* LunaChatのインスタンスを返す
|
||||
* @return LunaChat
|
||||
*/
|
||||
public static LunaChatBungee getInstance() {
|
||||
if ( instance == null ) {
|
||||
instance = (LunaChatBungee)ProxyServer.getInstance().getPluginManager().getPlugin("LunaChat");
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* コンフィグを返す
|
||||
* @return コンフィグ
|
||||
*/
|
||||
public LunaChatConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* プライベートメッセージの受信履歴を記録する
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* このプラグインのJarファイル自身を示すFileクラスを返す。
|
||||
* @return Jarファイル
|
||||
* @see com.github.ucchyocean.lc.PluginInterface#getPluginJarFile()
|
||||
*/
|
||||
@Override
|
||||
public File getPluginJarFile() {
|
||||
return getFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* LunaChatConfigを取得する
|
||||
* @return LunaChatConfig
|
||||
* @see com.github.ucchyocean.lc.PluginInterface#getLunaChatConfig()
|
||||
*/
|
||||
@Override
|
||||
public LunaChatConfig getLunaChatConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* LunaChatAPIを取得する
|
||||
* @return LunaChatAPI
|
||||
* @see com.github.ucchyocean.lc.PluginInterface#getLunaChatAPI()
|
||||
*/
|
||||
@Override
|
||||
public LunaChatAPI getLunaChatAPI() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャット用のロガーを返す
|
||||
* @return normalChatLogger
|
||||
*/
|
||||
@Override
|
||||
public LunaChatLogger getNormalChatLogger() {
|
||||
return normalChatLogger;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.bungee;
|
||||
|
||||
import com.github.ucchyocean.lc.command.LunaChatCommandBungee;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
|
||||
/**
|
||||
* LunaChatのlunachatコマンド実装クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatCommand extends Command implements TabExecutor {
|
||||
|
||||
private LunaChatCommandBungee com = new LunaChatCommandBungee();
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param name コマンド
|
||||
* @param permission パーミッション
|
||||
* @param aliases エイリアス
|
||||
*/
|
||||
public LunaChatCommand(String name, String permission, String... aliases) {
|
||||
super(name, permission, aliases);
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドを実行したときに呼び出されるメソッド
|
||||
* @param sender 実行者
|
||||
* @param args 実行されたコマンドの引数
|
||||
* @see net.md_5.bungee.api.plugin.Command#execute(net.md_5.bungee.api.CommandSender, java.lang.String[])
|
||||
*/
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
com.execute(sender, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* TABキー補完が実行されたときに呼び出されるメソッド
|
||||
* @param sender 実行者
|
||||
* @param args 実行されたコマンドの引数
|
||||
* @return 補完候補
|
||||
* @see net.md_5.bungee.api.plugin.TabExecutor#onTabComplete(net.md_5.bungee.api.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
return com.onTabComplete(sender, args);
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* LunaChatのreplyコマンド実装クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ReplyCommand extends TellCommand {
|
||||
|
||||
private LunaChatBungee parent;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param BungeeJapanizeMessenger
|
||||
* @param name コマンド
|
||||
* @param permission パーミッション
|
||||
* @param aliases エイリアス
|
||||
*/
|
||||
public ReplyCommand(LunaChatBungee parent, String name, String permission, String... aliases) {
|
||||
super(parent, name, permission, aliases);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
* @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.LunaChat;
|
||||
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;
|
||||
|
||||
/**
|
||||
* LunaChatのtellコマンド実装クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class TellCommand extends Command {
|
||||
|
||||
private LunaChatBungee parent;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param parent
|
||||
* @param name コマンド
|
||||
* @param permission パーミッション
|
||||
* @param aliases エイリアス
|
||||
*/
|
||||
public TellCommand(LunaChatBungee parent, String name, String permission, String... aliases) {
|
||||
super(name, permission, aliases);
|
||||
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(),
|
||||
LunaChat.getAPI().getAllDictionary());
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -1,607 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.channel;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
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.Messages;
|
||||
import com.github.ucchyocean.lc.NGWordAction;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.UtilityBukkit;
|
||||
import com.github.ucchyocean.lc.bridge.DynmapBridge;
|
||||
import com.github.ucchyocean.lc.bukkit.LunaChatBukkit;
|
||||
import com.github.ucchyocean.lc.event.LunaChatChannelChatEvent;
|
||||
import com.github.ucchyocean.lc.event.LunaChatChannelMessageEvent;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc.member.ChannelMemberBukkit;
|
||||
|
||||
/**
|
||||
* チャンネルの実装クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class BukkitChannel extends Channel {
|
||||
|
||||
private static final String PERMISSION_SPEAK_PREFIX = "lunachat.speak";
|
||||
|
||||
private static final String MSG_BAN_NGWORD = Messages.get("banNGWordMessage");
|
||||
private static final String MSG_KICK_NGWORD = Messages.get("kickNGWordMessage");
|
||||
private static final String MSG_MUTE_NGWORD = Messages.get("muteNGWordMessage");
|
||||
|
||||
private static final String PREERR = Messages.get("errorPrefix");
|
||||
|
||||
private static final String MSG_NO_RECIPIENT = Messages.get("noRecipientMessage");
|
||||
|
||||
private static final String ERRMSG_MUTED = Messages.get("errmsgMuted");
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param name チャンネル名
|
||||
*/
|
||||
protected BukkitChannel(String name) {
|
||||
super(name);
|
||||
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
timeFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
* このチャットに発言をする
|
||||
* @param player 発言をするプレイヤー
|
||||
* @param message 発言をするメッセージ
|
||||
*/
|
||||
@Override
|
||||
public void chat(ChannelMember player, String message) {
|
||||
|
||||
// 発言権限を確認する
|
||||
String node = PERMISSION_SPEAK_PREFIX + "." + getName();
|
||||
if ( player.isPermissionSet(node) && !player.hasPermission(node) ) {
|
||||
sendResourceMessage(player, PREERR, "errmsgPermission",
|
||||
PERMISSION_SPEAK_PREFIX + "." + getName());
|
||||
return;
|
||||
}
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
// Muteされているかどうかを確認する
|
||||
if ( getMuted().contains(player) ) {
|
||||
player.sendMessage( PREERR + ERRMSG_MUTED );
|
||||
return;
|
||||
}
|
||||
|
||||
String preReplaceMessage = new String(message);
|
||||
String maskedMessage = new String(message);
|
||||
|
||||
// 一時的にJapanizeスキップ設定かどうかを確認する
|
||||
boolean skipJapanize = false;
|
||||
String marker = config.getNoneJapanizeMarker();
|
||||
if ( !marker.equals("") && maskedMessage.startsWith(marker) ) {
|
||||
skipJapanize = true;
|
||||
maskedMessage = maskedMessage.substring(marker.length());
|
||||
}
|
||||
|
||||
// NGワード発言をしたかどうかのチェックとマスク
|
||||
boolean isNG = false;
|
||||
for ( Pattern pattern : config.getNgwordCompiled() ) {
|
||||
Matcher matcher = pattern.matcher(maskedMessage);
|
||||
if ( matcher.find() ) {
|
||||
maskedMessage = matcher.replaceAll(
|
||||
Utility.getAstariskString(matcher.group(0).length()));
|
||||
isNG = true;
|
||||
}
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
String msgFormat = replaceKeywords(getFormat(), player);
|
||||
|
||||
// カラーコード置き換え
|
||||
// チャンネルで許可されていて、発言者がパーミッションを持っている場合に置き換える
|
||||
if ( isAllowCC() && player.hasPermission("lunachat.allowcc") ) {
|
||||
maskedMessage = Utility.replaceColorCode(maskedMessage);
|
||||
}
|
||||
|
||||
// イベントコール
|
||||
LunaChatChannelChatEvent event =
|
||||
new LunaChatChannelChatEvent(getName(), player,
|
||||
preReplaceMessage, maskedMessage, msgFormat);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if ( event.isCancelled() ) {
|
||||
return;
|
||||
}
|
||||
msgFormat = event.getMessageFormat();
|
||||
maskedMessage = event.getNgMaskedMessage();
|
||||
|
||||
// 2byteコードを含むか、半角カタカナのみなら、Japanize変換は行わない
|
||||
String kanaTemp = Utility.stripColorCode(maskedMessage);
|
||||
if ( !skipJapanize &&
|
||||
( kanaTemp.getBytes().length > kanaTemp.length() ||
|
||||
kanaTemp.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
skipJapanize = true;
|
||||
}
|
||||
|
||||
// Japanize変換タスクを作成する
|
||||
boolean isIncludeSyncChat = true;
|
||||
DelayedJapanizeConvertTask delayedTask = null;
|
||||
JapanizeType japanizeType = (getJapanizeType() == null)
|
||||
? config.getJapanizeType() : getJapanizeType();
|
||||
|
||||
if ( !skipJapanize &&
|
||||
api.isPlayerJapanize(player.getName()) &&
|
||||
japanizeType != JapanizeType.NONE ) {
|
||||
|
||||
int lineType = config.getJapanizeDisplayLine();
|
||||
String jpFormat;
|
||||
String messageFormat = null;
|
||||
if ( lineType == 1 ) {
|
||||
jpFormat = Utility.replaceColorCode(config.getJapanizeLine1Format());
|
||||
messageFormat = msgFormat;
|
||||
isIncludeSyncChat = false;
|
||||
} else {
|
||||
jpFormat = Utility.replaceColorCode(config.getJapanizeLine2Format());
|
||||
}
|
||||
|
||||
// タスクを作成しておく
|
||||
delayedTask = new DelayedJapanizeChannelChatTask(maskedMessage,
|
||||
japanizeType, this, player, jpFormat, messageFormat);
|
||||
}
|
||||
|
||||
if ( isIncludeSyncChat ) {
|
||||
// メッセージの送信
|
||||
sendMessage(player, maskedMessage, msgFormat, true, player.getDisplayName());
|
||||
}
|
||||
|
||||
// 非同期実行タスクがある場合、追加で実行する
|
||||
if ( delayedTask != null ) {
|
||||
delayedTask.runTaskAsynchronously(LunaChatBukkit.getInstance());
|
||||
}
|
||||
|
||||
// NGワード発言者に、NGワードアクションを実行する
|
||||
if ( isNG ) {
|
||||
if ( config.getNgwordAction() == NGWordAction.BAN ) {
|
||||
// BANする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
getBanned().add(player);
|
||||
removeMember(player);
|
||||
if ( !MSG_BAN_NGWORD.equals("") ) {
|
||||
String m = replaceKeywordsForSystemMessages(
|
||||
MSG_BAN_NGWORD, player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.KICK ) {
|
||||
// キックする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
removeMember(player);
|
||||
if ( !MSG_KICK_NGWORD.equals("") ) {
|
||||
String m = replaceKeywordsForSystemMessages(
|
||||
MSG_KICK_NGWORD, player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.MUTE ) {
|
||||
// Muteする
|
||||
|
||||
getMuted().add(player);
|
||||
save();
|
||||
if ( !MSG_MUTE_NGWORD.equals("") ) {
|
||||
String m = replaceKeywordsForSystemMessages(
|
||||
MSG_MUTE_NGWORD, player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ほかの連携先などから、このチャットに発言する
|
||||
* @param player プレイヤー名
|
||||
* @param source 連携元を判別する文字列
|
||||
* @param message メッセージ
|
||||
*/
|
||||
@Override
|
||||
public void chatFromOtherSource(String player, String source, String message) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
// 表示名
|
||||
String name = player + "@" + source;
|
||||
|
||||
// NGワード発言のマスク
|
||||
String maskedMessage = new String(message);
|
||||
for ( Pattern pattern : config.getNgwordCompiled() ) {
|
||||
Matcher matcher = pattern.matcher(maskedMessage);
|
||||
if ( matcher.find() ) {
|
||||
maskedMessage = matcher.replaceAll(
|
||||
Utility.getAstariskString(matcher.group(0).length()));
|
||||
}
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
String msgFormat = replaceKeywordsForSystemMessages(getFormat(), name);
|
||||
msgFormat = msgFormat.replace("%prefix", "");
|
||||
msgFormat = msgFormat.replace("%suffix", "");
|
||||
|
||||
// カラーコード置き換え チャンネルで許可されている場合に置き換える。
|
||||
if ( isAllowCC() ) {
|
||||
maskedMessage = Utility.replaceColorCode(maskedMessage);
|
||||
}
|
||||
|
||||
// メッセージの送信
|
||||
boolean sendDynmap = source == null || !source.equals("web");
|
||||
sendMessage(null, maskedMessage, msgFormat, sendDynmap, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーに関連する、システムメッセージをチャンネルに流す
|
||||
* @param key リソースキー
|
||||
* @param player プレイヤー
|
||||
*/
|
||||
@Override
|
||||
protected void sendSystemMessage(String key, ChannelMember player) {
|
||||
|
||||
// プライベートチャットならシステムメッセージを流さない
|
||||
if ( isPersonalChat() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = Messages.get(key);
|
||||
if ( msg == null || msg.equals("") ) {
|
||||
return;
|
||||
}
|
||||
msg = replaceKeywordsForSystemMessages(msg, player.getName());
|
||||
sendMessage(null, msg, null, false, "system");
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを表示します。指定したプレイヤーの発言として処理されます。
|
||||
* @param player プレイヤー(ワールドチャット、範囲チャットの場合は必須です)
|
||||
* @param message メッセージ
|
||||
* @param format フォーマット
|
||||
* @param sendDynmap dynmapへ送信するかどうか
|
||||
* @param name 発言者名
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(ChannelMember player, String message,
|
||||
String format, boolean sendDynmap, String name) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
String originalMessage = new String(message);
|
||||
|
||||
// 受信者を設定する
|
||||
ArrayList<ChannelMember> recipients = new ArrayList<ChannelMember>();
|
||||
boolean sendNoRecipientMessage = false;
|
||||
|
||||
if ( isBroadcastChannel() ) {
|
||||
// ブロードキャストチャンネル
|
||||
|
||||
if ( isWorldRange() && player.isOnline() && player.getWorldName() != null ) {
|
||||
|
||||
World w = Bukkit.getWorld(player.getWorldName());
|
||||
|
||||
if ( getChatRange() > 0 ) {
|
||||
// 範囲チャット
|
||||
|
||||
if ( player instanceof ChannelMemberBukkit ) {
|
||||
Location origin = ((ChannelMemberBukkit)player).getLocation();
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
ChannelMember cp = ChannelMember.getChannelMember(p);
|
||||
if ( p.getWorld().equals(w) &&
|
||||
origin.distance(p.getLocation()) <= getChatRange() &&
|
||||
!getHided().contains(cp) ) {
|
||||
recipients.add(ChannelMember.getChannelMember(p));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO 何かするか?検討する
|
||||
}
|
||||
|
||||
} else {
|
||||
// ワールドチャット
|
||||
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
ChannelMember cp = ChannelMember.getChannelMember(p);
|
||||
if ( p.getWorld().equals(w) && !getHided().contains(cp) ) {
|
||||
recipients.add(ChannelMember.getChannelMember(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 受信者が自分以外いない場合は、メッセージを表示する
|
||||
if ( !MSG_NO_RECIPIENT.equals("") && (
|
||||
recipients.size() == 0 ||
|
||||
(recipients.size() == 1 &&
|
||||
recipients.get(0).getName().equals(player.getName()) ) ) ) {
|
||||
sendNoRecipientMessage = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
// 通常ブロードキャスト(全員へ送信)
|
||||
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
ChannelMember cp = ChannelMember.getChannelMember(p);
|
||||
if ( !getHided().contains(cp) ) {
|
||||
recipients.add(cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// 通常チャンネル
|
||||
|
||||
for ( ChannelMember mem : getMembers() ) {
|
||||
if ( mem != null && mem.isOnline() && !getHided().contains(mem) ) {
|
||||
recipients.add(mem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// opListenAllChannel 設定がある場合は、
|
||||
// パーミッション lunachat-admin.listen-all-channels を持つプレイヤーを
|
||||
// 受信者に加える。
|
||||
if ( config.isOpListenAllChannel() ) {
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
ChannelMember cp = ChannelMember.getChannelMember(p);
|
||||
if ( cp.hasPermission("lunachat-admin.listen-all-channels")
|
||||
&& !recipients.contains(cp) ) {
|
||||
recipients.add(cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// hideされている場合は、受信対象者から抜く。
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
for ( ChannelMember cp : api.getHidelist(player) ) {
|
||||
if ( recipients.contains(cp) ) {
|
||||
recipients.remove(cp);
|
||||
}
|
||||
}
|
||||
|
||||
// フォーマットがある場合は置き換える
|
||||
if ( format != null ) {
|
||||
message = format.replace("%msg", message);
|
||||
}
|
||||
|
||||
// イベントコール
|
||||
LunaChatChannelMessageEvent event =
|
||||
new LunaChatChannelMessageEvent(
|
||||
getName(), player, message, recipients, name, originalMessage);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
message = event.getMessage();
|
||||
recipients = event.getRecipients();
|
||||
|
||||
// 通常ブロードキャストなら、設定に応じてdynmapへ送信する
|
||||
DynmapBridge dynmap = LunaChatBukkit.getInstance().getDynmap();
|
||||
if ( config.isSendBroadcastChannelChatToDynmap() &&
|
||||
sendDynmap &&
|
||||
dynmap != null &&
|
||||
isBroadcastChannel() &&
|
||||
!isWorldRange() ) {
|
||||
|
||||
String msg = config.isSendFormattedMessageToDynmap() ? message : originalMessage;
|
||||
if ( player != null && player instanceof ChannelMemberBukkit
|
||||
&& ((ChannelMemberBukkit)player).getPlayer() != null ) {
|
||||
dynmap.chat(((ChannelMemberBukkit)player).getPlayer(), msg);
|
||||
} else {
|
||||
dynmap.broadcast(msg);
|
||||
}
|
||||
}
|
||||
|
||||
// 送信する
|
||||
for ( ChannelMember p : recipients ) {
|
||||
p.sendMessage(message);
|
||||
}
|
||||
|
||||
// 設定に応じて、コンソールに出力する
|
||||
if ( config.isDisplayChatOnConsole() ) {
|
||||
Bukkit.getLogger().info(ChatColor.stripColor(message));
|
||||
}
|
||||
|
||||
// 受信者が自分以外いない場合は、メッセージを表示する
|
||||
if ( sendNoRecipientMessage ) {
|
||||
String msg = replaceKeywordsForSystemMessages(MSG_NO_RECIPIENT, "");
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
|
||||
// ロギング
|
||||
log(originalMessage, name, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルのオンライン人数を返す
|
||||
* @return オンライン人数
|
||||
* @see com.github.ucchyocean.lc.channel.Channel#getOnlineNum()
|
||||
*/
|
||||
@Override
|
||||
public int getOnlineNum() {
|
||||
|
||||
// ブロードキャストチャンネルならサーバー接続人数を返す
|
||||
if ( isBroadcastChannel() ) {
|
||||
return UtilityBukkit.getOnlinePlayersCount();
|
||||
}
|
||||
|
||||
return super.getOnlineNum();
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルの総参加人数を返す
|
||||
* @return 総参加人数
|
||||
* @see com.github.ucchyocean.lc.channel.Channel#getTotalNum()
|
||||
*/
|
||||
@Override
|
||||
public int getTotalNum() {
|
||||
|
||||
// ブロードキャストチャンネルならサーバー接続人数を返す
|
||||
if ( isBroadcastChannel() ) {
|
||||
return UtilityBukkit.getOnlinePlayersCount();
|
||||
}
|
||||
|
||||
return super.getTotalNum();
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルのメンバーを返す
|
||||
* @return チャンネルのメンバー
|
||||
* @see com.github.ucchyocean.lc.channel.Channel#getMembers()
|
||||
*/
|
||||
@Override
|
||||
public List<ChannelMember> getMembers() {
|
||||
|
||||
// ブロードキャストチャンネルなら、
|
||||
// 現在サーバーに接続している全プレイヤーをメンバーとして返す
|
||||
if ( isBroadcastChannel() ) {
|
||||
List<ChannelMember> mem = new ArrayList<ChannelMember>();
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
mem.add(ChannelMember.getChannelMember(p));
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
||||
return super.getMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param player プレイヤー
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
@Override
|
||||
protected String replaceKeywords(String format, ChannelMember player) {
|
||||
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
String msg = format;
|
||||
|
||||
// テンプレートのキーワードを、まず最初に置き換える
|
||||
for ( int i=0; i<=9; i++ ) {
|
||||
String key = "%" + i;
|
||||
if ( msg.contains(key) ) {
|
||||
if ( api.getTemplate("" + i) != null ) {
|
||||
msg = msg.replace(key, api.getTemplate("" + i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg = msg.replace("%ch", getName());
|
||||
//msg = msg.replace("%msg", message);
|
||||
msg = msg.replace("%color", getColorCode());
|
||||
msg = msg.replace("%to", getPrivateMessageTo());
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg = msg.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg = msg.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( player != null ) {
|
||||
msg = msg.replace("%username", player.getDisplayName());
|
||||
msg = msg.replace("%player", player.getName());
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
msg = msg.replace("%prefix", player.getPrefix());
|
||||
msg = msg.replace("%suffix", player.getSuffix());
|
||||
}
|
||||
|
||||
if ( msg.contains("%world") ) {
|
||||
|
||||
String worldname = null;
|
||||
if ( LunaChatBukkit.getInstance().getMultiverseCore() != null ) {
|
||||
worldname = LunaChatBukkit.getInstance().getMultiverseCore().getWorldAlias(player.getWorldName());
|
||||
}
|
||||
if ( worldname == null || worldname.equals("") ) {
|
||||
worldname = player.getWorldName();
|
||||
}
|
||||
msg = msg.replace("%world", worldname);
|
||||
}
|
||||
|
||||
msg = msg.replace("%server", "");
|
||||
|
||||
} else {
|
||||
msg = msg.replace("%username", "");
|
||||
msg = msg.replace("%player", "");
|
||||
msg = msg.replace("%prefix", "");
|
||||
msg = msg.replace("%suffix", "");
|
||||
msg = msg.replace("%world", "");
|
||||
msg = msg.replace("%server", "");
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param playerName プレイヤー名
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
private String replaceKeywordsForSystemMessages(String format, String playerName) {
|
||||
|
||||
String msg = format;
|
||||
msg = msg.replace("%ch", getName());
|
||||
msg = msg.replace("%color", getColorCode());
|
||||
msg = msg.replace("%username", playerName);
|
||||
msg = msg.replace("%player", playerName);
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* ログを記録する
|
||||
* @param name 発言者
|
||||
* @param message 記録するメッセージ
|
||||
* @param player プレイヤー
|
||||
*/
|
||||
private void log(String message, String name, ChannelMember player) {
|
||||
|
||||
// LunaChatのチャットログへ記録
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
if ( config.isLoggingChat() && logger != null ) {
|
||||
logger.log(message, name);
|
||||
}
|
||||
|
||||
// TODO ログ記録プラグイン連携を検討する
|
||||
// // Hawkeye Reloaded のチャットログへ記録
|
||||
// if ( config.isLoggingChatToHawkEye() && LunaChat.getInstance().getHawkEye() != null
|
||||
// && player != null && player.getLocation() != null ) {
|
||||
// LunaChat.getInstance().getHawkEye().writeLog(name, player.getLocation(),
|
||||
// "channel(" + getName() + ")-" + Utility.stripColor(message));
|
||||
// }
|
||||
//
|
||||
// // Prism のチャットログへ記録
|
||||
// if ( config.isLoggingChatToPrism() && LunaChat.getInstance().getPrism() != null
|
||||
// && player != null && player.getPlayer() != null ) {
|
||||
// LunaChat.getInstance().getPrism().writeLog(player.getPlayer(),
|
||||
// "channel(" + getName() + ")-" + Utility.stripColor(message));
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,530 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.channel;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
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.LunaChatLogger;
|
||||
import com.github.ucchyocean.lc.Messages;
|
||||
import com.github.ucchyocean.lc.NGWordAction;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.bungee.LunaChatBungee;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc.member.ChannelMemberProxiedPlayer;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
/**
|
||||
* チャンネルのBungee実装クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class BungeeChannel extends Channel {
|
||||
|
||||
private static final String PERMISSION_SPEAK_PREFIX = "lunachat.speak";
|
||||
|
||||
private static final String MSG_BAN_NGWORD = Messages.get("banNGWordMessage");
|
||||
private static final String MSG_KICK_NGWORD = Messages.get("kickNGWordMessage");
|
||||
private static final String MSG_MUTE_NGWORD = Messages.get("muteNGWordMessage");
|
||||
|
||||
private static final String PREERR = Messages.get("errorPrefix");
|
||||
|
||||
private static final String ERRMSG_MUTED = Messages.get("errmsgMuted");
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
|
||||
/** ロガー */
|
||||
private LunaChatLogger logger;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param name チャンネル名
|
||||
*/
|
||||
protected BungeeChannel(String name) {
|
||||
|
||||
super(name);
|
||||
|
||||
logger = new LunaChatLogger(name.replace(">", "-"));
|
||||
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
timeFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
* このチャットに発言をする
|
||||
* @param player 発言をするプレイヤー
|
||||
* @param message 発言をするメッセージ
|
||||
*/
|
||||
@Override
|
||||
public void chat(ChannelMember player, String message) {
|
||||
|
||||
// 発言権限を確認する
|
||||
String node = PERMISSION_SPEAK_PREFIX + "." + getName();
|
||||
if ( player.isPermissionSet(node) && !player.hasPermission(node) ) {
|
||||
sendResourceMessage(player, PREERR, "errmsgPermission",
|
||||
PERMISSION_SPEAK_PREFIX + "." + getName());
|
||||
return;
|
||||
}
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
// Muteされているかどうかを確認する
|
||||
if ( getMuted().contains(player) ) {
|
||||
player.sendMessage( PREERR + ERRMSG_MUTED );
|
||||
return;
|
||||
}
|
||||
|
||||
// String preReplaceMessage = new String(message);
|
||||
String maskedMessage = new String(message);
|
||||
|
||||
// 一時的にJapanizeスキップ設定かどうかを確認する
|
||||
boolean skipJapanize = false;
|
||||
String marker = config.getNoneJapanizeMarker();
|
||||
if ( !marker.equals("") && maskedMessage.startsWith(marker) ) {
|
||||
skipJapanize = true;
|
||||
maskedMessage = maskedMessage.substring(marker.length());
|
||||
}
|
||||
|
||||
// NGワード発言をしたかどうかのチェックとマスク
|
||||
boolean isNG = false;
|
||||
for ( Pattern pattern : config.getNgwordCompiled() ) {
|
||||
Matcher matcher = pattern.matcher(maskedMessage);
|
||||
if ( matcher.find() ) {
|
||||
maskedMessage = matcher.replaceAll(
|
||||
Utility.getAstariskString(matcher.group(0).length()));
|
||||
isNG = true;
|
||||
}
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
String msgFormat = replaceKeywords(getFormat(), player);
|
||||
|
||||
// カラーコード置き換え
|
||||
// チャンネルで許可されていて、発言者がパーミッションを持っている場合に置き換える
|
||||
if ( isAllowCC() && player.hasPermission("lunachat.allowcc") ) {
|
||||
maskedMessage = Utility.replaceColorCode(maskedMessage);
|
||||
}
|
||||
|
||||
// イベントコール
|
||||
// LunaChatChannelChatEvent event =
|
||||
// new LunaChatChannelChatEvent(getName(), player,
|
||||
// preReplaceMessage, maskedMessage, msgFormat);
|
||||
// Bukkit.getPluginManager().callEvent(event);
|
||||
// if ( event.isCancelled() ) {
|
||||
// return;
|
||||
// }
|
||||
// msgFormat = event.getMessageFormat();
|
||||
// maskedMessage = event.getNgMaskedMessage();
|
||||
|
||||
// 2byteコードを含むか、半角カタカナのみなら、Japanize変換は行わない
|
||||
String kanaTemp = Utility.stripColorCode(maskedMessage);
|
||||
if ( !skipJapanize &&
|
||||
( kanaTemp.getBytes().length > kanaTemp.length() ||
|
||||
kanaTemp.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
skipJapanize = true;
|
||||
}
|
||||
|
||||
// Japanize変換タスクを作成する
|
||||
boolean isIncludeSyncChat = true;
|
||||
JapanizeChannelChatTask delayedTask = null;
|
||||
JapanizeType japanizeType = (getJapanizeType() == null)
|
||||
? config.getJapanizeType() : getJapanizeType();
|
||||
|
||||
if ( !skipJapanize &&
|
||||
api.isPlayerJapanize(player.getName()) &&
|
||||
japanizeType != JapanizeType.NONE ) {
|
||||
|
||||
int lineType = config.getJapanizeDisplayLine();
|
||||
String jpFormat;
|
||||
String messageFormat = null;
|
||||
if ( lineType == 1 ) {
|
||||
jpFormat = Utility.replaceColorCode(config.getJapanizeLine1Format());
|
||||
messageFormat = msgFormat;
|
||||
isIncludeSyncChat = false;
|
||||
} else {
|
||||
jpFormat = Utility.replaceColorCode(config.getJapanizeLine2Format());
|
||||
}
|
||||
|
||||
// タスクを作成しておく
|
||||
delayedTask = new JapanizeChannelChatTask(maskedMessage,
|
||||
japanizeType, this, player, jpFormat, messageFormat);
|
||||
}
|
||||
|
||||
if ( isIncludeSyncChat ) {
|
||||
// メッセージの送信
|
||||
sendMessage(player, maskedMessage, msgFormat, true, player.getDisplayName());
|
||||
}
|
||||
|
||||
// 非同期実行タスクがある場合、追加で実行する
|
||||
if ( delayedTask != null ) {
|
||||
ProxyServer.getInstance().getScheduler().runAsync(
|
||||
LunaChatBungee.getInstance(), delayedTask);
|
||||
}
|
||||
|
||||
// NGワード発言者に、NGワードアクションを実行する
|
||||
if ( isNG ) {
|
||||
if ( config.getNgwordAction() == NGWordAction.BAN ) {
|
||||
// BANする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
getBanned().add(player);
|
||||
removeMember(player);
|
||||
if ( !MSG_BAN_NGWORD.equals("") ) {
|
||||
String m = replaceKeywordsForSystemMessages(
|
||||
MSG_BAN_NGWORD, player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.KICK ) {
|
||||
// キックする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
removeMember(player);
|
||||
if ( !MSG_KICK_NGWORD.equals("") ) {
|
||||
String m = replaceKeywordsForSystemMessages(
|
||||
MSG_KICK_NGWORD, player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.MUTE ) {
|
||||
// Muteする
|
||||
|
||||
getMuted().add(player);
|
||||
save();
|
||||
if ( !MSG_MUTE_NGWORD.equals("") ) {
|
||||
String m = replaceKeywordsForSystemMessages(
|
||||
MSG_MUTE_NGWORD, player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ほかの連携先などから、このチャットに発言する
|
||||
* @param player プレイヤー名
|
||||
* @param source 連携元を判別する文字列
|
||||
* @param message メッセージ
|
||||
*/
|
||||
@Override
|
||||
public void chatFromOtherSource(String player, String source, String message) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
// 表示名
|
||||
String name = player + "@" + source;
|
||||
|
||||
// NGワード発言のマスク
|
||||
String maskedMessage = new String(message);
|
||||
for ( Pattern pattern : config.getNgwordCompiled() ) {
|
||||
Matcher matcher = pattern.matcher(maskedMessage);
|
||||
if ( matcher.find() ) {
|
||||
maskedMessage = matcher.replaceAll(
|
||||
Utility.getAstariskString(matcher.group(0).length()));
|
||||
}
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
String msgFormat = replaceKeywordsForSystemMessages(getFormat(), name);
|
||||
msgFormat = msgFormat.replace("%prefix", "");
|
||||
msgFormat = msgFormat.replace("%suffix", "");
|
||||
|
||||
// カラーコード置き換え チャンネルで許可されている場合に置き換える。
|
||||
if ( isAllowCC() ) {
|
||||
maskedMessage = Utility.replaceColorCode(maskedMessage);
|
||||
}
|
||||
|
||||
// メッセージの送信
|
||||
boolean sendDynmap = source == null || !source.equals("web");
|
||||
sendMessage(null, maskedMessage, msgFormat, sendDynmap, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーに関連する、システムメッセージをチャンネルに流す
|
||||
* @param key リソースキー
|
||||
* @param player プレイヤー
|
||||
*/
|
||||
@Override
|
||||
protected void sendSystemMessage(String key, ChannelMember player) {
|
||||
|
||||
// プライベートチャットならシステムメッセージを流さない
|
||||
if ( isPersonalChat() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = Messages.get(key);
|
||||
if ( msg == null || msg.equals("") ) {
|
||||
return;
|
||||
}
|
||||
msg = replaceKeywordsForSystemMessages(msg, player.getName());
|
||||
sendMessage(null, msg, null, false, "system");
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを表示します。指定したプレイヤーの発言として処理されます。
|
||||
* @param player プレイヤー(ワールドチャット、範囲チャットの場合は必須です)
|
||||
* @param message メッセージ
|
||||
* @param format フォーマット
|
||||
* @param sendDynmap dynmapへ送信するかどうか
|
||||
* @param name 発言者名
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(ChannelMember player, String message,
|
||||
String format, boolean sendDynmap, String name) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
String originalMessage = new String(message);
|
||||
|
||||
// 受信者を設定する
|
||||
Set<ChannelMember> recipients = new HashSet<ChannelMember>();
|
||||
|
||||
if ( isBroadcastChannel() ) {
|
||||
// ブロードキャストチャンネル
|
||||
|
||||
// NOTE: BungeeChannelは範囲チャットやワールドチャットをサポートしない
|
||||
|
||||
// 通常ブロードキャスト(全員へ送信)
|
||||
for ( ProxiedPlayer p : ProxyServer.getInstance().getPlayers() ) {
|
||||
ChannelMember cp = ChannelMember.getChannelMember(p);
|
||||
if ( !getHided().contains(cp) ) {
|
||||
recipients.add(cp);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// 通常チャンネル
|
||||
|
||||
for ( ChannelMember mem : getMembers() ) {
|
||||
if ( mem != null && mem.isOnline() && !getHided().contains(mem) ) {
|
||||
recipients.add(mem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// opListenAllChannel 設定がある場合は、
|
||||
// パーミッション lunachat-admin.listen-all-channels を持つプレイヤーを
|
||||
// 受信者に加える。
|
||||
if ( config.isOpListenAllChannel() ) {
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
ChannelMember cp = ChannelMember.getChannelMember(p);
|
||||
if ( cp.hasPermission("lunachat-admin.listen-all-channels")
|
||||
&& !recipients.contains(cp) ) {
|
||||
recipients.add(cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// hideされている場合は、受信対象者から抜く。
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
for ( ChannelMember cp : api.getHidelist(player) ) {
|
||||
if ( recipients.contains(cp) ) {
|
||||
recipients.remove(cp);
|
||||
}
|
||||
}
|
||||
|
||||
// フォーマットがある場合は置き換える
|
||||
if ( format != null ) {
|
||||
message = format.replace("%msg", message);
|
||||
}
|
||||
|
||||
// イベントコール
|
||||
// LunaChatChannelMessageEvent event =
|
||||
// new LunaChatChannelMessageEvent(
|
||||
// getName(), player, message, recipients, name, originalMessage);
|
||||
// Bukkit.getPluginManager().callEvent(event);
|
||||
// message = event.getMessage();
|
||||
// recipients = event.getRecipients();
|
||||
|
||||
// 送信する
|
||||
for ( ChannelMember p : recipients ) {
|
||||
p.sendMessage(message);
|
||||
}
|
||||
|
||||
// 設定に応じて、コンソールに出力する
|
||||
if ( config.isDisplayChatOnConsole() ) {
|
||||
Bukkit.getLogger().info(ChatColor.stripColor(message));
|
||||
}
|
||||
|
||||
// ロギング
|
||||
log(originalMessage, name, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルのオンライン人数を返す
|
||||
* @return オンライン人数
|
||||
* @see com.github.ucchyocean.lc.channel.Channel#getOnlineNum()
|
||||
*/
|
||||
@Override
|
||||
public int getOnlineNum() {
|
||||
|
||||
// ブロードキャストチャンネルならサーバー接続人数を返す
|
||||
if ( isBroadcastChannel() ) {
|
||||
return ProxyServer.getInstance().getOnlineCount();
|
||||
}
|
||||
|
||||
return super.getOnlineNum();
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルの総参加人数を返す
|
||||
* @return 総参加人数
|
||||
* @see com.github.ucchyocean.lc.channel.Channel#getTotalNum()
|
||||
*/
|
||||
@Override
|
||||
public int getTotalNum() {
|
||||
|
||||
// ブロードキャストチャンネルならサーバー接続人数を返す
|
||||
if ( isBroadcastChannel() ) {
|
||||
return ProxyServer.getInstance().getOnlineCount();
|
||||
}
|
||||
|
||||
return super.getTotalNum();
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルのメンバーを返す
|
||||
* @return チャンネルのメンバー
|
||||
* @see com.github.ucchyocean.lc.channel.Channel#getMembers()
|
||||
*/
|
||||
@Override
|
||||
public List<ChannelMember> getMembers() {
|
||||
|
||||
// ブロードキャストチャンネルなら、
|
||||
// 現在サーバーに接続している全プレイヤーをメンバーとして返す
|
||||
if ( isBroadcastChannel() ) {
|
||||
List<ChannelMember> mem = new ArrayList<ChannelMember>();
|
||||
for ( ProxiedPlayer p : ProxyServer.getInstance().getPlayers() ) {
|
||||
mem.add(ChannelMember.getChannelMember(p));
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
||||
return super.getMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param player プレイヤー
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
@Override
|
||||
protected String replaceKeywords(String format, ChannelMember player) {
|
||||
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
String msg = format;
|
||||
|
||||
// テンプレートのキーワードを、まず最初に置き換える
|
||||
for ( int i=0; i<=9; i++ ) {
|
||||
String key = "%" + i;
|
||||
if ( msg.contains(key) ) {
|
||||
if ( api.getTemplate("" + i) != null ) {
|
||||
msg = msg.replace(key, api.getTemplate("" + i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg = msg.replace("%ch", getName());
|
||||
//msg = msg.replace("%msg", message);
|
||||
msg = msg.replace("%color", getColorCode());
|
||||
msg = msg.replace("%to", getPrivateMessageTo());
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg = msg.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg = msg.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( player != null ) {
|
||||
msg = msg.replace("%username", player.getDisplayName());
|
||||
msg = msg.replace("%player", player.getName());
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
msg = msg.replace("%prefix", player.getPrefix());
|
||||
msg = msg.replace("%suffix", player.getSuffix());
|
||||
}
|
||||
|
||||
msg = msg.replace("%world", "");
|
||||
|
||||
if ( msg.contains("%server") ) {
|
||||
if ( player instanceof ChannelMemberProxiedPlayer ) {
|
||||
String serverName = ((ChannelMemberProxiedPlayer)player).getServer().getInfo().getName();
|
||||
msg = msg.replace("%server", serverName);
|
||||
}
|
||||
msg = msg.replace("%server", "");
|
||||
}
|
||||
|
||||
} else {
|
||||
msg = msg.replace("%username", "");
|
||||
msg = msg.replace("%player", "");
|
||||
msg = msg.replace("%prefix", "");
|
||||
msg = msg.replace("%suffix", "");
|
||||
msg = msg.replace("%world", "");
|
||||
msg = msg.replace("%server", "");
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param playerName プレイヤー名
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
private String replaceKeywordsForSystemMessages(String format, String playerName) {
|
||||
|
||||
String msg = format;
|
||||
msg = msg.replace("%ch", getName());
|
||||
msg = msg.replace("%color", getColorCode());
|
||||
msg = msg.replace("%username", playerName);
|
||||
msg = msg.replace("%player", playerName);
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* ログを記録する
|
||||
* @param name 発言者
|
||||
* @param message 記録するメッセージ
|
||||
* @param player プレイヤー
|
||||
*/
|
||||
private void log(String message, String name, ChannelMember player) {
|
||||
|
||||
// LunaChatのチャットログへ記録
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
if ( config.isLoggingChat() && logger != null ) {
|
||||
logger.log(message, name);
|
||||
}
|
||||
|
||||
// TODO ログ記録プラグイン連携を検討する
|
||||
}
|
||||
}
|
||||
ファイル差分が大きすぎるため表示されません。
差分を読み込み
@@ -1,647 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.channel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc.LunaChatMode;
|
||||
import com.github.ucchyocean.lc.Messages;
|
||||
import com.github.ucchyocean.lc.YamlConfig;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* チャンネルマネージャー
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ChannelManager implements LunaChatAPI {
|
||||
|
||||
private static final String MSG_BREAKUP = Messages.get("breakupMessage");
|
||||
|
||||
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 static final String FILE_NAME_HIDELIST = "hidelist.yml";
|
||||
|
||||
private File fileDefaults;
|
||||
private File fileTemplates;
|
||||
private File fileJapanize;
|
||||
private File fileDictionary;
|
||||
private File fileHidelist;
|
||||
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;
|
||||
private HashMap<String, List<ChannelMember>> hidelist;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
*/
|
||||
public ChannelManager() {
|
||||
reloadAllData();
|
||||
}
|
||||
|
||||
/**
|
||||
* すべて読み込みする
|
||||
*/
|
||||
@Override
|
||||
public void reloadAllData() {
|
||||
|
||||
// デフォルトチャンネル設定のロード
|
||||
fileDefaults = new File(LunaChat.getDataFolder(), FILE_NAME_DCHANNELS);
|
||||
|
||||
if ( !fileDefaults.exists() ) {
|
||||
makeEmptyFile(fileDefaults);
|
||||
}
|
||||
|
||||
YamlConfig config = YamlConfig.load(fileDefaults);
|
||||
|
||||
defaultChannels = new HashMap<String, String>();
|
||||
for ( String key : config.getKeys(false) ) {
|
||||
String value = config.getString(key);
|
||||
if ( value != null) {
|
||||
defaultChannels.put(key, value.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
// テンプレート設定のロード
|
||||
fileTemplates = new File(LunaChat.getDataFolder(), FILE_NAME_TEMPLATES);
|
||||
|
||||
if ( !fileTemplates.exists() ) {
|
||||
makeEmptyFile(fileTemplates);
|
||||
}
|
||||
|
||||
YamlConfig configTemplates = YamlConfig.load(fileTemplates);
|
||||
|
||||
templates = new HashMap<String, String>();
|
||||
for ( String key : configTemplates.getKeys(false) ) {
|
||||
templates.put(key, configTemplates.getString(key));
|
||||
}
|
||||
|
||||
// Japanize設定のロード
|
||||
fileJapanize = new File(LunaChat.getDataFolder(), FILE_NAME_JAPANIZE);
|
||||
|
||||
if ( !fileJapanize.exists() ) {
|
||||
makeEmptyFile(fileJapanize);
|
||||
}
|
||||
|
||||
YamlConfig configJapanize = YamlConfig.load(fileJapanize);
|
||||
|
||||
japanize = new HashMap<String, Boolean>();
|
||||
for ( String key : configJapanize.getKeys(false) ) {
|
||||
japanize.put(key, configJapanize.getBoolean(key));
|
||||
}
|
||||
|
||||
// dictionaryのロード
|
||||
fileDictionary = new File(LunaChat.getDataFolder(), FILE_NAME_DICTIONARY);
|
||||
|
||||
if ( !fileDictionary.exists() ) {
|
||||
makeEmptyFile(fileDictionary);
|
||||
}
|
||||
|
||||
YamlConfig configDictionary = YamlConfig.load(fileDictionary);
|
||||
|
||||
dictionary = new HashMap<String, String>();
|
||||
for ( String key : configDictionary.getKeys(false) ) {
|
||||
dictionary.put(key, configDictionary.getString(key));
|
||||
}
|
||||
|
||||
// hideリストのロード
|
||||
fileHidelist = new File(LunaChat.getDataFolder(), FILE_NAME_HIDELIST);
|
||||
|
||||
if ( !fileHidelist.exists() ) {
|
||||
makeEmptyFile(fileHidelist);
|
||||
}
|
||||
|
||||
YamlConfig configHidelist = YamlConfig.load(fileHidelist);
|
||||
|
||||
hidelist = new HashMap<String, List<ChannelMember>>();
|
||||
for ( String key : configHidelist.getKeys(false) ) {
|
||||
hidelist.put(key, new ArrayList<ChannelMember>());
|
||||
for ( String id : configHidelist.getStringList(key) ) {
|
||||
hidelist.get(key).add(ChannelMember.getChannelMember(id));
|
||||
}
|
||||
}
|
||||
|
||||
// チャンネル設定のロード
|
||||
channels = Channel.loadAllChannels();
|
||||
}
|
||||
|
||||
/**
|
||||
* すべて保存する
|
||||
*/
|
||||
protected void saveAllChannels() {
|
||||
|
||||
saveDefaults();
|
||||
|
||||
for ( Channel channel : channels.values() ) {
|
||||
channel.save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* デフォルトチャンネル設定を保存する
|
||||
* @return 保存したかどうか
|
||||
*/
|
||||
private boolean saveDefaults() {
|
||||
|
||||
try {
|
||||
YamlConfig config = new YamlConfig();
|
||||
for ( String key : defaultChannels.keySet() ) {
|
||||
config.set(key, defaultChannels.get(key));
|
||||
}
|
||||
config.save(fileDefaults);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* テンプレート設定を保存する
|
||||
* @return 保存したかどうか
|
||||
*/
|
||||
private boolean saveTemplates() {
|
||||
|
||||
try {
|
||||
YamlConfig config = new YamlConfig();
|
||||
for ( String key : templates.keySet() ) {
|
||||
config.set(key, templates.get(key));
|
||||
}
|
||||
config.save(fileTemplates);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize設定を保存する
|
||||
* @return 保存したかどうか
|
||||
*/
|
||||
private boolean saveJapanize() {
|
||||
|
||||
try {
|
||||
YamlConfig config = new YamlConfig();
|
||||
for ( String key : japanize.keySet() ) {
|
||||
config.set(key, japanize.get(key));
|
||||
}
|
||||
config.save(fileJapanize);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dictionary設定を保存する
|
||||
* @return 保存したかどうか
|
||||
*/
|
||||
private boolean saveDictionary() {
|
||||
|
||||
try {
|
||||
YamlConfig config = new YamlConfig();
|
||||
for ( String key : dictionary.keySet() ) {
|
||||
config.set(key, dictionary.get(key));
|
||||
}
|
||||
config.save(fileDictionary);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hidelist設定を保存する
|
||||
* @return 保存したかどうか
|
||||
*/
|
||||
private boolean saveHidelist() {
|
||||
|
||||
try {
|
||||
YamlConfig config = new YamlConfig();
|
||||
for ( String key : hidelist.keySet() ) {
|
||||
config.set(key, getIdList(hidelist.get(key)));
|
||||
}
|
||||
config.save(fileHidelist);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* デフォルトチャンネル設定を全て削除する
|
||||
*/
|
||||
public void removeAllDefaultChannels() {
|
||||
defaultChannels.clear();
|
||||
saveDefaults();
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのJapanize設定を返す
|
||||
* @param playerName プレイヤー名
|
||||
* @return Japanize設定
|
||||
*/
|
||||
@Override
|
||||
public boolean isPlayerJapanize(String playerName) {
|
||||
if ( !japanize.containsKey(playerName) ) {
|
||||
return true;
|
||||
}
|
||||
return japanize.get(playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定したチャンネル名が存在するかどうかを返す
|
||||
* @param channelName チャンネル名
|
||||
* @return 存在するかどうか
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#isExistChannel(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean isExistChannel(String channelName) {
|
||||
if ( channelName == null ) {
|
||||
return false;
|
||||
}
|
||||
return channels.containsKey(channelName.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* 全てのチャンネルを返す
|
||||
* @return 全てのチャンネル
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#getChannels()
|
||||
*/
|
||||
@Override
|
||||
public Collection<Channel> getChannels() {
|
||||
|
||||
return channels.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーが参加しているチャンネルを返す
|
||||
* @param playerName プレイヤー名
|
||||
* @return チャンネル
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#getChannelsByPlayer(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Collection<Channel> getChannelsByPlayer(String playerName) {
|
||||
|
||||
ChannelMember cp = ChannelMember.getChannelMember(playerName);
|
||||
Collection<Channel> result = new ArrayList<Channel>();
|
||||
for ( String key : channels.keySet() ) {
|
||||
Channel channel = channels.get(key);
|
||||
if ( channel.getMembers().contains(cp) ||
|
||||
channel.isGlobalChannel() ) {
|
||||
result.add(channel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーが参加しているデフォルトのチャンネルを返す
|
||||
* @param playerName プレイヤー
|
||||
* @return チャンネル
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#getDefaultChannel(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Channel getDefaultChannel(String playerName) {
|
||||
|
||||
String cname = defaultChannels.get(playerName);
|
||||
|
||||
if ( cname == null || !isExistChannel(cname) ) {
|
||||
return null;
|
||||
}
|
||||
return channels.get(cname);
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのデフォルトチャンネルを設定する
|
||||
* @param playerName プレイヤー
|
||||
* @param channelName チャンネル名
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#setDefaultChannel(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setDefaultChannel(String playerName, String channelName) {
|
||||
if ( channelName == null ) {
|
||||
removeDefaultChannel(playerName);
|
||||
return;
|
||||
}
|
||||
defaultChannels.put(playerName, channelName.toLowerCase());
|
||||
saveDefaults();
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定した名前のプレイヤーに設定されている、デフォルトチャンネルを削除する
|
||||
* @param playerName プレイヤー名
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#removeDefaultChannel(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void removeDefaultChannel(String playerName) {
|
||||
if ( defaultChannels.containsKey(playerName) ) {
|
||||
defaultChannels.remove(playerName);
|
||||
}
|
||||
saveDefaults();
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルを取得する
|
||||
* @param channelName チャンネル名、または、チャンネルの別名
|
||||
* @return チャンネル
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#getChannel(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Channel getChannel(String channelName) {
|
||||
if ( channelName == null ) return null;
|
||||
Channel channel = channels.get(channelName.toLowerCase());
|
||||
if ( channel != null ) return channel;
|
||||
for ( Channel ch : channels.values() ) {
|
||||
String alias = ch.getAlias();
|
||||
if ( alias != null && alias.length() > 0
|
||||
&& channelName.equalsIgnoreCase(ch.getAlias()) ) {
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新しいチャンネルを作成する
|
||||
* @param channelName チャンネル名
|
||||
* @return 作成されたチャンネル
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#createChannel(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Channel createChannel(String channelName) {
|
||||
|
||||
// イベントコール
|
||||
// LunaChatChannelCreateEvent event =
|
||||
// new LunaChatChannelCreateEvent(channelName, sender);
|
||||
// Bukkit.getPluginManager().callEvent(event);
|
||||
// if ( event.isCancelled() ) {
|
||||
// return null;
|
||||
// }
|
||||
// String name = event.getChannelName();
|
||||
String name = channelName;
|
||||
|
||||
Channel channel = null;
|
||||
if ( LunaChat.getMode() == LunaChatMode.BUKKIT ) {
|
||||
channel = new BukkitChannel(name);
|
||||
} else if ( LunaChat.getMode() == LunaChatMode.BUNGEE ) {
|
||||
channel = new BungeeChannel(name);
|
||||
}
|
||||
// TODO Standalone のチャンネル作成
|
||||
|
||||
channels.put(name.toLowerCase(), channel);
|
||||
channel.save();
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルを削除する
|
||||
* @param channelName 削除するチャンネル名
|
||||
* @return 削除したかどうか
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#removeChannel(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean removeChannel(String channelName) {
|
||||
|
||||
channelName = channelName.toLowerCase();
|
||||
|
||||
// イベントコール
|
||||
// LunaChatChannelRemoveEvent event =
|
||||
// new LunaChatChannelRemoveEvent(channelName, sender);
|
||||
// Bukkit.getPluginManager().callEvent(event);
|
||||
// if ( event.isCancelled() ) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
Channel channel = getChannel(channelName);
|
||||
if ( channel != null ) {
|
||||
|
||||
// 強制解散のメッセージを、残ったメンバーに流す
|
||||
if ( !channel.isPersonalChat() && !MSG_BREAKUP.equals("") ) {
|
||||
String message = new String(MSG_BREAKUP);
|
||||
message = message.replace("%ch", channel.getName());
|
||||
message = message.replace("%color", channel.getColorCode());
|
||||
for ( ChannelMember cp : channel.getMembers() ) {
|
||||
cp.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
// チャンネルの削除
|
||||
channel.remove();
|
||||
channels.remove(channelName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* テンプレートを取得する
|
||||
* @param id テンプレートID
|
||||
* @return テンプレート
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#getTemplate(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public String getTemplate(String id) {
|
||||
return templates.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* テンプレートを登録する
|
||||
* @param id テンプレートID
|
||||
* @param template テンプレート
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#setTemplate(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setTemplate(String id, String template) {
|
||||
templates.put(id, template);
|
||||
saveTemplates();
|
||||
}
|
||||
|
||||
/**
|
||||
* テンプレートを削除する
|
||||
* @param id テンプレートID
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#removeTemplate(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void removeTemplate(String id) {
|
||||
templates.remove(id);
|
||||
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);
|
||||
saveDictionary();
|
||||
}
|
||||
|
||||
/**
|
||||
* 該当のプレイヤーに関連するhidelistを取得する。
|
||||
* @param key プレイヤー
|
||||
* @return 指定されたプレイヤーをhideしているプレイヤー(非null)
|
||||
*/
|
||||
public List<ChannelMember> getHidelist(ChannelMember key) {
|
||||
if ( key == null ) {
|
||||
return new ArrayList<ChannelMember>();
|
||||
}
|
||||
if ( hidelist.containsKey(key.toString()) ) {
|
||||
return hidelist.get(key.toString());
|
||||
}
|
||||
return new ArrayList<ChannelMember>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 該当のプレイヤーがhideしているプレイヤーのリストを返す。
|
||||
* @param player プレイヤー
|
||||
* @return 指定したプレイヤーがhideしているプレイヤーのリスト(非null)
|
||||
*/
|
||||
public ArrayList<ChannelMember> getHideinfo(ChannelMember player) {
|
||||
if ( player == null ) {
|
||||
return new ArrayList<ChannelMember>();
|
||||
}
|
||||
ArrayList<ChannelMember> info = new ArrayList<ChannelMember>();
|
||||
for ( String key : hidelist.keySet() ) {
|
||||
if ( hidelist.get(key).contains(player) ) {
|
||||
info.add(ChannelMember.getChannelMember(key));
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたプレイヤーが、指定されたプレイヤーをhideするように設定する。
|
||||
* @param player hideする側のプレイヤー
|
||||
* @param hided hideされる側のプレイヤー
|
||||
*/
|
||||
public void addHidelist(ChannelMember player, ChannelMember hided) {
|
||||
String hidedId = hided.toString();
|
||||
if ( !hidelist.containsKey(hidedId) ) {
|
||||
hidelist.put(hidedId, new ArrayList<ChannelMember>());
|
||||
}
|
||||
if ( !hidelist.get(hidedId).contains(player) ) {
|
||||
hidelist.get(hidedId).add(player);
|
||||
saveHidelist();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたプレイヤーが、指定されたプレイヤーのhideを解除するように設定する。
|
||||
* @param player hideしていた側のプレイヤー
|
||||
* @param hided hideされていた側のプレイヤー
|
||||
*/
|
||||
public void removeHidelist(ChannelMember player, ChannelMember hided) {
|
||||
String hidedId = hided.toString();
|
||||
if ( !hidelist.containsKey(hidedId) ) {
|
||||
return;
|
||||
}
|
||||
if ( hidelist.get(hidedId).contains(player) ) {
|
||||
hidelist.get(hidedId).remove(player);
|
||||
if ( hidelist.get(hidedId).size() <= 0 ) {
|
||||
hidelist.remove(hidedId);
|
||||
}
|
||||
saveHidelist();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize変換を行う
|
||||
* @param message 変換するメッセージ
|
||||
* @param type 変換タイプ
|
||||
* @return 変換後のメッセージ、ただしイベントでキャンセルされた場合はnullが返されるので注意
|
||||
*/
|
||||
@Override
|
||||
public String japanize(String message, JapanizeType type) {
|
||||
|
||||
if ( type == JapanizeType.NONE ) {
|
||||
return message;
|
||||
}
|
||||
|
||||
// Japanize変換
|
||||
JapanizeConvertTask task = new JapanizeConvertTask(message, type, "%japanize");
|
||||
if ( task.runSync() ) {
|
||||
return task.getResult();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 該当プレイヤーのJapanize変換をオン/オフする
|
||||
* @param playerName 設定するプレイヤー名
|
||||
* @param doJapanize Japanize変換するかどうか
|
||||
*/
|
||||
@Override
|
||||
public void setPlayersJapanize(String playerName, boolean doJapanize) {
|
||||
japanize.put(playerName, doJapanize);
|
||||
saveJapanize();
|
||||
}
|
||||
|
||||
/**
|
||||
* ChannelMemberのリストを、IDのStringリストに変換して返す
|
||||
* @param players
|
||||
* @return
|
||||
*/
|
||||
private List<String> getIdList(List<ChannelMember> players) {
|
||||
List<String> results = new ArrayList<String>();
|
||||
for ( ChannelMember cp : players ) {
|
||||
results.add(cp.toString());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたファイル出力先に、空のYamlファイルを作成する
|
||||
* @param file 出力先
|
||||
*/
|
||||
private void makeEmptyFile(File file) {
|
||||
// try {
|
||||
// file.createNewFile();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
YamlConfig config = new YamlConfig();
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.channel;
|
||||
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* Japanize2行表示のときに、変換結果を遅延してチャンネルに表示するためのタスク
|
||||
* @author ucchy
|
||||
*/
|
||||
public class DelayedJapanizeChannelChatTask extends DelayedJapanizeConvertTask {
|
||||
|
||||
private Channel channel;
|
||||
private ChannelMember player;
|
||||
private String lineFormat;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param org 変換前の文字列
|
||||
* @param type 変換タイプ
|
||||
* @param channel 変換後に発言する、発言先チャンネル
|
||||
* @param player 発言したプレイヤー
|
||||
* @param japanizeFormat 変換後に発言するときの、発言フォーマット
|
||||
* @param lineFormat
|
||||
*/
|
||||
public DelayedJapanizeChannelChatTask(String org, JapanizeType type, Channel channel,
|
||||
ChannelMember player, String japanizeFormat, String lineFormat) {
|
||||
super(org, type, channel, player, japanizeFormat);
|
||||
this.channel = channel;
|
||||
this.player = player;
|
||||
this.lineFormat = lineFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if ( runSync() ) {
|
||||
// チャンネルへ送信
|
||||
String name = (player != null) ? player.getDisplayName() : "";
|
||||
channel.sendMessage(player, getResult(), lineFormat, true, name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.channel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.event.LunaChatPostJapanizeEvent;
|
||||
import com.github.ucchyocean.lc.japanize.IMEConverter;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.japanize.YukiKanaConverter;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* Japanize変換を実行して、実行後に発言を行うタスク
|
||||
* @author ucchy
|
||||
*/
|
||||
public class DelayedJapanizeConvertTask extends BukkitRunnable {
|
||||
|
||||
private static final String REGEX_URL = "https?://[\\w/:%#\\$&\\?\\(\\)~\\.=\\+\\-]+";
|
||||
|
||||
private String org;
|
||||
private JapanizeType type;
|
||||
private Channel channel;
|
||||
private ChannelMember player;
|
||||
private String format;
|
||||
private String result;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param org 変換前の文字列
|
||||
* @param type 変換タイプ
|
||||
* @param channel 変換後に発言する、発言先チャンネル
|
||||
* @param player 発言したプレイヤー
|
||||
* @param japanizeFormat 変換後に発言するときの、発言フォーマット
|
||||
*/
|
||||
public DelayedJapanizeConvertTask(String org, JapanizeType type, Channel channel,
|
||||
ChannelMember player, String japanizeFormat) {
|
||||
this.org = org;
|
||||
this.type = type;
|
||||
this.channel = channel;
|
||||
this.player = player;
|
||||
this.format = japanizeFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
runSync();
|
||||
}
|
||||
|
||||
/**
|
||||
* 同期処理で変換を行います。結果は getResult() で取得してください。
|
||||
* @return 処理を実行したかどうか(イベントでキャンセルされた場合はfalseになります)
|
||||
*/
|
||||
public boolean runSync() {
|
||||
|
||||
// 変換対象外のキーワード
|
||||
HashMap<String, String> keywordMap = new HashMap<String, String>();
|
||||
ArrayList<String> keywords = new ArrayList<String>();
|
||||
if ( LunaChat.getConfig().isJapanizeIgnorePlayerName() ) {
|
||||
for ( Player player : Bukkit.getOnlinePlayers() ) {
|
||||
keywords.add(player.getName());
|
||||
}
|
||||
}
|
||||
HashMap<String, String> dictionary =
|
||||
LunaChat.getAPI().getAllDictionary();
|
||||
|
||||
// カラーコード削除、URL削除
|
||||
String deletedURL = Utility.stripColorCode(org.replaceAll(REGEX_URL, " "));
|
||||
|
||||
// キーワードをロック
|
||||
int index = 0;
|
||||
String keywordLocked = deletedURL;
|
||||
for ( String keyword : keywords ) {
|
||||
if ( keywordLocked.contains(keyword) ) {
|
||||
index++;
|
||||
String key = "<" + makeMultibytesDigit(index) + ">";
|
||||
keywordLocked = keywordLocked.replace(keyword, key);
|
||||
keywordMap.put(key, keyword);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
// キーワードのアンロック
|
||||
for ( String key : keywordMap.keySet() ) {
|
||||
japanized = japanized.replace(key, keywordMap.get(key));
|
||||
}
|
||||
|
||||
// 変換後の文字列にNGワードが含まれている場合は、マスクする
|
||||
for ( Pattern pattern :
|
||||
LunaChat.getConfig().getNgwordCompiled() ) {
|
||||
Matcher matcher = pattern.matcher(japanized);
|
||||
if ( matcher.find() ) {
|
||||
japanized = matcher.replaceAll(
|
||||
Utility.getAstariskString(matcher.group(0).length()));
|
||||
}
|
||||
}
|
||||
|
||||
// イベントコール
|
||||
String channelName = (channel == null) ? "" : channel.getName();
|
||||
LunaChatPostJapanizeEvent event =
|
||||
new LunaChatPostJapanizeEvent(channelName, player, org, japanized);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if ( event.isCancelled() ) {
|
||||
return false;
|
||||
}
|
||||
japanized = event.getJapanized();
|
||||
|
||||
// フォーマットする
|
||||
result = format.replace("%msg", org);
|
||||
result = result.replace("%japanize", japanized);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize変換の結果を返します。
|
||||
* @return 変換結果
|
||||
*/
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数値を、全角文字の文字列に変換して返す
|
||||
* @param digit
|
||||
* @return
|
||||
*/
|
||||
private 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,69 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.channel;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.bukkit.LunaChatBukkit;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc.member.ChannelMemberPlayer;
|
||||
|
||||
/**
|
||||
* Japanize2行表示のときに、変換結果を遅延して通常チャットに表示するためのタスク
|
||||
* @author ucchy
|
||||
*/
|
||||
public class DelayedJapanizeNormalChatTask extends DelayedJapanizeConvertTask {
|
||||
|
||||
private ChannelMember player;
|
||||
private AsyncPlayerChatEvent event;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param org 変換前の文字列
|
||||
* @param type 変換タイプ
|
||||
* @param player 発言したプレイヤー
|
||||
* @param japanizeFormat 変換後に発言するときの、発言フォーマット
|
||||
* @param event イベント
|
||||
*/
|
||||
public DelayedJapanizeNormalChatTask(String org, JapanizeType type,
|
||||
ChannelMember player, String japanizeFormat, final AsyncPlayerChatEvent event) {
|
||||
super(org, type, null, player, japanizeFormat);
|
||||
this.player = player;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if ( runSync() ) {
|
||||
|
||||
String result = getResult();
|
||||
|
||||
// 送信
|
||||
for ( Player p : event.getRecipients() ) {
|
||||
p.sendMessage(result);
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage(result);
|
||||
|
||||
// 設定に応じてdynmapへ送信する
|
||||
if ( LunaChat.getConfig().isSendBroadcastChannelChatToDynmap() &&
|
||||
LunaChatBukkit.getInstance().getDynmap() != null ) {
|
||||
if ( player != null && player instanceof ChannelMemberPlayer
|
||||
&& ((ChannelMemberPlayer)player).getPlayer() != null )
|
||||
LunaChatBukkit.getInstance().getDynmap().chat(((ChannelMemberPlayer)player).getPlayer(), result);
|
||||
else
|
||||
LunaChatBukkit.getInstance().getDynmap().broadcast(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.channel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* Japanize2行表示のときに、変換結果を遅延して指定した受信者に表示するためのタスク。
|
||||
* 他プラグインのチャンネル(mcMMOのパーティチャットや、TownyChatなど)に、Japanize変換結果を表示するために使用する。
|
||||
* @author ucchy
|
||||
*/
|
||||
public class DelayedJapanizeRecipientChatTask extends DelayedJapanizeConvertTask {
|
||||
|
||||
private List<Player> recipients;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param org 変換前の文字列
|
||||
* @param type 変換タイプ
|
||||
* @param player 発言したプレイヤー
|
||||
* @param japanizeFormat 変換後に発言するときの、発言フォーマット
|
||||
* @param recipients メッセージ受信者
|
||||
*/
|
||||
public DelayedJapanizeRecipientChatTask(String org, JapanizeType type, ChannelMember player,
|
||||
String japanizeFormat, List<Player> recipients) {
|
||||
super(org, type, null, player, japanizeFormat);
|
||||
this.recipients = recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if ( runSync() ) {
|
||||
|
||||
String result = getResult();
|
||||
|
||||
// 送信
|
||||
for ( Player p : recipients ) {
|
||||
p.sendMessage(result);
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.channel;
|
||||
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* Japanize2行表示のときに、変換結果を遅延してチャンネルに表示するためのタスク
|
||||
* @author ucchy
|
||||
*/
|
||||
public class JapanizeChannelChatTask implements Runnable {
|
||||
|
||||
private Channel channel;
|
||||
private ChannelMember player;
|
||||
private String lineFormat;
|
||||
|
||||
private JapanizeConvertTask task;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param org 変換前の文字列
|
||||
* @param type 変換タイプ
|
||||
* @param channel 変換後に発言する、発言先チャンネル
|
||||
* @param player 発言したプレイヤー
|
||||
* @param japanizeFormat 変換後に発言するときの、発言フォーマット
|
||||
* @param lineFormat
|
||||
*/
|
||||
public JapanizeChannelChatTask(String org, JapanizeType type, Channel channel,
|
||||
ChannelMember player, String japanizeFormat, String lineFormat) {
|
||||
|
||||
task = new JapanizeConvertTask(org, type, japanizeFormat);
|
||||
this.channel = channel;
|
||||
this.player = player;
|
||||
this.lineFormat = lineFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if ( task.runSync() ) {
|
||||
// チャンネルへ送信
|
||||
String name = (player != null) ? player.getDisplayName() : "";
|
||||
channel.sendMessage(player, task.getResult(), lineFormat, true, name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.channel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.japanize.IMEConverter;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.japanize.YukiKanaConverter;
|
||||
|
||||
/**
|
||||
* Japanize変換を実行して、実行後に発言を行うタスク
|
||||
* @author ucchy
|
||||
*/
|
||||
public class JapanizeConvertTask {
|
||||
|
||||
private static final String REGEX_URL = "https?://[\\w/:%#\\$&\\?\\(\\)~\\.=\\+\\-]+";
|
||||
|
||||
private String org;
|
||||
private JapanizeType type;
|
||||
private String format;
|
||||
private String result;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param org 変換前の文字列
|
||||
* @param type 変換タイプ
|
||||
* @param japanizeFormat 変換後に発言するときの、発言フォーマット
|
||||
*/
|
||||
public JapanizeConvertTask(String org, JapanizeType type, String japanizeFormat) {
|
||||
this.org = org;
|
||||
this.type = type;
|
||||
this.format = japanizeFormat;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
runSync();
|
||||
}
|
||||
|
||||
/**
|
||||
* 同期処理で変換を行います。結果は getResult() で取得してください。
|
||||
* @return 処理を実行したかどうか(イベントでキャンセルされた場合はfalseになります)
|
||||
*/
|
||||
public boolean runSync() {
|
||||
|
||||
// 変換対象外のキーワード
|
||||
HashMap<String, String> keywordMap = new HashMap<String, String>();
|
||||
ArrayList<String> keywords = new ArrayList<String>();
|
||||
if ( LunaChat.getConfig().isJapanizeIgnorePlayerName() ) {
|
||||
// TODO
|
||||
// for ( Player player : Bukkit.getOnlinePlayers() ) {
|
||||
// keywords.add(player.getName());
|
||||
// }
|
||||
}
|
||||
HashMap<String, String> dictionary =
|
||||
LunaChat.getAPI().getAllDictionary();
|
||||
|
||||
// カラーコード削除、URL削除
|
||||
String deletedURL = Utility.stripColorCode(org.replaceAll(REGEX_URL, " "));
|
||||
|
||||
// キーワードをロック
|
||||
int index = 0;
|
||||
String keywordLocked = deletedURL;
|
||||
for ( String keyword : keywords ) {
|
||||
if ( keywordLocked.contains(keyword) ) {
|
||||
index++;
|
||||
String key = "<" + makeMultibytesDigit(index) + ">";
|
||||
keywordLocked = keywordLocked.replace(keyword, key);
|
||||
keywordMap.put(key, keyword);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
// キーワードのアンロック
|
||||
for ( String key : keywordMap.keySet() ) {
|
||||
japanized = japanized.replace(key, keywordMap.get(key));
|
||||
}
|
||||
|
||||
// 変換後の文字列にNGワードが含まれている場合は、マスクする
|
||||
for ( Pattern pattern : LunaChat.getConfig().getNgwordCompiled() ) {
|
||||
Matcher matcher = pattern.matcher(japanized);
|
||||
if ( matcher.find() ) {
|
||||
japanized = matcher.replaceAll(
|
||||
Utility.getAstariskString(matcher.group(0).length()));
|
||||
}
|
||||
}
|
||||
|
||||
// イベントコール
|
||||
// String channelName = (channel == null) ? "" : channel.getName();
|
||||
// EventResult event = LunaChat.getEventSender().sendLunaChatPostJapanizeEvent(
|
||||
// channelName, player, org, japanized);
|
||||
// if ( event.isCancelled() ) {
|
||||
// return false;
|
||||
// }
|
||||
// japanized = event.getValueAsString("japanized");
|
||||
|
||||
// フォーマットする
|
||||
result = format.replace("%msg", org);
|
||||
result = result.replace("%japanize", japanized);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize変換の結果を返します。
|
||||
* @return 変換結果
|
||||
*/
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数値を、全角文字の文字列に変換して返す
|
||||
* @param digit
|
||||
* @return
|
||||
*/
|
||||
private 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,108 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* acceptコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class AcceptCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "accept";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageAccept";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 招待を受けていないプレイヤーなら、エラーを表示して終了する
|
||||
if (!DataMaps.inviteMap.containsKey(sender.getName())) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotInvited");
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルを取得して、招待記録を消去する
|
||||
String channelName = DataMaps.inviteMap.get(sender.getName());
|
||||
Channel channel = api.getChannel(channelName);
|
||||
DataMaps.inviteMap.remove(sender.getName());
|
||||
DataMaps.inviterMap.remove(sender.getName());
|
||||
|
||||
// 取得できなかったらエラー終了する
|
||||
if (channel == null) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotfoundChannel");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 既に参加しているなら、エラーを表示して終了する
|
||||
if (channel.getMembers().contains(sender)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgInvitedAlreadyJoin");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 参加する
|
||||
channel.addMember(sender);
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgJoin", channel.getName());
|
||||
|
||||
// デフォルトの発言先に設定する
|
||||
api.setDefaultChannel(sender.getName(), channelName);
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgSet", channelName);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* banコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class BanCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "ban";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY1 = "usageBan";
|
||||
private static final String USAGE_KEY2 = "usageBan2";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.MODERATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember sender, String label) {
|
||||
sendResourceMessage(sender, "", USAGE_KEY1, label);
|
||||
sendResourceMessage(sender, "", USAGE_KEY2, label);
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドを実行します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @param args 実行時の引数
|
||||
* @return コマンドが実行されたかどうか
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#runCommand(java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean runCommand(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 実行引数から、BANするユーザーを取得する
|
||||
String kickedName = "";
|
||||
if (args.length >= 2) {
|
||||
kickedName = args[1];
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 対象チャンネルを取得、取得できない場合はエラー表示して終了する
|
||||
Channel channel = null;
|
||||
boolean isSpecifiedChannel = false;
|
||||
if (args.length >= 3) {
|
||||
channel = api.getChannel(args[2]);
|
||||
isSpecifiedChannel = true;
|
||||
} else {
|
||||
channel = api.getDefaultChannel(sender.getName());
|
||||
}
|
||||
if (channel == null) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNoJoin");
|
||||
return true;
|
||||
}
|
||||
|
||||
// モデレーターかどうか確認する
|
||||
if ( !channel.hasModeratorPermission(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
|
||||
return true;
|
||||
}
|
||||
|
||||
// グローバルチャンネルならBANできない
|
||||
if ( channel.isGlobalChannel() ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCannotBANGlobal", channel.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
// BANされるプレイヤーがメンバーかどうかチェックする
|
||||
ChannelMember kicked = ChannelMember.getChannelMember(kickedName);
|
||||
if (!channel.getMembers().contains(kicked)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNomemberOther");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 既にBANされているかどうかチェックする
|
||||
if (channel.getBanned().contains(kicked)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgAlreadyBanned");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 期限付きBANの場合、期限の指定が正しいかどうかをチェックする
|
||||
int expireMinutes = -1;
|
||||
if (args.length >= 3 && !isSpecifiedChannel) {
|
||||
if ( !args[2].matches("[0-9]+") ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgInvalidBanExpireParameter");
|
||||
return true;
|
||||
}
|
||||
expireMinutes = Integer.parseInt(args[2]);
|
||||
if ( expireMinutes < 1 || 43200 < expireMinutes ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgInvalidBanExpireParameter");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// BAN実行
|
||||
channel.getBanned().add(kicked);
|
||||
if ( expireMinutes != -1 ) {
|
||||
long expire = System.currentTimeMillis() + expireMinutes * 60 * 1000;
|
||||
channel.getBanExpires().put(kicked, expire);
|
||||
}
|
||||
channel.removeMember(kicked);
|
||||
|
||||
// senderに通知メッセージを出す
|
||||
if ( expireMinutes != -1 ) {
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgBanWithExpire", kickedName, channel.getName(), expireMinutes);
|
||||
} else {
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgBan", kickedName, channel.getName());
|
||||
}
|
||||
|
||||
// チャンネルに通知メッセージを出す
|
||||
if ( expireMinutes != -1 ) {
|
||||
sendResourceMessageWithKeyword(channel,
|
||||
"banWithExpireMessage", kicked, expireMinutes);
|
||||
} else {
|
||||
sendResourceMessageWithKeyword(channel, "banMessage", kicked);
|
||||
}
|
||||
|
||||
// BANされた人に通知メッセージを出す
|
||||
if ( kicked != null && kicked.isOnline() ) {
|
||||
sendResourceMessage(kicked, PREINFO,
|
||||
"cmdmsgBanned", channel.getName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* createコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class CreateCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "create";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageCreate";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.MODERATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 実行引数から、作成するチャンネルを取得する
|
||||
String name = "";
|
||||
String desc = "";
|
||||
if (args.length >= 2) {
|
||||
name = args[1];
|
||||
if (args.length >= 3) {
|
||||
desc = args[2];
|
||||
}
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
Channel other = api.getChannel(name);
|
||||
if ( other != null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgExist");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 使用可能なチャンネル名かどうかをチェックする
|
||||
if ( !name.matches("[0-9a-zA-Z\\-_]+") ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgCannotUseForChannel", name);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 最低文字列長を上回っているかをチェックする
|
||||
if ( name.length() < config.getMinChannelNameLength() ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgCannotUseForChannelTooShort",
|
||||
name, config.getMinChannelNameLength());
|
||||
return true;
|
||||
}
|
||||
|
||||
// 最大文字列長を下回っているかをチェックする
|
||||
if ( name.length() > config.getMaxChannelNameLength() ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgCannotUseForChannelTooLong",
|
||||
name, config.getMaxChannelNameLength());
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネル作成
|
||||
Channel channel = api.createChannel(name);
|
||||
if ( channel != null ) {
|
||||
channel.setDescription(desc);
|
||||
channel.save();
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgCreate", name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* データマップ
|
||||
* @author ucchy
|
||||
*/
|
||||
public class DataMaps {
|
||||
|
||||
/** 招待された人→招待されたチャンネル名 のマップ */
|
||||
protected static HashMap<String, String> inviteMap;
|
||||
|
||||
/** 招待された人→招待した人 のマップ */
|
||||
protected static HashMap<String, String> inviterMap;
|
||||
|
||||
/** tell/rコマンドの送信者→受信者 のマップ */
|
||||
protected static HashMap<String, String> privateMessageMap;
|
||||
|
||||
static {
|
||||
inviteMap = new HashMap<String, String>();
|
||||
inviterMap = new HashMap<String, String>();
|
||||
privateMessageMap = new HashMap<String, String>();
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* denyコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class DenyCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "deny";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageDeny";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 招待を受けていないプレイヤーなら、エラーを表示して終了する
|
||||
if (!DataMaps.inviteMap.containsKey(sender.getName())) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotInvited");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待者を取得して、招待記録を消去する
|
||||
String inviterName = DataMaps.inviterMap.get(sender.getName());
|
||||
DataMaps.inviteMap.remove(sender.getName());
|
||||
DataMaps.inviterMap.remove(sender.getName());
|
||||
|
||||
// メッセージ送信
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgDeny");
|
||||
ChannelMember inviter = ChannelMember.getChannelMember(inviterName);
|
||||
if (inviter != null) {
|
||||
sendResourceMessage(inviter, PREINFO, "cmdmsgDenyed");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* 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(
|
||||
ChannelMember sender, String label) {
|
||||
sendResourceMessage(sender, "", USAGE_KEY, label);
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* 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(
|
||||
ChannelMember 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(ChannelMember 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* formatコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class FormatCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "format";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageFormat";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.MODERATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
// このコマンドは、デフォルトチャンネルでない人も実行できるが、その場合はチャンネル名を指定する必要がある
|
||||
String format = "";
|
||||
String cname = null;
|
||||
if ( args.length >= 2 ) {
|
||||
Channel def = api.getDefaultChannel(sender.getName());
|
||||
if ( def != null ) {
|
||||
cname = def.getName();
|
||||
}
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
format = format + args[i] + " ";
|
||||
}
|
||||
} else if ( args.length >= 3 ) {
|
||||
cname = args[1];
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
format = format + args[i] + " ";
|
||||
}
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
format = format.trim();
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
Channel channel = api.getChannel(cname);
|
||||
if ( channel == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExist");
|
||||
return true;
|
||||
}
|
||||
|
||||
// モデレーターかどうか確認する
|
||||
if ( !channel.hasModeratorPermission(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 制約キーワードを確認する
|
||||
List<String> constraints = config.getFormatConstraint();
|
||||
String tempFormat = new String(format);
|
||||
for ( int i=0; i<=9; i++ ) {
|
||||
String key = "%" + i;
|
||||
if ( tempFormat.contains(key) && api.getTemplate(i + "") != null ) {
|
||||
tempFormat = tempFormat.replace(key, api.getTemplate("" + i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
for ( String constraint : constraints ) {
|
||||
if ( !tempFormat.contains(constraint) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgFormatConstraint", constraint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// フォーマットの設定
|
||||
channel.setFormat(format);
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgFormat", format);
|
||||
channel.save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* helpコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class HelpCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "help";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageHelp";
|
||||
|
||||
// 1ページに表示するコマンドヘルプの項目数
|
||||
private static final int PAGE_ITEM_NUM = 6;
|
||||
|
||||
private ArrayList<SubCommandAbst> commands;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param commands
|
||||
*/
|
||||
public HelpCommand(ArrayList<SubCommandAbst> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(ChannelMember sender, String label, String[] args) {
|
||||
|
||||
CommandType type = CommandType.USER;
|
||||
int page = 1;
|
||||
|
||||
if ( args.length >= 2 &&
|
||||
(args[1].equalsIgnoreCase("mod")
|
||||
|| args[1].equalsIgnoreCase("moderator") ) ) {
|
||||
type = CommandType.MODERATOR;
|
||||
} else if ( args.length >= 2 && args[1].equalsIgnoreCase("admin") ) {
|
||||
type = CommandType.ADMIN;
|
||||
} else if ( args.length >= 2 && args[1].matches("[1-9]") ) {
|
||||
page = Integer.parseInt(args[1]);
|
||||
}
|
||||
|
||||
if ( args.length >= 3 && args[2].matches("[1-9]") ) {
|
||||
page = Integer.parseInt(args[2]);
|
||||
}
|
||||
|
||||
printUsage(sender, label, type, page);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドの使い方を senderに送る
|
||||
* @param sender
|
||||
* @param label
|
||||
* @param type コマンド種別
|
||||
* @param page ページ
|
||||
*/
|
||||
private void printUsage(ChannelMember sender, String label,
|
||||
CommandType type, int page) {
|
||||
|
||||
String typeDesc;
|
||||
switch (type) {
|
||||
case USER:
|
||||
typeDesc = "user";
|
||||
break;
|
||||
case MODERATOR:
|
||||
typeDesc = "moderator";
|
||||
break;
|
||||
case ADMIN:
|
||||
typeDesc = "admin";
|
||||
break;
|
||||
default:
|
||||
typeDesc = "user";
|
||||
}
|
||||
|
||||
// 種別に該当するコマンドを取得
|
||||
ArrayList<SubCommandAbst> com = new ArrayList<SubCommandAbst>();
|
||||
for ( SubCommandAbst c : commands ) {
|
||||
if ( c.getCommandType() == type
|
||||
&& sender.hasPermission(c.getPermissionNode()) ) {
|
||||
com.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
int lastPage = ( (com.size() - 1) / PAGE_ITEM_NUM) + 1;
|
||||
|
||||
// 表示処理
|
||||
sendResourceMessage(sender, "", "usageTop", typeDesc, page, lastPage);
|
||||
for (int index=(page-1)*PAGE_ITEM_NUM; index<page*PAGE_ITEM_NUM; index++) {
|
||||
if ( index >= com.size() ) break;
|
||||
com.get(index).sendUsageMessage(sender, label);
|
||||
}
|
||||
sendResourceMessage(sender, "", "usageFoot");
|
||||
if ( page < lastPage ) {
|
||||
if ( type != CommandType.USER ) {
|
||||
sendResourceMessage(sender, "", "usageNoticeNextPage", typeDesc, (page + 1));
|
||||
} else {
|
||||
sendResourceMessage(sender, "", "usageNoticeNextPage", "", (page + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,215 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.github.ucchyocean.lc.Messages;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* hideコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class HideCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "hide";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY1 = "usageHide";
|
||||
private static final String USAGE_KEY2 = "usageHidePlayer";
|
||||
|
||||
private static final String HIDE_CHANNEL_FIRSTLINE =
|
||||
Messages.get("hideChannelFirstLine");
|
||||
private static final String HIDE_PLAYER_FIRSTLINE =
|
||||
Messages.get("hidePlayerFirstLine");
|
||||
private static final String LIST_ENDLINE = Messages.get("listEndLine");
|
||||
private static final String LIST_PREFIX = Messages.get("listPlainPrefix");
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember sender, String label) {
|
||||
sendResourceMessage(sender, "", USAGE_KEY1, label);
|
||||
sendResourceMessage(sender, "", USAGE_KEY2, label);
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドを実行します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @param args 実行時の引数
|
||||
* @return コマンドが実行されたかどうか
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#runCommand(java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean runCommand(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
String cname = null;
|
||||
boolean isPlayerCommand = false;
|
||||
boolean isChannelCommand = false;
|
||||
if ( args.length <= 1 ) {
|
||||
Channel def = api.getDefaultChannel(sender.getName());
|
||||
if ( def != null ) {
|
||||
cname = def.getName();
|
||||
}
|
||||
} else if ( args.length >= 2 ) {
|
||||
|
||||
if ( args[1].equals("list") ) {
|
||||
// 指定されたコマンドが「/ch hide list」なら、リストを表示して終了
|
||||
for ( String item : getHideInfoList(sender) ) {
|
||||
sender.sendMessage(item);
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if ( args.length >= 3 && args[1].equalsIgnoreCase("player") ) {
|
||||
// 指定されたコマンドが「/ch hide player (player名)」なら、対象をプレイヤーとする。
|
||||
isPlayerCommand = true;
|
||||
isChannelCommand = false;
|
||||
cname = args[2];
|
||||
|
||||
} else if ( args.length >= 3 && args[1].equalsIgnoreCase("channel") ) {
|
||||
// 指定されたコマンドが「/ch hide channel (channel名)」なら、対象をチャンネルとする。
|
||||
isPlayerCommand = false;
|
||||
isChannelCommand = true;
|
||||
cname = args[2];
|
||||
|
||||
} else {
|
||||
// 「/ch hide (player名 または channel名)」
|
||||
cname = args[1];
|
||||
}
|
||||
}
|
||||
|
||||
// チャンネルかプレイヤーが存在するかどうかをチェックする
|
||||
Channel channel = api.getChannel(cname);
|
||||
if ( !isPlayerCommand && channel != null ) {
|
||||
isChannelCommand = true;
|
||||
} else if ( Utility.existsOfflinePlayer(cname) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExistChannelAndPlayer");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( isChannelCommand ) {
|
||||
// チャンネルが対象の場合の処理
|
||||
|
||||
// 既に非表示になっていないかどうかをチェックする
|
||||
if ( channel.getHided().contains(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgAlreadyHided");
|
||||
return true;
|
||||
}
|
||||
|
||||
// メンバーかどうかをチェックする
|
||||
if ( !channel.getMembers().contains(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNomember");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 設定する
|
||||
channel.getHided().add(sender);
|
||||
channel.save();
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgHided", channel.getName());
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
// プレイヤーが対象の場合の処理
|
||||
|
||||
// 既に非表示になっていないかどうかをチェックする
|
||||
ChannelMember hided = ChannelMember.getChannelMember(cname);
|
||||
if ( api.getHidelist(hided).contains(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgAlreadyHidedPlayer");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 自分自身を指定していないかどうかチェックする
|
||||
if ( hided.equals(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCannotHideSelf");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 設定する
|
||||
api.addHidelist(sender, hided);
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgHidedPlayer", hided.getDisplayName());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* hide情報のメッセージを取得する
|
||||
* @param player 対象となるプレイヤー
|
||||
* @return メッセージ
|
||||
*/
|
||||
private ArrayList<String> getHideInfoList(ChannelMember player) {
|
||||
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
items.add(HIDE_CHANNEL_FIRSTLINE);
|
||||
for ( String channel : getHideChannelNameList(player) ) {
|
||||
items.add(LIST_PREFIX + channel);
|
||||
}
|
||||
items.add(HIDE_PLAYER_FIRSTLINE);
|
||||
for ( ChannelMember p : api.getHideinfo(player) ) {
|
||||
items.add(LIST_PREFIX + p.getDisplayName());
|
||||
}
|
||||
items.add(LIST_ENDLINE);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定したプレイヤーが非表示にしているチャンネル名のリストを返す
|
||||
* @param player プレイヤー
|
||||
* @return 指定したプレイヤーが非表示にしているチャンネルのリスト
|
||||
*/
|
||||
private ArrayList<String> getHideChannelNameList(ChannelMember player) {
|
||||
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
for ( Channel channel : api.getChannels() ) {
|
||||
if ( channel.getHided().contains(player) ) {
|
||||
names.add(channel.getName());
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* infoコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class InfoCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "info";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageInfo";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
// このコマンドは、デフォルトチャンネルでない人も実行できるが、その場合はチャンネル名を指定する必要がある
|
||||
String cname = null;
|
||||
if ( args.length <= 1 ) {
|
||||
Channel def = api.getDefaultChannel(sender.getName());
|
||||
if ( def != null ) {
|
||||
cname = def.getName();
|
||||
}
|
||||
} else if ( args.length >= 2 ) {
|
||||
cname = args[1];
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルが存在するかどうか確認する
|
||||
Channel channel = api.getChannel(cname);
|
||||
if ( channel == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExist");
|
||||
return true;
|
||||
}
|
||||
|
||||
// BANされていないかどうか確認する
|
||||
if ( channel.getBanned().contains(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgBanned");
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルモデレーターかどうか確認する
|
||||
boolean isModerator = channel.hasModeratorPermission(sender);
|
||||
|
||||
// 情報を取得して表示する
|
||||
List<String> list = channel.getInfo(isModerator);
|
||||
for (String msg : list) {
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* inviteコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class InviteCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "invite";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageInvite";
|
||||
|
||||
private static final String PERMISSION_NODE_FORCE_INVITE
|
||||
= "lunachat-admin.force-invite";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.MODERATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(ChannelMember sender, String label, String[] args) {
|
||||
|
||||
if ( args.length >= 3 && args[2].equalsIgnoreCase("force") ) {
|
||||
return runForceInviteCommand(sender, label, args);
|
||||
}
|
||||
|
||||
return runNormalInviteCommand(sender, label, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常のinviteコマンドを処理する
|
||||
* @param sender
|
||||
* @param label
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean runNormalInviteCommand(ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// デフォルトの発言先を取得する
|
||||
Channel channel = api.getDefaultChannel(sender.getName());
|
||||
if ( channel == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNoJoin");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 実行引数から招待する人を取得する
|
||||
String invitedName = "";
|
||||
if (args.length >= 2) {
|
||||
invitedName = args[1];
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// モデレーターかどうか確認する
|
||||
if ( !channel.hasModeratorPermission(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待相手が存在するかどうかを確認する
|
||||
ChannelMember invited = ChannelMember.getChannelMember(invitedName);
|
||||
if ( invited == null || !invited.isOnline() ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotfoundPlayer", invitedName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待相手が既にチャンネルに参加しているかどうかを確認する
|
||||
if (channel.getMembers().contains(invited)) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgInvitedAlreadyExist", invitedName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待を送信する
|
||||
DataMaps.inviteMap.put(invitedName, channel.getName());
|
||||
DataMaps.inviterMap.put(invitedName, sender.getName());
|
||||
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgInvite", invitedName, channel.getName());
|
||||
sendResourceMessage(invited, PREINFO,
|
||||
"cmdmsgInvited1", sender.getName(), channel.getName());
|
||||
sendResourceMessage(invited, PREINFO, "cmdmsgInvited2");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 強制入室コマンドを処理する
|
||||
* @param sender
|
||||
* @param label
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean runForceInviteCommand(ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// パーミッションチェック
|
||||
if ( !sender.hasPermission(PERMISSION_NODE_FORCE_INVITE) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgPermission",
|
||||
PERMISSION_NODE_FORCE_INVITE);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 引数チェック
|
||||
// このコマンドは、デフォルトチャンネルでない人も実行できるが、その場合はチャンネル名を指定する必要がある
|
||||
String cname = null;
|
||||
if ( args.length <= 3 ) {
|
||||
Channel def = api.getDefaultChannel(sender.getName());
|
||||
if ( def != null ) {
|
||||
cname = def.getName();
|
||||
}
|
||||
} else if ( args.length >= 4 ) {
|
||||
cname = args[3];
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルが存在するかどうか確認する
|
||||
Channel channel = api.getChannel(cname);
|
||||
if ( channel == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExist");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待相手が存在するかどうかを確認する
|
||||
String invitedName = args[1];
|
||||
ChannelMember invited = ChannelMember.getChannelMember(invitedName);
|
||||
if ( invited == null || !invited.isOnline() ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotfoundPlayer", invitedName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待相手が既にチャンネルに参加しているかどうかを確認する
|
||||
if (channel.getMembers().contains(invited)) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgInvitedAlreadyExist", invitedName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 参加する
|
||||
channel.addMember(invited);
|
||||
api.setDefaultChannel(invitedName, cname);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgInvite", invitedName, channel.getName());
|
||||
sendResourceMessage(invited, PREINFO,
|
||||
"cmdmsgJoin", channel.getName());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* joinコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class JoinCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "join";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String PERMISSION_SPEAK_PREFIX = "lunachat.speak";
|
||||
private static final String USAGE_KEY = "usageJoin";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 実行引数から、参加するチャンネルを取得する
|
||||
String channelName = "";
|
||||
StringBuilder message = new StringBuilder();
|
||||
if (!args[0].equalsIgnoreCase("join")) {
|
||||
channelName = args[0];
|
||||
if (args.length >= 2) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
message.append(args[i] + " ");
|
||||
}
|
||||
}
|
||||
} else if (args.length >= 2) {
|
||||
channelName = args[1];
|
||||
if (args.length >= 3) {
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
message.append(args[i] + " ");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルを取得する
|
||||
Channel channel = api.getChannel(channelName);
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
if ( channel == null ) {
|
||||
if ( config.getGlobalChannel().equals("") &&
|
||||
channelName.equals(config.getGlobalMarker()) ) {
|
||||
// グローバルチャンネル設定が無くて、指定チャンネルがマーカーの場合、
|
||||
// 発言先を削除して、グローバルチャンネルにする
|
||||
|
||||
api.removeDefaultChannel(sender.getName());
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgSet", "グローバル");
|
||||
|
||||
// TODO
|
||||
// Player p = null;
|
||||
// if ( sender instanceof ChannelMemberBukkit ) p = ((ChannelMemberBukkit)sender).getPlayer();
|
||||
//
|
||||
// if ( message.length() > 0 && p != null ) {
|
||||
// p.chat(config.getGlobalMarker() + message.toString());
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
if (config.isCreateChannelOnJoinCommand()) {
|
||||
// 存在しないチャットには、チャンネルを作って入る設定の場合
|
||||
|
||||
// 使用可能なチャンネル名かどうかをチェックする
|
||||
if ( !channelName.matches("[0-9a-zA-Z\\-_]+") ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgCannotUseForChannel", channelName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 最低文字列長を上回っているかをチェックする
|
||||
if ( channelName.length() < config.getMinChannelNameLength() ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgCannotUseForChannelTooShort",
|
||||
channelName, config.getMinChannelNameLength());
|
||||
return true;
|
||||
}
|
||||
|
||||
// 最大文字列長を下回っているかをチェックする
|
||||
if ( channelName.length() > config.getMaxChannelNameLength() ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgCannotUseForChannelTooLong",
|
||||
channelName, config.getMaxChannelNameLength());
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネル作成
|
||||
Channel c = api.createChannel(channelName);
|
||||
if ( c != null ) {
|
||||
c.addMember(sender);
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgCreate", channelName);
|
||||
}
|
||||
return true;
|
||||
|
||||
} else {
|
||||
// 存在しないチャットには入れない設定の場合
|
||||
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExist");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
channelName = channel.getName();
|
||||
|
||||
// 入室権限を確認する
|
||||
String node = PERMISSION_NODE + "." + channelName;
|
||||
if (sender.isPermissionSet(node) && !sender.hasPermission(node)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgPermission",
|
||||
PERMISSION_NODE + "." + channelName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// BANされていないか確認する
|
||||
if (channel.getBanned().contains(sender)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgBanned");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 個人チャットの場合はエラーにする
|
||||
if (channel.isPersonalChat()) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCannotJoinPersonal");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (channel.getMembers().contains(sender)) {
|
||||
|
||||
// 何かメッセージがあるなら、そのままチャット送信する
|
||||
if (message.length() > 0 && hasSpeakPermission(sender, channelName)) {
|
||||
channel.chat(sender, message.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
// デフォルトの発言先に設定する
|
||||
api.setDefaultChannel(sender.getName(), channelName);
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgSet", channelName);
|
||||
|
||||
} else {
|
||||
|
||||
// グローバルチャンネルで、何かメッセージがあるなら、そのままチャット送信する
|
||||
if (channel.getName().equals(config.getGlobalChannel()) &&
|
||||
message.length() > 0 && hasSpeakPermission(sender, channelName)) {
|
||||
channel.chat(sender, message.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
// パスワードが設定されている場合は、パスワードを確認する
|
||||
if ( !channel.getPassword().equals("") ) {
|
||||
if ( message.toString().trim().equals("") ) {
|
||||
// パスワード空欄
|
||||
sendResourceMessage(sender, PREERR, "errmsgPassword1");
|
||||
sendResourceMessage(sender, PREERR, "errmsgPassword2");
|
||||
sendResourceMessage(sender, PREERR, "errmsgPassword3");
|
||||
return true;
|
||||
} else if ( !channel.getPassword().equals(message.toString().trim()) ) {
|
||||
// パスワード不一致
|
||||
sendResourceMessage(sender, PREERR, "errmsgPasswordNotmatch");
|
||||
sendResourceMessage(sender, PREERR, "errmsgPassword2");
|
||||
sendResourceMessage(sender, PREERR, "errmsgPassword3");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// チャンネルに参加し、デフォルトの発言先に設定する
|
||||
if ( !channel.getName().equals(config.getGlobalChannel()) ) {
|
||||
channel.addMember(sender);
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgJoin", channelName);
|
||||
}
|
||||
api.setDefaultChannel(sender.getName(), channelName);
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgSet", channelName);
|
||||
}
|
||||
|
||||
// チャンネル説明文があるなら、説明文を表示する
|
||||
if ( !channel.getDescription().trim().equals("") ) {
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgSetTopic", channel.getDescription().trim());
|
||||
}
|
||||
|
||||
// 非表示に設定しているなら、注意を流す
|
||||
if ( channel.getHided().contains(sender) ) {
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgSetHide");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasSpeakPermission(ChannelMember sender, String channelName) {
|
||||
String node = PERMISSION_SPEAK_PREFIX + "." + channelName;
|
||||
return sender.isPermissionSet(node) && sender.hasPermission(node);
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* kickコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class KickCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "kick";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageKick";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.MODERATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 実行引数から、キックするユーザーを取得する
|
||||
String kickedName = "";
|
||||
if (args.length >= 2) {
|
||||
kickedName = args[1];
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 対象チャンネルを取得、取得できない場合はエラー表示して終了する
|
||||
Channel channel = null;
|
||||
if (args.length >= 3) {
|
||||
channel = api.getChannel(args[2]);
|
||||
} else if (sender instanceof Player) {
|
||||
Player kicker = (Player) sender;
|
||||
channel = api.getDefaultChannel(kicker.getName());
|
||||
}
|
||||
if (channel == null) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNoJoin");
|
||||
return true;
|
||||
}
|
||||
|
||||
// モデレーターかどうか確認する
|
||||
if ( !channel.hasModeratorPermission(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
|
||||
return true;
|
||||
}
|
||||
|
||||
// グローバルチャンネルならキックできない
|
||||
if ( channel.isGlobalChannel() ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgCannotKickGlobal", channel.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
// キックされるプレイヤーがメンバーかどうかチェックする
|
||||
ChannelMember kicked = ChannelMember.getChannelMember(kickedName);
|
||||
if (!channel.getMembers().contains(kicked)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNomemberOther");
|
||||
return true;
|
||||
}
|
||||
|
||||
// キック実行
|
||||
channel.removeMember(kicked);
|
||||
channel.save();
|
||||
|
||||
// senderに通知メッセージを出す
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgKick", kickedName, channel.getName());
|
||||
|
||||
// チャンネルに通知メッセージを出す
|
||||
sendResourceMessageWithKeyword(channel, "kickMessage", kicked);
|
||||
|
||||
// キックされた人に通知メッセージを出す
|
||||
if ( kicked != null && kicked.isOnline() ) {
|
||||
sendResourceMessage(kicked, PREINFO,
|
||||
"cmdmsgKicked", channel.getName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* leaveコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LeaveCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "leave";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageLeave";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 実行引数から退出するチャンネルを取得する
|
||||
// 指定が無いならデフォルトの発言先にする
|
||||
Channel def = api.getDefaultChannel(sender.getName());
|
||||
String channelName = null;
|
||||
if ( def != null ) {
|
||||
channelName = def.getName();
|
||||
}
|
||||
if (args.length >= 2) {
|
||||
channelName = args[1];
|
||||
}
|
||||
|
||||
Channel channel = api.getChannel(channelName);
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
if ( channel == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExist");
|
||||
return true;
|
||||
}
|
||||
|
||||
channelName = channel.getName();
|
||||
|
||||
// 退室権限を確認する
|
||||
String node = PERMISSION_NODE + "." + channelName;
|
||||
if (sender.isPermissionSet(node) && !sender.hasPermission(node)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgPermission",
|
||||
PERMISSION_NODE + "." + channelName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// グローバルチャンネルなら退出できない
|
||||
if ( channel.isGlobalChannel() ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCannotLeaveGlobal", channelName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 強制参加チャンネルなら退出できない
|
||||
if ( channel.isForceJoinChannel() ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCannotLeaveForceJoin", channelName);
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルのメンバーかどうかを確認する
|
||||
if (!channel.getMembers().contains(sender)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNomember");
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルから退出する
|
||||
channel.removeMember(sender);
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgLeave", channelName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.github.ucchyocean.lc.Messages;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* listコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ListCommand extends SubCommandAbst {
|
||||
|
||||
private static final String LIST_FIRSTLINE = Messages.get("listFirstLine");
|
||||
private static final String LIST_FIRSTLINE_PAGING = Messages.get("listFirstLinePaging");
|
||||
private static final String LIST_ENDLINE = Messages.get("listEndLine");
|
||||
private static final String LIST_FORMAT = Messages.get("listFormat");
|
||||
|
||||
private static final String COMMAND_NAME = "list";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageList";
|
||||
|
||||
private static final int PAGE_SIZE = 8;
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
int page = 0;
|
||||
if ( args.length >= 2 && args[1].matches("[0-9]") ) {
|
||||
page = Integer.parseInt(args[1]);
|
||||
}
|
||||
|
||||
// リストを取得して表示する
|
||||
ArrayList<String> list = getList(sender, page);
|
||||
for (String msg : list) {
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* リスト表示用のリストを返す
|
||||
* @param player プレイヤー、指定しない場合はnullにする
|
||||
* @param page 表示するページ、0を指定した場合は全表示
|
||||
* @return リスト
|
||||
*/
|
||||
private ArrayList<String> getList(ChannelMember player, int page) {
|
||||
|
||||
ArrayList<String> list = getPlayerList(player);
|
||||
int size = list.size();
|
||||
int maxPage = (int)(size / PAGE_SIZE) + 1;
|
||||
|
||||
if ( page < 0 ) page = 0;
|
||||
if ( page > maxPage ) page = maxPage;
|
||||
|
||||
ArrayList<String> items = new ArrayList<>();
|
||||
if ( page == 0 ) { // 全表示
|
||||
items.add(LIST_FIRSTLINE);
|
||||
items.addAll(list);
|
||||
items.add(LIST_ENDLINE);
|
||||
} else { // ページ表示
|
||||
items.add(String.format(LIST_FIRSTLINE_PAGING, page, maxPage));
|
||||
int endIndex = (page * PAGE_SIZE > size) ? size : page * PAGE_SIZE;
|
||||
items.addAll(list.subList((page - 1) * PAGE_SIZE, endIndex));
|
||||
items.add(LIST_ENDLINE);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたプレイヤーに対するチャンネルリストを返す
|
||||
* @param player プレイヤー
|
||||
* @return チャンネルリスト
|
||||
*/
|
||||
private ArrayList<String> getPlayerList(ChannelMember player) {
|
||||
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
String dchannel = "";
|
||||
String playerName = "";
|
||||
if ( player != null ) {
|
||||
playerName = player.getName();
|
||||
Channel def = api.getDefaultChannel(playerName);
|
||||
if ( def == null ) {
|
||||
dchannel = "";
|
||||
} else {
|
||||
dchannel = def.getName();
|
||||
}
|
||||
}
|
||||
|
||||
// チャンネルを取得して、チャンネル名でソートする
|
||||
ArrayList<Channel> channels = new ArrayList<>(api.getChannels());
|
||||
Collections.sort(channels, new Comparator<Channel>() {
|
||||
public int compare(Channel c1, Channel c2) {
|
||||
return c1.getName().compareTo(c2.getName());
|
||||
}
|
||||
});
|
||||
|
||||
// 指定されたプレイヤー名に合うように、フィルタ&表示用整形する。
|
||||
for ( Channel channel : channels ) {
|
||||
|
||||
// BANされているチャンネルは表示しない
|
||||
if ( channel.getBanned().contains(player) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 個人チャットはリストに表示しない
|
||||
if ( channel.isPersonalChat() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// デフォルト発言先なら赤に、非表示中なら暗青にする。
|
||||
String disp = ChatColor.WHITE + channel.getName();
|
||||
if ( channel.getName().equalsIgnoreCase(dchannel) ) {
|
||||
disp = ChatColor.RED + channel.getName();
|
||||
} else if ( channel.getHided().contains(player) ) {
|
||||
disp = ChatColor.DARK_AQUA + channel.getName();
|
||||
}
|
||||
|
||||
if ( !channel.getMembers().contains(player) &&
|
||||
!channel.isGlobalChannel() ) {
|
||||
|
||||
// 未参加で visible=false のチャンネルは表示しない
|
||||
if ( !channel.isVisible() ) {
|
||||
continue;
|
||||
}
|
||||
disp = ChatColor.GRAY + channel.getName();
|
||||
}
|
||||
String desc = channel.getDescription();
|
||||
int onlineNum = channel.getOnlineNum();
|
||||
int memberNum = channel.getTotalNum();
|
||||
String item = String.format(
|
||||
LIST_FORMAT, disp, onlineNum, memberNum, desc);
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChatLogger;
|
||||
import com.github.ucchyocean.lc.Messages;
|
||||
import com.github.ucchyocean.lc.bukkit.LunaChatBukkit;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* logコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LogCommand extends SubCommandAbst {
|
||||
|
||||
private static final String LOGDISPLAY_FIRSTLINE = Messages.get("logDisplayFirstLine");
|
||||
private static final String LOGDISPLAY_ENDLINE = Messages.get("logDisplayEndLine");
|
||||
private static final String LOGDISPLAY_FORMAT = Messages.get("logDisplayFormat");
|
||||
|
||||
private static final String COMMAND_NAME = "log";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageLog";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
String cname = null;
|
||||
String argsPlayer = null;
|
||||
String argsFilter = null;
|
||||
String argsDate = null;
|
||||
boolean reverse = false;
|
||||
|
||||
int index = 1;
|
||||
if ( args.length >= 2 && !args[1].contains("=")) {
|
||||
cname = args[1];
|
||||
index = 2;
|
||||
}
|
||||
|
||||
for ( int i=index; i<args.length; i++ ) {
|
||||
String arg = args[i];
|
||||
if ( arg.startsWith("p=") ) {
|
||||
argsPlayer = arg.substring(2);
|
||||
} else if ( arg.startsWith("f=") ) {
|
||||
argsFilter = arg.substring(2);
|
||||
} else if ( arg.startsWith("d=") ) {
|
||||
argsDate = arg.substring(2);
|
||||
} else if ( arg.equals("r=") ) {
|
||||
reverse = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( sender != null && cname == null ) {
|
||||
Channel def = api.getDefaultChannel(sender.getName());
|
||||
if ( def != null ) {
|
||||
cname = def.getName();
|
||||
}
|
||||
}
|
||||
|
||||
// 参照権限を確認する
|
||||
String node = PERMISSION_NODE + "." + cname;
|
||||
if (sender.isPermissionSet(node) && !sender.hasPermission(node)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgPermission",
|
||||
PERMISSION_NODE + "." + cname);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ログの取得
|
||||
ArrayList<String> logs;
|
||||
|
||||
if ( config.getGlobalChannel().equals("") &&
|
||||
(cname == null || cname.equals(config.getGlobalMarker())) ) {
|
||||
|
||||
// グローバルチャンネル設定が無くて、指定チャンネルがマーカーの場合、
|
||||
// 通常チャットのログを取得する
|
||||
LunaChatLogger logger = LunaChatBukkit.getInstance().getNormalChatLogger();
|
||||
logs = logger.getLog(argsPlayer, argsFilter, argsDate, reverse);
|
||||
|
||||
cname = "グローバルチャット";
|
||||
|
||||
} else {
|
||||
|
||||
// チャンネルが存在するかどうか確認する
|
||||
Channel channel = api.getChannel(cname);
|
||||
if ( channel == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExist");
|
||||
return true;
|
||||
}
|
||||
|
||||
// BANされていないかどうか確認する
|
||||
ChannelMember cp = ChannelMember.getChannelMember(sender);
|
||||
if ( sender != null && channel.getBanned().contains(cp) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgBanned");
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルのメンバーかどうかを確認する
|
||||
if (!channel.getMembers().contains(cp)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNomember");
|
||||
return true;
|
||||
}
|
||||
|
||||
logs = channel.getLog(argsPlayer, argsFilter, argsDate, reverse);
|
||||
}
|
||||
|
||||
// 整形と表示
|
||||
sender.sendMessage(String.format(LOGDISPLAY_FIRSTLINE, cname));
|
||||
|
||||
for ( String log : logs ) {
|
||||
|
||||
String[] temp = log.split(",");
|
||||
String date = temp[0];
|
||||
String message = temp[1];
|
||||
String playerName = "";
|
||||
if ( temp.length >= 3 ) {
|
||||
playerName = temp[2];
|
||||
}
|
||||
sender.sendMessage(String.format(
|
||||
LOGDISPLAY_FORMAT, date, playerName, message));
|
||||
}
|
||||
|
||||
sender.sendMessage(LOGDISPLAY_ENDLINE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,399 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.Messages;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* Lunachatコマンドの処理クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public abstract class LunaChatCommand {
|
||||
|
||||
private static final String PREERR = Messages.get("errorPrefix");
|
||||
|
||||
private ArrayList<SubCommandAbst> commands;
|
||||
private ArrayList<SubCommandAbst> commonCommands;
|
||||
private JoinCommand joinCommand;
|
||||
private HelpCommand helpCommand;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
*/
|
||||
public LunaChatCommand() {
|
||||
|
||||
commands = new ArrayList<SubCommandAbst>();
|
||||
joinCommand = new JoinCommand();
|
||||
commands.add(joinCommand);
|
||||
commands.add(new LeaveCommand());
|
||||
commands.add(new ListCommand());
|
||||
commands.add(new InviteCommand());
|
||||
commands.add(new AcceptCommand());
|
||||
commands.add(new DenyCommand());
|
||||
commands.add(new KickCommand());
|
||||
commands.add(new BanCommand());
|
||||
commands.add(new PardonCommand());
|
||||
commands.add(new MuteCommand());
|
||||
commands.add(new UnmuteCommand());
|
||||
commands.add(new InfoCommand());
|
||||
commands.add(new LogCommand());
|
||||
commands.add(new CreateCommand());
|
||||
commands.add(new RemoveCommand());
|
||||
commands.add(new FormatCommand());
|
||||
commands.add(new ModeratorCommand());
|
||||
commands.add(new ModCommand());
|
||||
commands.add(new OptionCommand());
|
||||
commands.add(new TemplateCommand());
|
||||
commands.add(new SetCommand());
|
||||
helpCommand = new HelpCommand(commands);
|
||||
commands.add(helpCommand);
|
||||
|
||||
commonCommands = new ArrayList<SubCommandAbst>();
|
||||
commonCommands.add(new HideCommand());
|
||||
commonCommands.add(new UnhideCommand());
|
||||
commonCommands.add(new DictionaryCommand());
|
||||
commonCommands.add(new DicCommand());
|
||||
commonCommands.add(new ReloadCommand());
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドを実行したときに呼び出されるメソッド
|
||||
* @param sender 実行者
|
||||
* @param label 実行されたコマンドのラベル
|
||||
* @param args 実行されたコマンドの引数
|
||||
* @return 実行したかどうか(falseを返した場合、サーバーがUsageを表示する)
|
||||
*/
|
||||
protected boolean execute(ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// チャンネルチャットが無効でも利用できるコマンドはここで処理する
|
||||
// (hide, unhide, dic, dictionary, reload)
|
||||
if ( args.length >= 1 ) {
|
||||
for ( SubCommandAbst c : commonCommands ) {
|
||||
if ( c.getCommandName().equalsIgnoreCase(args[0]) ) {
|
||||
|
||||
// パーミッションの確認
|
||||
String node = c.getPermissionNode();
|
||||
if ( !sender.hasPermission(node) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgPermission", node);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 実行
|
||||
return c.runCommand(sender, label, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// チャンネルチャット機能が無効になっている場合は、メッセージを表示して終了
|
||||
if ( !LunaChat.getConfig().isEnableChannelChat()
|
||||
&& !sender.hasPermission("lunachat-admin") ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgChannelChatDisabled");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 引数なしは、ヘルプを表示
|
||||
if (args.length == 0) {
|
||||
helpCommand.runCommand(sender, label, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 第1引数に指定されたコマンドを実行する
|
||||
for ( SubCommandAbst c : commands ) {
|
||||
if ( c.getCommandName().equalsIgnoreCase(args[0]) ) {
|
||||
|
||||
// パーミッションの確認
|
||||
String node = c.getPermissionNode();
|
||||
if ( !sender.hasPermission(node) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgPermission", node);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 実行
|
||||
return c.runCommand(sender, label, args);
|
||||
}
|
||||
}
|
||||
|
||||
// 第1引数がコマンドでないなら、joinが指定されたとみなす
|
||||
String node = joinCommand.getPermissionNode();
|
||||
if ( !sender.hasPermission(node) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgPermission", node);
|
||||
return true;
|
||||
}
|
||||
|
||||
return joinCommand.runCommand(sender, label, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* TABキー補完が実行されたときに呼び出されるメソッド
|
||||
* @param sender TABキー補完の実行者
|
||||
* @param label 実行されたコマンドのラベル
|
||||
* @param args 実行されたコマンドの引数
|
||||
* @return 補完候補
|
||||
*/
|
||||
protected List<String> onTabComplete(ChannelMember sender, String label, String[] args) {
|
||||
if ( args.length == 1 ) {
|
||||
// コマンド名で補完する
|
||||
String arg = args[0].toLowerCase();
|
||||
ArrayList<String> coms = new ArrayList<String>();
|
||||
for ( SubCommandAbst c : commands ) {
|
||||
if ( c.getCommandName().startsWith(arg) &&
|
||||
sender.hasPermission(c.getPermissionNode()) ) {
|
||||
coms.add(c.getCommandName());
|
||||
}
|
||||
}
|
||||
for ( SubCommandAbst c : commonCommands ) {
|
||||
if ( c.getCommandName().startsWith(arg) &&
|
||||
sender.hasPermission(c.getPermissionNode()) ) {
|
||||
coms.add(c.getCommandName());
|
||||
}
|
||||
}
|
||||
return coms;
|
||||
|
||||
} else if ( args.length == 2 && (
|
||||
args[0].equalsIgnoreCase("join") ||
|
||||
args[0].equalsIgnoreCase("info") ) ) {
|
||||
// 参加可能チャンネル名で補完する
|
||||
String arg = args[1].toLowerCase();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
for ( String name : getListCanJoin(sender) ) {
|
||||
if ( name.toLowerCase().startsWith(arg) ) {
|
||||
items.add(name);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
|
||||
} else if ( args.length == 2 && (
|
||||
args[0].equalsIgnoreCase("ban") ||
|
||||
args[0].equalsIgnoreCase("pardon") ||
|
||||
args[0].equalsIgnoreCase("kick") ||
|
||||
args[0].equalsIgnoreCase("mute") ||
|
||||
args[0].equalsIgnoreCase("unmute") ) ) {
|
||||
// プレイヤー名で補完する
|
||||
String arg = args[1].toLowerCase();
|
||||
return getListPlayerNames(arg);
|
||||
|
||||
} else if ( args.length == 3 && (
|
||||
args[0].equalsIgnoreCase("ban") ||
|
||||
args[0].equalsIgnoreCase("pardon") ||
|
||||
args[0].equalsIgnoreCase("kick") ||
|
||||
args[0].equalsIgnoreCase("mute") ||
|
||||
args[0].equalsIgnoreCase("unmute") ) ) {
|
||||
// チャンネル名で補完する
|
||||
String arg = args[2].toLowerCase();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
for ( String name : getListCanJoin(sender) ) {
|
||||
if ( name.toLowerCase().startsWith(arg) ) {
|
||||
items.add(name);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
|
||||
} else if ( args.length == 2 && (
|
||||
args[0].equalsIgnoreCase("hide") ||
|
||||
args[0].equalsIgnoreCase("unhide") ) ) {
|
||||
|
||||
// 参加可能チャンネル名とプレイヤー名と
|
||||
// 文字列"player", "channel"で補完する
|
||||
String arg = args[1].toLowerCase();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
for ( String name : getListCanJoin(sender) ) {
|
||||
if ( name.toLowerCase().startsWith(arg) ) {
|
||||
items.add(name);
|
||||
}
|
||||
}
|
||||
items.addAll(getListPlayerNames(arg));
|
||||
if ( "player".startsWith(arg) ) {
|
||||
items.add("player");
|
||||
}
|
||||
if ( "channel".startsWith(arg) ) {
|
||||
items.add("channel");
|
||||
}
|
||||
return items;
|
||||
|
||||
} else if ( args.length == 3 &&
|
||||
(args[0].equalsIgnoreCase("hide") ||
|
||||
args[0].equalsIgnoreCase("unhide") ) &&
|
||||
args[1].equalsIgnoreCase("player") ) {
|
||||
|
||||
// プレイヤー名で補完する
|
||||
String arg = args[2].toLowerCase();
|
||||
return getListPlayerNames(arg);
|
||||
|
||||
} else if ( args.length == 3 &&
|
||||
(args[0].equalsIgnoreCase("hide") ||
|
||||
args[0].equalsIgnoreCase("unhide") ) &&
|
||||
args[1].equalsIgnoreCase("channel") ) {
|
||||
|
||||
// チャンネル名で補完する
|
||||
String arg = args[2].toLowerCase();
|
||||
return getListPlayerNames(arg);
|
||||
|
||||
} else if ( args.length == 2 && args[0].equalsIgnoreCase("remove") ) {
|
||||
// 削除可能チャンネル名で補完する
|
||||
String arg = args[1].toLowerCase();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
for ( String name : getListCanRemove(sender) ) {
|
||||
if ( name.toLowerCase().startsWith(arg) ) {
|
||||
items.add(name);
|
||||
}
|
||||
}
|
||||
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.getAPI().getAllDictionary().keySet() ) {
|
||||
if ( name.toLowerCase().startsWith(arg) ) {
|
||||
items.add(name);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
|
||||
} else if ( args.length == 2 &&
|
||||
args[0].equalsIgnoreCase("set") ) {
|
||||
// "default" で補完する
|
||||
String arg = args[1].toLowerCase();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
if ( "default".startsWith(arg) ) {
|
||||
items.add("default");
|
||||
}
|
||||
return items;
|
||||
|
||||
} else if ( args.length == 3 &&
|
||||
args[0].equalsIgnoreCase("set") && args[1].equalsIgnoreCase("default") ) {
|
||||
// プレイヤー名で補完する
|
||||
String arg = args[2].toLowerCase();
|
||||
return getListPlayerNames(arg);
|
||||
|
||||
} else if ( args.length == 4 &&
|
||||
args[0].equalsIgnoreCase("set") && args[1].equalsIgnoreCase("default") ) {
|
||||
// チャンネル名で補完する
|
||||
String arg = args[3].toLowerCase();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
for ( String name : getListCanJoin(sender) ) {
|
||||
if ( name.toLowerCase().startsWith(arg) ) {
|
||||
items.add(name);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージリソースのメッセージを、カラーコード置き換えしつつ、senderに送信する
|
||||
*
|
||||
* @param sender メッセージの送り先
|
||||
* @param pre プレフィックス
|
||||
* @param key リソースキー
|
||||
* @param args リソース内の置き換え対象キーワード
|
||||
*/
|
||||
private void sendResourceMessage(ChannelMember sender, String pre,
|
||||
String key, Object... args) {
|
||||
|
||||
String org = Messages.get(key);
|
||||
if ( org == null || org.equals("") ) {
|
||||
return;
|
||||
}
|
||||
String msg = String.format(pre + org, args);
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* TAB補完用の参加可能チャンネルリストを返す
|
||||
* @param sender コマンド実行者
|
||||
* @return リスト
|
||||
*/
|
||||
protected ArrayList<String> getListCanJoin(ChannelMember sender) {
|
||||
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
|
||||
for ( Channel channel : LunaChat.getAPI().getChannels() ) {
|
||||
|
||||
// BANされているチャンネルは対象外
|
||||
if ( channel.getBanned().contains(sender) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 個人チャットは対象外
|
||||
if ( channel.isPersonalChat() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 未参加で visible=false のチャンネルは対象外
|
||||
if ( !channel.getMembers().contains(sender) &&
|
||||
!channel.isGlobalChannel() && !channel.isVisible() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
items.add(channel.getName());
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* TAB補完用の削除可能チャンネルリストを返す
|
||||
* @param sender コマンド実行者
|
||||
* @return リスト
|
||||
*/
|
||||
protected ArrayList<String> getListCanRemove(ChannelMember sender) {
|
||||
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
|
||||
for ( Channel channel : LunaChat.getAPI().getChannels() ) {
|
||||
|
||||
// 実行者がチャンネルモデレーターでない場合は対象外
|
||||
if ( !channel.hasModeratorPermission(sender) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 個人チャットは対象外
|
||||
if ( channel.isPersonalChat() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// グローバルチャンネルは対象外
|
||||
if ( channel.isGlobalChannel() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
items.add(channel.getName());
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* オンラインプレイヤーのうち、プレイヤー名が指定された文字列と前方一致するものをリストにして返す
|
||||
* @param pre 検索キー
|
||||
* @return プレイヤー名リスト
|
||||
*/
|
||||
protected abstract List<String> getListPlayerNames(String pre);
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* Lunachatコマンドの処理クラス(Bukkit実装)
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatCommandBukkit extends LunaChatCommand implements CommandExecutor {
|
||||
|
||||
/**
|
||||
* コマンドを実行したときに呼び出されるメソッド
|
||||
* @param sender 実行者
|
||||
* @param command 実行されたコマンド
|
||||
* @param label 実行されたコマンドのラベル
|
||||
* @param args 実行されたコマンドの引数
|
||||
* @return 実行したかどうか(falseを返した場合、サーバーがUsageを表示する)
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
return execute(ChannelMember.getChannelMember(sender), label, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* TABキー補完が実行されたときに呼び出されるメソッド
|
||||
* @param sender TABキー補完の実行者
|
||||
* @param command 実行されたコマンド
|
||||
* @param label 実行されたコマンドのラベル
|
||||
* @param args 実行されたコマンドの引数
|
||||
* @return 補完候補
|
||||
*/
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
return onTabComplete(ChannelMember.getChannelMember(sender), label, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* オンラインプレイヤーのうち、プレイヤー名が指定された文字列と前方一致するものをリストにして返す
|
||||
* @param pre 検索キー
|
||||
* @return プレイヤー名リスト
|
||||
* @see com.github.ucchyocean.lc.command.LunaChatCommand#getListPlayerNames(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected List<String> getListPlayerNames(String pre) {
|
||||
|
||||
List<String> items = new ArrayList<String>();
|
||||
for ( Player player : Bukkit.getOnlinePlayers() ) {
|
||||
String pname = player.getName();
|
||||
if ( pname == null ) continue;
|
||||
if ( pname.toLowerCase().startsWith(pre) ) {
|
||||
items.add(player.getName());
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
/**
|
||||
* Lunachatコマンドの処理クラス(Bungee実装)
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatCommandBungee extends LunaChatCommand {
|
||||
|
||||
/**
|
||||
* コマンドを実行したときに呼び出されるメソッド
|
||||
* @param sender 実行者
|
||||
* @param args 実行されたコマンドの引数
|
||||
* @see net.md_5.bungee.api.plugin.Command#execute(net.md_5.bungee.api.CommandSender, java.lang.String[])
|
||||
*/
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
String label = args.length >= 1 ? args[0] : "lunachat";
|
||||
execute(ChannelMember.getChannelMember(sender), label, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* TABキー補完が実行されたときに呼び出されるメソッド
|
||||
* @param sender 実行者
|
||||
* @param args 実行されたコマンドの引数
|
||||
* @return 補完候補
|
||||
* @see net.md_5.bungee.api.plugin.TabExecutor#onTabComplete(net.md_5.bungee.api.CommandSender, java.lang.String[])
|
||||
*/
|
||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
return onTabComplete(ChannelMember.getChannelMember(sender), "", args);
|
||||
}
|
||||
|
||||
/**
|
||||
* オンラインプレイヤーのうち、プレイヤー名が指定された文字列と前方一致するものをリストにして返す
|
||||
* @param pre 検索キー
|
||||
* @return プレイヤー名リスト
|
||||
* @see com.github.ucchyocean.lc.command.LunaChatCommand#getListPlayerNames(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected List<String> getListPlayerNames(String pre) {
|
||||
|
||||
List<String> items = new ArrayList<String>();
|
||||
for ( ProxiedPlayer player : ProxyServer.getInstance().getPlayers() ) {
|
||||
String pname = player.getName();
|
||||
if ( pname == null ) continue;
|
||||
if ( pname.toLowerCase().startsWith(pre) ) {
|
||||
items.add(player.getName());
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc.Messages;
|
||||
import com.github.ucchyocean.lc.bukkit.LunaChatBukkit;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* Japanize変換設定コマンド
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatJapanizeCommand implements CommandExecutor {
|
||||
|
||||
private static final String PERM_JAPANIZE_OTHER = "lunachat-admin.japanize-other";
|
||||
|
||||
private static final String PREINFO = Messages.get("infoPrefix");
|
||||
private static final String PREERR = Messages.get("errorPrefix");
|
||||
|
||||
/**
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command,
|
||||
String label, String[] args) {
|
||||
|
||||
if ( args.length == 1 &&
|
||||
(args[0].equalsIgnoreCase("on") || args[0].equalsIgnoreCase("off")) ) {
|
||||
// japanize on/off の実行
|
||||
|
||||
// プレイヤーでなければ終了する
|
||||
if (!(sender instanceof Player)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgIngame");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
|
||||
// Japanize設定をon/offにする
|
||||
boolean value = args[0].equalsIgnoreCase("on");
|
||||
LunaChatAPI api = LunaChatBukkit.getInstance().getLunaChatAPI();
|
||||
api.setPlayersJapanize(player.getName(), value);
|
||||
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgPlayerJapanize", args[0]);
|
||||
return true;
|
||||
|
||||
} else if ( args.length == 2 &&
|
||||
(args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("off")) ) {
|
||||
// japanize (player) on/off の実行
|
||||
|
||||
// 権限チェック
|
||||
if ( !sender.hasPermission(PERM_JAPANIZE_OTHER) ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotPermission", PERM_JAPANIZE_OTHER);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 指定されたプレイヤーが存在するかチェック
|
||||
ChannelMember target = ChannelMember.getChannelMember(args[0]);
|
||||
if ( target == null || !target.isOnline() ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotfoundPlayer", args[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Japanize設定をon/offにする
|
||||
boolean value = args[1].equalsIgnoreCase("on");
|
||||
LunaChatAPI api = LunaChatBukkit.getInstance().getLunaChatAPI();
|
||||
api.setPlayersJapanize(target.getName(), value);
|
||||
|
||||
sendResourceMessage(target, PREINFO,
|
||||
"cmdmsgPlayerJapanize", args[1]);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgPlayerJapanizeOther", args[0], args[1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
// usageを表示して終了する
|
||||
printUsage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドの使い方を senderに送る
|
||||
* @param sender
|
||||
* @param label
|
||||
*/
|
||||
private void printUsage(CommandSender sender, String label) {
|
||||
sendResourceMessage(sender, "", "usageJapanize", label);
|
||||
if ( sender.hasPermission(PERM_JAPANIZE_OTHER) ) {
|
||||
sendResourceMessage(sender, "", "usageJapanizeOther", label);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージリソースのメッセージを、カラーコード置き換えしつつ、senderに送信する
|
||||
* @param sender メッセージの送り先
|
||||
* @param pre プレフィックス
|
||||
* @param key リソースキー
|
||||
* @param args リソース内の置き換え対象キーワード
|
||||
*/
|
||||
protected void sendResourceMessage(CommandSender sender, String pre,
|
||||
String key, Object... args) {
|
||||
|
||||
String org = Messages.get(key);
|
||||
if ( org == null || org.equals("") ) {
|
||||
return;
|
||||
}
|
||||
String msg = String.format(pre + org, args);
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージリソースのメッセージを、カラーコード置き換えしつつ、senderに送信する
|
||||
* @param cp メッセージの送り先
|
||||
* @param pre プレフィックス
|
||||
* @param key リソースキー
|
||||
* @param args リソース内の置き換え対象キーワード
|
||||
*/
|
||||
protected void sendResourceMessage(ChannelMember cp, String pre,
|
||||
String key, Object... args) {
|
||||
|
||||
String org = Messages.get(key);
|
||||
if ( org == null || org.equals("") ) {
|
||||
return;
|
||||
}
|
||||
String msg = String.format(pre + org, args);
|
||||
cp.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc.Messages;
|
||||
import com.github.ucchyocean.lc.bukkit.LunaChatBukkit;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* 1:1チャット送信コマンド
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatMessageCommand implements CommandExecutor {
|
||||
|
||||
private static final String PREERR = Messages.get("errorPrefix");
|
||||
|
||||
/**
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command,
|
||||
String label, String[] args) {
|
||||
|
||||
// senderからChannelMemberを作成する
|
||||
ChannelMember inviter = ChannelMember.getChannelMember(sender);
|
||||
|
||||
// 引数が無ければ、usageを表示して終了する
|
||||
if (args.length == 0) {
|
||||
printUsage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 実行引数から1:1チャットの相手を取得する
|
||||
String invitedName = "";
|
||||
StringBuilder message = new StringBuilder();
|
||||
if (args.length >= 1) {
|
||||
invitedName = args[0];
|
||||
if ( args.length >= 2 ) {
|
||||
for ( int i=1; i<args.length; i++ ) {
|
||||
message.append(args[i] + " ");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
printUsage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
// メッセージを送信する
|
||||
sendTellMessage(inviter, invitedName, message.toString().trim());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tellコマンドの実行処理を行う
|
||||
* @param inviter
|
||||
* @param invitedName
|
||||
* @param message
|
||||
*/
|
||||
protected void sendTellMessage(ChannelMember inviter, String invitedName, String message) {
|
||||
|
||||
// 招待相手が存在するかどうかを確認する
|
||||
ChannelMember invited = ChannelMember.getChannelMember(invitedName);
|
||||
if ( invited == null || !invited.isOnline() ) {
|
||||
sendResourceMessage(inviter, PREERR,
|
||||
"errmsgNotfoundPlayer", invitedName);
|
||||
return;
|
||||
}
|
||||
|
||||
// 招待相手が自分自身でないか確認する
|
||||
if (inviter.getName().equals(invited.getName())) {
|
||||
sendResourceMessage(inviter, PREERR,
|
||||
"errmsgCannotSendPMSelf");
|
||||
return;
|
||||
}
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
LunaChatAPI api = LunaChatBukkit.getInstance().getLunaChatAPI();
|
||||
String cname = inviter.getName() + ">" + invited.getName();
|
||||
Channel channel = api.getChannel(cname);
|
||||
if ( channel == null ) {
|
||||
// チャンネルを作成して、送信者、受信者をメンバーにする
|
||||
channel = api.createChannel(cname);
|
||||
channel.setVisible(false);
|
||||
channel.addMember(inviter);
|
||||
channel.addMember(invited);
|
||||
channel.setPrivateMessageTo(invited.getName());
|
||||
}
|
||||
|
||||
// メッセージがあるなら送信する
|
||||
if ( message.trim().length() > 0 ) {
|
||||
channel.chat(inviter, message);
|
||||
}
|
||||
|
||||
// 送信履歴を残す
|
||||
DataMaps.privateMessageMap.put(
|
||||
invited.getName(), inviter.getName());
|
||||
DataMaps.privateMessageMap.put(
|
||||
inviter.getName(), invited.getName());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドの使い方を senderに送る
|
||||
* @param sender
|
||||
* @param label
|
||||
*/
|
||||
private void printUsage(CommandSender sender, String label) {
|
||||
sendResourceMessage(sender, "", "usageMessage", label);
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージリソースのメッセージを、カラーコード置き換えしつつ、senderに送信する
|
||||
* @param sender メッセージの送り先
|
||||
* @param pre プレフィックス
|
||||
* @param key リソースキー
|
||||
* @param args リソース内の置き換え対象キーワード
|
||||
*/
|
||||
protected void sendResourceMessage(CommandSender sender, String pre,
|
||||
String key, Object... args) {
|
||||
|
||||
String org = Messages.get(key);
|
||||
if ( org == null || org.equals("") ) {
|
||||
return;
|
||||
}
|
||||
String msg = String.format(pre + org, args);
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージリソースのメッセージを、カラーコード置き換えしつつ、senderに送信する
|
||||
* @param sender メッセージの送り先
|
||||
* @param pre プレフィックス
|
||||
* @param key リソースキー
|
||||
* @param args リソース内の置き換え対象キーワード
|
||||
*/
|
||||
protected void sendResourceMessage(ChannelMember cp, String pre,
|
||||
String key, Object... args) {
|
||||
|
||||
String org = Messages.get(key);
|
||||
if ( org == null || org.equals("") ) {
|
||||
return;
|
||||
}
|
||||
String msg = String.format(pre + org, args);
|
||||
cp.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.github.ucchyocean.lc.Messages;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* 1:1チャット受信コマンド
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatReplyCommand extends LunaChatMessageCommand {
|
||||
|
||||
private static final String PREINFO = Messages.get("infoPrefix");
|
||||
private static final String PREERR = Messages.get("errorPrefix");
|
||||
|
||||
/**
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command,
|
||||
String label, String[] args) {
|
||||
|
||||
// senderからChannelMemberを作成する
|
||||
ChannelMember inviter = ChannelMember.getChannelMember(sender);
|
||||
|
||||
// 会話相手を履歴から取得する
|
||||
String invitedName = DataMaps.privateMessageMap.get(inviter.getName());
|
||||
|
||||
// 引数が無ければ、現在の会話相手を表示して終了する
|
||||
if (args.length == 0) {
|
||||
if ( invitedName == null ) {
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgReplyInviterNone", inviter.getName());
|
||||
} else {
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgReplyInviter", inviter.getName(), invitedName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 会話相手がからっぽなら、コマンドを終了する。
|
||||
if ( invitedName == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotfoundPM");
|
||||
return true;
|
||||
}
|
||||
|
||||
// メッセージを取得する
|
||||
StringBuilder message = new StringBuilder();
|
||||
for ( int i=0; i<args.length; i++ ) {
|
||||
message.append(args[i] + " ");
|
||||
}
|
||||
|
||||
sendTellMessage(inviter, invitedName, message.toString().trim());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* moderatorコマンドのエイリアス実行クラス、名前のみが異なるが、他は全て一緒。
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ModCommand extends ModeratorCommand {
|
||||
|
||||
private static final String COMMAND_NAME = "mod";
|
||||
private static final String USAGE_KEY = "usageMod";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @return コマンド
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#getCommandName()
|
||||
*/
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return COMMAND_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者O
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember sender, String label) {
|
||||
sendResourceMessage(sender, "", USAGE_KEY, label);
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* moderatorコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ModeratorCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "moderator";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageModerator";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.MODERATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
// このコマンドは、デフォルトチャンネルでない人も実行できるが、その場合はチャンネル名を指定する必要がある
|
||||
String cname = null;
|
||||
ArrayList<String> moderator = new ArrayList<String>();
|
||||
if ( args.length >= 2 ) {
|
||||
Channel def = api.getDefaultChannel(sender.getName());
|
||||
if ( def != null ) {
|
||||
cname = def.getName();
|
||||
}
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
moderator.add(args[i]);
|
||||
}
|
||||
} else if ( args.length >= 3 ) {
|
||||
cname = args[1];
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
moderator.add(args[i]);
|
||||
}
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
Channel channel = api.getChannel(cname);
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
if ( channel == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExist");
|
||||
return true;
|
||||
}
|
||||
|
||||
cname = channel.getName();
|
||||
|
||||
// モデレーターかどうか確認する
|
||||
if ( !channel.hasModeratorPermission(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
|
||||
return true;
|
||||
}
|
||||
|
||||
// グローバルチャンネルなら設定できない
|
||||
if ( channel.isGlobalChannel() ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgCannotModeratorGlobal", channel.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
// 設定する
|
||||
for ( String mod : moderator ) {
|
||||
if ( mod.startsWith("-") ) {
|
||||
String name = mod.substring(1);
|
||||
ChannelMember cp = ChannelMember.getChannelMember(name);
|
||||
channel.removeModerator(cp);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgModeratorMinus", name, cname);
|
||||
} else {
|
||||
ChannelMember cp = ChannelMember.getChannelMember(mod);
|
||||
channel.addModerator(cp);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgModerator", mod, cname);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* muteコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class MuteCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "mute";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY1 = "usageMute";
|
||||
private static final String USAGE_KEY2 = "usageMute2";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.MODERATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember sender, String label) {
|
||||
sendResourceMessage(sender, "", USAGE_KEY1, label);
|
||||
sendResourceMessage(sender, "", USAGE_KEY2, label);
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドを実行します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @param args 実行時の引数
|
||||
* @return コマンドが実行されたかどうか
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#runCommand(java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean runCommand(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 実行引数から、Muteするユーザーを取得する
|
||||
String kickedName = "";
|
||||
if (args.length >= 2) {
|
||||
kickedName = args[1];
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 対象チャンネルを取得、取得できない場合はエラー表示して終了する
|
||||
boolean isSpecifiedChannel = false;
|
||||
Channel channel = null;
|
||||
if (args.length >= 3) {
|
||||
channel = api.getChannel(args[2]);
|
||||
isSpecifiedChannel = true;
|
||||
} else if (sender instanceof Player) {
|
||||
channel = api.getDefaultChannel(sender.getName());
|
||||
}
|
||||
if (channel == null) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNoJoin");
|
||||
return true;
|
||||
}
|
||||
|
||||
// モデレーターかどうか確認する
|
||||
if ( !channel.hasModeratorPermission(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Muteされるプレイヤーがメンバーかどうかチェックする
|
||||
ChannelMember kicked = ChannelMember.getChannelMember(kickedName);
|
||||
if (!channel.getMembers().contains(kicked)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNomemberOther");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 既にMuteされているかどうかチェックする
|
||||
if (channel.getMuted().contains(kicked)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgAlreadyMuted");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 期限付きMuteの場合、期限の指定が正しいかどうかをチェックする
|
||||
int expireMinutes = -1;
|
||||
if (args.length >= 3 && !isSpecifiedChannel) {
|
||||
if ( !args[2].matches("[0-9]+") ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgInvalidMuteExpireParameter");
|
||||
return true;
|
||||
}
|
||||
expireMinutes = Integer.parseInt(args[2]);
|
||||
if ( expireMinutes < 1 || 43200 < expireMinutes ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgInvalidMuteExpireParameter");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Mute実行
|
||||
channel.getMuted().add(kicked);
|
||||
if ( expireMinutes != -1 ) {
|
||||
long expire = System.currentTimeMillis() + expireMinutes * 60 * 1000;
|
||||
channel.getMuteExpires().put(kicked, expire);
|
||||
}
|
||||
channel.save();
|
||||
|
||||
// senderに通知メッセージを出す
|
||||
if ( expireMinutes != -1 ) {
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgMuteWithExpire", kickedName, channel.getName(), expireMinutes);
|
||||
} else {
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgMute", kickedName, channel.getName());
|
||||
}
|
||||
|
||||
// チャンネルに通知メッセージを出す
|
||||
if ( expireMinutes != -1 ) {
|
||||
sendResourceMessageWithKeyword(channel,
|
||||
"muteWithExpireMessage", kicked, expireMinutes);
|
||||
} else {
|
||||
sendResourceMessageWithKeyword(channel, "muteMessage", kicked);
|
||||
}
|
||||
|
||||
// BANされた人に通知メッセージを出す
|
||||
if ( kicked != null ) {
|
||||
sendResourceMessage(kicked, PREINFO,
|
||||
"cmdmsgMuted", channel.getName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,411 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.UtilityBukkit;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* optionコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class OptionCommand extends SubCommandAbst {
|
||||
|
||||
private static final int MAX_LENGTH_DESCRIPTION = 30;
|
||||
private static final int MAX_LENGTH_ALIAS = 15;
|
||||
private static final int MAX_LENGTH_PASSWORD = 15;
|
||||
|
||||
private static final String COMMAND_NAME = "option";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageOption";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.MODERATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
// このコマンドは、デフォルトチャンネルでない人も実行できるが、その場合はチャンネル名を指定する必要がある
|
||||
ArrayList<String> optionsTemp = new ArrayList<String>();
|
||||
String cname = null;
|
||||
if ( args.length >= 2 ) {
|
||||
Channel def = api.getDefaultChannel(sender.getName());
|
||||
if ( def != null ) {
|
||||
cname = def.getName();
|
||||
}
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
optionsTemp.add(args[i]);
|
||||
}
|
||||
} else if ( args.length >= 3 ) {
|
||||
cname = args[1];
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
optionsTemp.add(args[i]);
|
||||
}
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
Channel channel = api.getChannel(cname);
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
if ( channel == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExist");
|
||||
return true;
|
||||
}
|
||||
|
||||
cname = channel.getName();
|
||||
|
||||
// モデレーターかどうか確認する
|
||||
if ( !channel.hasModeratorPermission(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 指定内容を解析する
|
||||
HashMap<String, String> options = new HashMap<String, String>();
|
||||
for ( String t : optionsTemp ) {
|
||||
int index = t.indexOf("=");
|
||||
if ( index == -1 ) {
|
||||
continue;
|
||||
}
|
||||
options.put(t.substring(0, index), t.substring(index + 1));
|
||||
}
|
||||
|
||||
// イベントコール
|
||||
// EventResult result = LunaChat.getEventSender().sendLunaChatChannelOptionChangedEvent(
|
||||
// cname, sender, options);
|
||||
// if ( result.isCancelled() ) {
|
||||
// return true;
|
||||
// }
|
||||
// options = result.getValueAsStringMap("options");
|
||||
|
||||
// 設定する
|
||||
boolean setOption = false;
|
||||
|
||||
if ( options.containsKey("description") ) {
|
||||
// チャンネル説明文
|
||||
|
||||
String pnode = PERMISSION_NODE + ".description";
|
||||
if ( !sender.hasPermission(pnode) ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotPermission", pnode);
|
||||
} else {
|
||||
|
||||
String desc = options.get("description");
|
||||
// チャンネル説明文は最大文字長を超えていないか確認
|
||||
if ( desc.length() > MAX_LENGTH_DESCRIPTION ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgToolongDescription", MAX_LENGTH_DESCRIPTION);
|
||||
} else {
|
||||
channel.setDescription(desc);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "description", desc);
|
||||
setOption = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( options.containsKey("alias") ) {
|
||||
// チャンネル別名
|
||||
|
||||
String pnode = PERMISSION_NODE + ".alias";
|
||||
if ( !sender.hasPermission(pnode) ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotPermission", pnode);
|
||||
} else {
|
||||
|
||||
String alias = options.get("alias");
|
||||
if ( alias.length() > MAX_LENGTH_ALIAS ) {
|
||||
// チャンネル別名が最大文字長を超えている
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgToolongAlias", MAX_LENGTH_ALIAS);
|
||||
|
||||
} else if (api.getChannel(alias) != null) {
|
||||
// 別のチャンネル名またはチャンネル別名と重複する
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgDuplicatedAlias",
|
||||
alias, api.getChannel(alias).getName());
|
||||
|
||||
} else {
|
||||
channel.setAlias(alias);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "alias", alias);
|
||||
setOption = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( options.containsKey("color") ) {
|
||||
// チャンネルカラー
|
||||
|
||||
String pnode = PERMISSION_NODE + ".color";
|
||||
if ( !sender.hasPermission(pnode) ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotPermission", pnode);
|
||||
} else {
|
||||
|
||||
String code = options.get("color");
|
||||
|
||||
// TODO Bukkit依存になってしまっているので、実装修正を検討する
|
||||
if ( UtilityBukkit.isValidColor(code) ) {
|
||||
code = UtilityBukkit.changeToColorCode(code);
|
||||
}
|
||||
if ( Utility.isAltColorCode(code) ) {
|
||||
channel.setColorCode(code);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "color", options.get("color"));
|
||||
setOption = true;
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgInvalidColorCode", options.get("color"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( options.containsKey("broadcast") ) {
|
||||
// ブロードキャストチャンネル
|
||||
|
||||
String pnode = PERMISSION_NODE + ".broadcast";
|
||||
if ( !sender.hasPermission(pnode) ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotPermission", pnode);
|
||||
} else {
|
||||
|
||||
String value = options.get("broadcast");
|
||||
|
||||
if ( value.equals("") || value.equalsIgnoreCase("false") ) {
|
||||
if ( channel.isGlobalChannel() ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgCannotOffGlobalBroadcast");
|
||||
} else {
|
||||
channel.setBroadcast(false);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "broadcast", "false");
|
||||
setOption = true;
|
||||
}
|
||||
} else if ( value.equalsIgnoreCase("true") ) {
|
||||
channel.setBroadcast(true);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "broadcast", "true");
|
||||
setOption = true;
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgInvalidBooleanOption", "broadcast");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( options.containsKey("range") ) {
|
||||
// レンジ
|
||||
|
||||
String pnode = PERMISSION_NODE + ".range";
|
||||
if ( !sender.hasPermission(pnode) ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotPermission", pnode);
|
||||
} else {
|
||||
|
||||
String value = options.get("range");
|
||||
|
||||
if ( value.equals("") ) {
|
||||
channel.setWorldRange(false);
|
||||
channel.setChatRange(0);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "range", "無効");
|
||||
setOption = true;
|
||||
} else if ( value.equalsIgnoreCase("world") ) {
|
||||
channel.setWorldRange(true);
|
||||
channel.setChatRange(0);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "range", "world");
|
||||
setOption = true;
|
||||
} else if ( value.matches("[0-9]+") ) {
|
||||
channel.setWorldRange(true);
|
||||
channel.setChatRange(Integer.parseInt(value));
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "range", value);
|
||||
setOption = true;
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgInvalidRangeOption");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( options.containsKey("allowcc") ) {
|
||||
// カラーコード使用可否
|
||||
|
||||
String pnode = PERMISSION_NODE + ".allowcc";
|
||||
if ( !sender.hasPermission(pnode) ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotPermission", pnode);
|
||||
} else {
|
||||
|
||||
String value = options.get("allowcc");
|
||||
|
||||
if ( value.equals("") || value.equalsIgnoreCase("false") ) {
|
||||
channel.setAllowCC(false);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "allowcc", "false");
|
||||
setOption = true;
|
||||
} else if ( value.equalsIgnoreCase("true") ) {
|
||||
channel.setAllowCC(true);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "allowcc", "true");
|
||||
setOption = true;
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgInvalidBooleanOption", "allowcc");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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") ) {
|
||||
// パスワード
|
||||
|
||||
String pnode = PERMISSION_NODE + ".password";
|
||||
if ( !sender.hasPermission(pnode) ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotPermission", pnode);
|
||||
} else {
|
||||
|
||||
String password = options.get("password");
|
||||
// パスワードが文字制限を超える場合はエラー
|
||||
if ( password.length() > MAX_LENGTH_PASSWORD ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgToolongPassword", MAX_LENGTH_PASSWORD);
|
||||
} else {
|
||||
channel.setPassword(password);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "password", password);
|
||||
setOption = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( options.containsKey("visible") ) {
|
||||
// ビジブル
|
||||
|
||||
String pnode = PERMISSION_NODE + ".visible";
|
||||
if ( !sender.hasPermission(pnode) ) {
|
||||
sendResourceMessage(sender, PREERR,
|
||||
"errmsgNotPermission", pnode);
|
||||
} else {
|
||||
|
||||
String temp = options.get("visible");
|
||||
if ( temp.equalsIgnoreCase("false") ) {
|
||||
channel.setVisible(false);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "visible", "false");
|
||||
setOption = true;
|
||||
} else if ( temp.equalsIgnoreCase("true") ) {
|
||||
channel.setVisible(true);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "visible", "true");
|
||||
setOption = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !setOption ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgInvalidOptions");
|
||||
} else {
|
||||
channel.save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* pardonコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class PardonCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "pardon";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usagePardon";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.MODERATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 実行引数から、BAN解除するユーザーを取得する
|
||||
String kickedName = "";
|
||||
if (args.length >= 2) {
|
||||
kickedName = args[1];
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 対象チャンネルを取得、取得できない場合はエラー表示して終了する
|
||||
Channel channel = null;
|
||||
if (args.length >= 3) {
|
||||
channel = api.getChannel(args[2]);
|
||||
} else if (sender instanceof Player) {
|
||||
channel = api.getDefaultChannel(sender.getName());
|
||||
}
|
||||
if (channel == null) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNoJoin");
|
||||
return true;
|
||||
}
|
||||
|
||||
// モデレーターかどうか確認する
|
||||
if ( !channel.hasModeratorPermission(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
|
||||
return true;
|
||||
}
|
||||
|
||||
// BAN解除されるプレイヤーがBANされているかどうかチェックする
|
||||
ChannelMember kicked = ChannelMember.getChannelMember(kickedName);
|
||||
if (!channel.getBanned().contains(kicked)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotBanned");
|
||||
return true;
|
||||
}
|
||||
|
||||
// BAN解除実行
|
||||
channel.getBanned().remove(kicked);
|
||||
if ( channel.getBanExpires().containsKey(kicked) ) {
|
||||
channel.getBanExpires().remove(kicked);
|
||||
}
|
||||
channel.save();
|
||||
|
||||
// senderに通知メッセージを出す
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgPardon", kickedName, channel.getName());
|
||||
|
||||
// チャンネルに通知メッセージを出す
|
||||
sendResourceMessageWithKeyword(channel, "pardonMessage", kicked);
|
||||
|
||||
// BANされていた人に通知メッセージを出す
|
||||
if ( kicked != null && kicked.isOnline() ) {
|
||||
sendResourceMessage(kicked, PREINFO,
|
||||
"cmdmsgPardoned", channel.getName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* reloadコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ReloadCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "reload";
|
||||
private static final String PERMISSION_NODE = "lunachat-admin." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageReload";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
api.reloadAllData();
|
||||
config.reloadConfig(LunaChat.getDataFolder(), LunaChat.getPluginJarFile());
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgReload");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* removeコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class RemoveCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "remove";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageRemove";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.MODERATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
// このコマンドは、デフォルトチャンネルでない人も実行できるが、その場合はチャンネル名を指定する必要がある
|
||||
String cname = null;
|
||||
if ( args.length <= 1 ) {
|
||||
Channel def = api.getDefaultChannel(sender.getName());
|
||||
if ( def != null ) {
|
||||
cname = def.getName();
|
||||
}
|
||||
} else if ( args.length >= 2 ) {
|
||||
cname = args[1];
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルが存在するかどうか確認する
|
||||
Channel channel = api.getChannel(cname);
|
||||
if ( channel == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExist");
|
||||
return true;
|
||||
}
|
||||
|
||||
// モデレーターかどうか確認する
|
||||
if ( !channel.hasModeratorPermission(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
|
||||
return true;
|
||||
}
|
||||
|
||||
// グローバルチャンネルなら削除できない
|
||||
if ( channel.isGlobalChannel() ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCannotRemoveGlobal", channel.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネル削除
|
||||
if ( api.removeChannel(cname) ) {
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgRemove", cname);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
public class SetCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "set";
|
||||
private static final String PERMISSION_NODE = "lunachat-admin." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY1 = "usageSet1";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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(ChannelMember sender, String label) {
|
||||
sendResourceMessage(sender, "", USAGE_KEY1, label);
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドを実行します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @param args 実行時の引数
|
||||
* @return コマンドが実行されたかどうか
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#runCommand(java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean runCommand(ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
// このコマンドは、コンソールでも実行できる
|
||||
|
||||
if ( args.length >= 3 && args[1].equalsIgnoreCase("default") ) {
|
||||
// 「/ch set default (player名) [channel名]」の実行
|
||||
|
||||
String targetPlayer = args[2];
|
||||
|
||||
Channel targetChannel = null;
|
||||
if ( args.length >= 4 ) {
|
||||
targetChannel = api.getChannel(args[3]);
|
||||
} else {
|
||||
targetChannel = api.getDefaultChannel(sender.getName());
|
||||
}
|
||||
|
||||
if ( targetChannel == null ) {
|
||||
// チャンネルが正しく指定されなかった
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExistOrNotSpecified");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 発言先を設定
|
||||
api.setDefaultChannel(targetPlayer, targetChannel.getName());
|
||||
|
||||
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());
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc.Messages;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* サブコマンドの抽象クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public abstract class SubCommandAbst {
|
||||
|
||||
/**
|
||||
* コマンドの種別
|
||||
* @author ucchy
|
||||
*/
|
||||
protected enum CommandType {
|
||||
|
||||
/** 一般ユーザー向けコマンド */
|
||||
USER,
|
||||
|
||||
/** チャンネルモデレーター向けコマンド */
|
||||
MODERATOR,
|
||||
|
||||
/** サーバー管理者向けコマンド */
|
||||
ADMIN
|
||||
}
|
||||
|
||||
protected static final String PREINFO = Messages.get("infoPrefix");
|
||||
protected static final String PREERR = Messages.get("errorPrefix");
|
||||
|
||||
protected LunaChatAPI api;
|
||||
protected LunaChatConfig config;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
*/
|
||||
public SubCommandAbst() {
|
||||
api = LunaChat.getPlugin().getLunaChatAPI();
|
||||
config = LunaChat.getPlugin().getLunaChatConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージリソースのメッセージを、カラーコード置き換えしつつ、Channelに送信する
|
||||
* @param channel メッセージの送り先
|
||||
* @param pre プレフィックス
|
||||
* @param key リソースキー
|
||||
* @param player キーワード置き換えに使用するプレイヤー
|
||||
*/
|
||||
protected void sendResourceMessageWithKeyword(
|
||||
Channel channel, String key, ChannelMember player) {
|
||||
|
||||
String msg = Messages.get(key);
|
||||
if ( msg == null || msg.equals("") ) {
|
||||
return;
|
||||
}
|
||||
msg = msg.replace("%ch", channel.getName());
|
||||
msg = msg.replace("%color", channel.getColorCode());
|
||||
if ( player != null ) {
|
||||
msg = msg.replace("%username", player.getDisplayName());
|
||||
msg = msg.replace("%player", player.getName());
|
||||
} else {
|
||||
msg = msg.replace("%username", "");
|
||||
msg = msg.replace("%player", "");
|
||||
}
|
||||
msg = Utility.replaceColorCode(msg);
|
||||
channel.sendMessage(null, msg, null, true, "system");
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージリソースのメッセージを、カラーコード置き換えしつつ、Channelに送信する
|
||||
* @param channel メッセージの送り先
|
||||
* @param pre プレフィックス
|
||||
* @param key リソースキー
|
||||
* @param player キーワード置き換えに使用するプレイヤー
|
||||
* @param minutes キーワード置き換えに使用する数値
|
||||
*/
|
||||
protected void sendResourceMessageWithKeyword(
|
||||
Channel channel, String key, ChannelMember player, int minutes) {
|
||||
|
||||
String msg = Messages.get(key);
|
||||
if ( msg == null || msg.equals("") ) {
|
||||
return;
|
||||
}
|
||||
msg = msg.replace("%ch", channel.getName());
|
||||
msg = msg.replace("%color", channel.getColorCode());
|
||||
msg = msg.replace("%d", String.valueOf(minutes));
|
||||
if ( player != null ) {
|
||||
msg = msg.replace("%username", player.getDisplayName());
|
||||
msg = msg.replace("%player", player.getName());
|
||||
} else {
|
||||
msg = msg.replace("%username", "");
|
||||
msg = msg.replace("%player", "");
|
||||
}
|
||||
msg = Utility.replaceColorCode(msg);
|
||||
channel.sendMessage(null, msg, null, true, "system");
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージリソースのメッセージを、カラーコード置き換えしつつ、ChannelMemberに送信する
|
||||
* @param sender メッセージの送り先
|
||||
* @param pre プレフィックス
|
||||
* @param key リソースキー
|
||||
* @param args リソース内の置き換え対象キーワード
|
||||
*/
|
||||
protected void sendResourceMessage(
|
||||
ChannelMember cp, String pre, String key, Object... args) {
|
||||
|
||||
String org = Messages.get(key);
|
||||
if ( org == null || org.equals("") ) {
|
||||
return;
|
||||
}
|
||||
String msg = String.format(pre + org, args);
|
||||
cp.sendMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @return コマンド
|
||||
*/
|
||||
public abstract String getCommandName();
|
||||
|
||||
/**
|
||||
* パーミッションノードを取得します。
|
||||
* @return パーミッションノード
|
||||
*/
|
||||
public abstract String getPermissionNode();
|
||||
|
||||
/**
|
||||
* コマンドの種別を取得します。
|
||||
* @return コマンド種別
|
||||
*/
|
||||
public abstract CommandType getCommandType();
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
*/
|
||||
public abstract void sendUsageMessage(
|
||||
ChannelMember sender, String label);
|
||||
|
||||
/**
|
||||
* コマンドを実行します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @param args 実行時の引数
|
||||
* @return コマンドが実行されたかどうか
|
||||
*/
|
||||
public abstract boolean runCommand(
|
||||
ChannelMember sender, String label, String[] args);
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* templateコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class TemplateCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "template";
|
||||
private static final String PERMISSION_NODE = "lunachat-admin." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageTemplate";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
// このコマンドは、コンソールでも実行できる
|
||||
if ( args.length <= 1 ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !args[1].matches("[0-9]") ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgInvalidTemplateNumber");
|
||||
sendResourceMessage(sender, PREERR, "usageTemplate");
|
||||
return true;
|
||||
}
|
||||
|
||||
String id = args[1];
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if ( args.length >= 3 ) {
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
buf.append(args[i] + " ");
|
||||
}
|
||||
}
|
||||
String format = buf.toString().trim();
|
||||
|
||||
// 登録を実行
|
||||
if ( format.equals("") ) {
|
||||
api.removeTemplate(id);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgTemplateRemove", id);
|
||||
} else {
|
||||
api.setTemplate(id, format);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgTemplate", id, format);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* unhideコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class UnhideCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "unhide";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY1 = "usageUnhide";
|
||||
private static final String USAGE_KEY2 = "usageUnhidePlayer";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember sender, String label) {
|
||||
sendResourceMessage(sender, "", USAGE_KEY1, label);
|
||||
sendResourceMessage(sender, "", USAGE_KEY2, label);
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドを実行します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @param args 実行時の引数
|
||||
* @return コマンドが実行されたかどうか
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#runCommand(java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean runCommand(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
String cname = null;
|
||||
boolean isPlayerCommand = false;
|
||||
boolean isChannelCommand = false;
|
||||
if ( args.length <= 1 ) {
|
||||
Channel def = api.getDefaultChannel(sender.getName());
|
||||
if ( def != null ) {
|
||||
cname = def.getName();
|
||||
}
|
||||
} else if ( args.length >= 2 ) {
|
||||
if ( args.length >= 3 && args[1].equalsIgnoreCase("player") ) {
|
||||
// 指定されたコマンドが「/ch unhide player (player名)」なら、対象をプレイヤーとする。
|
||||
isPlayerCommand = true;
|
||||
isChannelCommand = false;
|
||||
cname = args[2];
|
||||
|
||||
} else if ( args.length >= 3 && args[1].equalsIgnoreCase("channel") ) {
|
||||
// 指定されたコマンドが「/ch unhide channel (channel名)」なら、対象をチャンネルとする。
|
||||
isPlayerCommand = false;
|
||||
isChannelCommand = true;
|
||||
cname = args[2];
|
||||
|
||||
} else {
|
||||
// 「/ch hide (player名 または channel名)」
|
||||
cname = args[1];
|
||||
}
|
||||
}
|
||||
|
||||
// チャンネルかプレイヤーが存在するかどうかをチェックする
|
||||
Channel channel = api.getChannel(cname);
|
||||
if ( !isPlayerCommand && channel != null ) {
|
||||
isChannelCommand = true;
|
||||
} else if ( Utility.existsOfflinePlayer(cname) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExistChannelAndPlayer");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( isChannelCommand ) {
|
||||
// チャンネルが対象の場合の処理
|
||||
|
||||
// 非表示になっているかどうかをチェックする
|
||||
if ( !channel.getHided().contains(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgAlreadyUnhided");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 設定する
|
||||
channel.getHided().remove(sender);
|
||||
channel.save();
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgUnhided", channel.getName());
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
// プレイヤーが対象の場合の処理
|
||||
|
||||
// 既に表示になっていないかどうかをチェックする
|
||||
ChannelMember hided = ChannelMember.getChannelMember(cname);
|
||||
if ( !api.getHidelist(hided).contains(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgAlreadyUnhidedPlayer");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 設定する
|
||||
api.removeHidelist(sender, hided);
|
||||
sendResourceMessage(sender, PREINFO, "cmdmsgUnhidedPlayer", hided.getDisplayName());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* unmuteコマンドの実行クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class UnmuteCommand extends SubCommandAbst {
|
||||
|
||||
private static final String COMMAND_NAME = "unmute";
|
||||
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
|
||||
private static final String USAGE_KEY = "usageUnmute";
|
||||
|
||||
/**
|
||||
* コマンドを取得します。
|
||||
* @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.MODERATOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用方法に関するメッセージをsenderに送信します。
|
||||
* @param sender コマンド実行者
|
||||
* @param label 実行ラベル
|
||||
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
|
||||
*/
|
||||
@Override
|
||||
public void sendUsageMessage(
|
||||
ChannelMember 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(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
// 実行引数から、Mute解除するユーザーを取得する
|
||||
String kickedName = "";
|
||||
if (args.length >= 2) {
|
||||
kickedName = args[1];
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 対象チャンネルを取得、取得できない場合はエラー表示して終了する
|
||||
Channel channel = null;
|
||||
if (args.length >= 3) {
|
||||
channel = api.getChannel(args[2]);
|
||||
} else if (sender instanceof Player) {
|
||||
channel = api.getDefaultChannel(sender.getName());
|
||||
}
|
||||
if (channel == null) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNoJoin");
|
||||
return true;
|
||||
}
|
||||
|
||||
// モデレーターかどうか確認する
|
||||
if ( !channel.hasModeratorPermission(sender) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Mute解除されるプレイヤーがMuteされているかどうかチェックする
|
||||
ChannelMember kicked = ChannelMember.getChannelMember(kickedName);
|
||||
if (!channel.getMuted().contains(kicked)) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotMuted");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Mute解除実行
|
||||
channel.getMuted().remove(kicked);
|
||||
if ( channel.getMuteExpires().containsKey(kicked) ) {
|
||||
channel.getMuteExpires().remove(kicked);
|
||||
}
|
||||
channel.save();
|
||||
|
||||
// senderに通知メッセージを出す
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgUnmute", kickedName, channel.getName());
|
||||
|
||||
// チャンネルに通知メッセージを出す
|
||||
sendResourceMessageWithKeyword(channel, "unmuteMessage", kicked);
|
||||
|
||||
// BANされていた人に通知メッセージを出す
|
||||
if ( kicked != null && kicked.isOnline() ) {
|
||||
sendResourceMessage(kicked, PREINFO,
|
||||
"cmdmsgUnmuted", channel.getName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.event;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
/**
|
||||
* 基底のキャンセル可能イベントクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatBaseCancellableEvent extends LunaChatBaseEvent implements Cancellable {
|
||||
|
||||
private boolean isCancelled;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param channelName チャンネル名
|
||||
*/
|
||||
public LunaChatBaseCancellableEvent(String channelName) {
|
||||
super(channelName);
|
||||
}
|
||||
|
||||
/**
|
||||
* イベントがキャンセルされたかどうかをかえす
|
||||
* @see org.bukkit.event.Cancellable#isCancelled()
|
||||
*/
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* イベントをキャンセルするかどうかを設定する
|
||||
* @see org.bukkit.event.Cancellable#setCancelled(boolean)
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
isCancelled = cancelled;
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.event;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
|
||||
/**
|
||||
* 基底イベントクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public abstract class LunaChatBaseEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
protected String channelName;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param channelName チャンネル名
|
||||
*/
|
||||
public LunaChatBaseEvent(String channelName) {
|
||||
super(!Bukkit.isPrimaryThread());
|
||||
this.channelName = channelName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネル名を取得する
|
||||
* @return チャンネル名
|
||||
*/
|
||||
public String getChannelName() {
|
||||
return channelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルを取得する
|
||||
* @return チャンネル
|
||||
*/
|
||||
public Channel getChannel() {
|
||||
return LunaChat.getAPI().getChannel(channelName);
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.event;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* チャンネルチャットのチャットイベント
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatChannelChatEvent extends LunaChatBaseCancellableEvent {
|
||||
|
||||
private ChannelMember player;
|
||||
private String originalMessage;
|
||||
private String ngMaskedMessage;
|
||||
private String messageFormat;
|
||||
|
||||
public LunaChatChannelChatEvent(String channelName, ChannelMember player,
|
||||
String originalMessage, String ngMaskedMessage,
|
||||
String messageFormat) {
|
||||
super(channelName);
|
||||
this.player = player;
|
||||
this.originalMessage = originalMessage;
|
||||
this.ngMaskedMessage = ngMaskedMessage;
|
||||
this.messageFormat = messageFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言を行ったプレイヤーを取得します。
|
||||
* @return 発言したプレイヤー
|
||||
*/
|
||||
public ChannelMember getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* 置き換え前の、発言されたままのテキストをかえす
|
||||
* @return 発言内容
|
||||
*/
|
||||
public String getPreReplaceMessage() {
|
||||
return originalMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* NGワードがマスクされた後のテキストをかえす
|
||||
* @return NGワードマスク済みの発言内容
|
||||
*/
|
||||
public String getNgMaskedMessage() {
|
||||
return ngMaskedMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージに適用されるフォーマットをかえす
|
||||
* @return フォーマット
|
||||
*/
|
||||
public String getMessageFormat() {
|
||||
return messageFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* NGワードマスク後のテキストを上書き設定する
|
||||
* @param ngMaskedMessage 上書きする発言内容
|
||||
*/
|
||||
public void setNgMaskedMessage(String ngMaskedMessage) {
|
||||
this.ngMaskedMessage = ngMaskedMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージフォーマットを上書き設定する
|
||||
* @param messageFormat フォーマット
|
||||
*/
|
||||
public void setMessageFormat(String messageFormat) {
|
||||
this.messageFormat = messageFormat;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.event;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
|
||||
/**
|
||||
* チャンネル作成イベント
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatChannelCreateEvent extends LunaChatBaseCancellableEvent {
|
||||
|
||||
private CommandSender sender;
|
||||
|
||||
public LunaChatChannelCreateEvent(String channelName, CommandSender sender) {
|
||||
super(channelName);
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* 作成するチャンネルのチャンネル名を上書き設定する
|
||||
* @param channelName 設定するチャンネル名
|
||||
*/
|
||||
public void setChannelName(String channelName) {
|
||||
this.channelName = channelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルを作成した人を取得する。
|
||||
* @return チャンネルを作成したCommandSender
|
||||
*/
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated チャンネル作成イベントは、チャンネルを作成する前に呼び出されるので、
|
||||
* このメソッドの戻り値は必ずnullになります。
|
||||
* @see com.github.ucchyocean.lc.event.LunaChatBaseEvent#getChannel()
|
||||
*/
|
||||
@Override
|
||||
public Channel getChannel() {
|
||||
return super.getChannel();
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* メンバー変更イベント
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatChannelMemberChangedEvent extends LunaChatBaseCancellableEvent {
|
||||
|
||||
private List<ChannelMember> before;
|
||||
private List<ChannelMember> after;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param channelName チャンネル名
|
||||
* @param before 変更前のメンバー
|
||||
* @param after 変更後のメンバー
|
||||
*/
|
||||
public LunaChatChannelMemberChangedEvent(
|
||||
String channelName, List<ChannelMember> before, List<ChannelMember> after) {
|
||||
super(channelName);
|
||||
this.before = before;
|
||||
this.after = after;
|
||||
}
|
||||
|
||||
/**
|
||||
* 変更前のメンバーリストをかえす
|
||||
* @return
|
||||
*/
|
||||
public List<ChannelMember> getMembersBefore() {
|
||||
return before;
|
||||
}
|
||||
|
||||
/**
|
||||
* 変更後のメンバーリストをかえす
|
||||
* @return
|
||||
*/
|
||||
public List<ChannelMember> getMembersAfter() {
|
||||
return after;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* チャンネルチャットのメッセージイベント、
|
||||
* このイベントはキャンセルできない。
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatChannelMessageEvent extends LunaChatBaseEvent {
|
||||
|
||||
private ChannelMember player;
|
||||
private String message;
|
||||
private ArrayList<ChannelMember> recipients;
|
||||
private String displayName;
|
||||
private String originalMessage;
|
||||
|
||||
public LunaChatChannelMessageEvent(String channelName,
|
||||
ChannelMember player, String message, ArrayList<ChannelMember> recipients,
|
||||
String displayName, String originalMessage) {
|
||||
super(channelName);
|
||||
this.player = player;
|
||||
this.message = message;
|
||||
this.recipients = recipients;
|
||||
this.displayName = displayName;
|
||||
this.originalMessage = originalMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言したプレイヤー、システムメッセージの場合はnullになることに注意
|
||||
* @return player 発言プレイヤー
|
||||
*/
|
||||
public ChannelMember getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* 置き換えされたメッセージ
|
||||
* @return message メッセージ
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを受信するプレイヤーリスト
|
||||
* @return recipients プレイヤーリスト
|
||||
*/
|
||||
public ArrayList<ChannelMember> getRecipients() {
|
||||
return recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者の表示名を取得する
|
||||
* @return 発言者の表示名
|
||||
*/
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* オリジナルメッセージ(チャットフォーマットを適用していない状態のメッセージ)を取得する
|
||||
* @return オリジナルメッセージ
|
||||
*/
|
||||
public String getOriginalMessage() {
|
||||
return originalMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを上書き設定する
|
||||
* @param message メッセージ
|
||||
*/
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージ受信者を上書き設定する
|
||||
* @param recipients メッセージ受信者
|
||||
*/
|
||||
public void setRecipients(ArrayList<ChannelMember> recipients) {
|
||||
this.recipients = recipients;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.event;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* オプション変更イベント
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatChannelOptionChangedEvent extends LunaChatBaseCancellableEvent {
|
||||
|
||||
private CommandSender sender;
|
||||
private HashMap<String, String> options;
|
||||
|
||||
public LunaChatChannelOptionChangedEvent(String channelName,
|
||||
CommandSender sender, HashMap<String, String> options) {
|
||||
super(channelName);
|
||||
this.sender = sender;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 変更後のオプションリストをかえす
|
||||
* @return オプションリスト
|
||||
*/
|
||||
public HashMap<String, String> getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* オプションリストを上書き設定する
|
||||
* @param options オプションリスト
|
||||
*/
|
||||
public void setOptions(HashMap<String, String> options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルのオプションを変更した人を取得する。
|
||||
* @return チャンネルのオプションを変更したCommandSender
|
||||
*/
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.event;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* チャンネル削除イベント
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatChannelRemoveEvent extends LunaChatBaseCancellableEvent {
|
||||
|
||||
private CommandSender sender;
|
||||
|
||||
public LunaChatChannelRemoveEvent(String channelName, CommandSender sender) {
|
||||
super(channelName);
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルを削除した人を取得する。
|
||||
* @return チャンネルを削除したCommandSender
|
||||
*/
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.event;
|
||||
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* Japanize変換が行われた後に呼び出されるイベント
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatPostJapanizeEvent extends LunaChatBaseCancellableEvent {
|
||||
|
||||
private ChannelMember player;
|
||||
private String original;
|
||||
private String japanized;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param channelName チャンネル名
|
||||
* @param player 発言したプレイヤー
|
||||
* @param original 変換前の文字列
|
||||
* @param japanized 変換後の文字列
|
||||
*/
|
||||
public LunaChatPostJapanizeEvent(String channelName, ChannelMember player,
|
||||
String original, String japanized) {
|
||||
super(channelName);
|
||||
this.player = player;
|
||||
this.original = original;
|
||||
this.japanized = japanized;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言を行ったプレイヤーを取得します。
|
||||
* @return 発言したプレイヤー
|
||||
*/
|
||||
public ChannelMember getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize変換後の文字列を返す
|
||||
* @return 変換後の文字列
|
||||
*/
|
||||
public String getJapanized() {
|
||||
return japanized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize変換後の文字列を差し替える
|
||||
* @param japanized 変換後の文字列
|
||||
*/
|
||||
public void setJapanized(String japanized) {
|
||||
this.japanized = japanized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Japanize変換前の文字列を返す
|
||||
* @return 変換前の文字列
|
||||
*/
|
||||
public String getOriginal() {
|
||||
return original;
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.event;
|
||||
|
||||
import com.github.ucchyocean.lc.channel.Channel;
|
||||
import com.github.ucchyocean.lc.member.ChannelMember;
|
||||
|
||||
/**
|
||||
* チャンネルチャットへの発言前に発生するイベント
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatPreChatEvent extends LunaChatBaseCancellableEvent {
|
||||
|
||||
private ChannelMember player;
|
||||
private String message;
|
||||
|
||||
public LunaChatPreChatEvent(String channelName, ChannelMember player, String message) {
|
||||
super(channelName);
|
||||
this.player = player;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言を行ったプレイヤーを取得します。
|
||||
* @return 発言したプレイヤー
|
||||
*/
|
||||
public ChannelMember getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言内容を取得します。
|
||||
* @return 発言内容
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言先チャンネルを変更します。
|
||||
* @param channelName 発言先チャンネル名
|
||||
*/
|
||||
public void setChannelName(String channelName) {
|
||||
this.channelName = channelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言先チャンネルを変更します。
|
||||
* @param channel 発言先チャンネル
|
||||
*/
|
||||
public void setChannel(Channel channel) {
|
||||
if ( channel == null ) return;
|
||||
this.channelName = channel.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言内容を変更します。
|
||||
* @param message 発言内容
|
||||
*/
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.github.ucchyocean.lc.japanize;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
public class GoogleIME {
|
||||
|
||||
protected GoogleIME() {
|
||||
}
|
||||
|
||||
/**
|
||||
* GoogleIMEの最初の変換候補を抽出して結合します
|
||||
*
|
||||
* @param json 変換元のJson形式の文字列
|
||||
* @return 変換後の文字列
|
||||
* @since 2.8.10
|
||||
*/
|
||||
public static String parseJson(String json) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for ( JsonElement response : new Gson().fromJson(json, JsonArray.class) ) {
|
||||
result.append(response.getAsJsonArray().get(1).getAsJsonArray().get(0).getAsString());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.japanize;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import com.google.common.io.CharStreams;
|
||||
|
||||
/**
|
||||
* ひらがなのみの文章を、IMEを使用して変換します。
|
||||
* 使用される変換候補は全て第1候補のため、正しくない結果が含まれることもよくあります。
|
||||
* @author ucchy
|
||||
*/
|
||||
public class IMEConverter {
|
||||
|
||||
private static final String SOCIAL_IME_URL =
|
||||
"https://www.social-ime.com/api/?string=";
|
||||
private static final String GOOGLE_IME_URL =
|
||||
"https://www.google.com/transliterate?langpair=ja-Hira|ja&text=";
|
||||
|
||||
/**
|
||||
* GoogleIMEを使って変換する
|
||||
* @param org 変換元
|
||||
* @return 変換後
|
||||
*/
|
||||
public static String convByGoogleIME(String org) {
|
||||
return conv(org, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* SocialIMEを使って変換する
|
||||
* @param org 変換元
|
||||
* @return 変換後
|
||||
* @deprecated SocialIMEが2016年9月1日にサービス終了するため、このAPIは今後呼び出してはならない。
|
||||
*/
|
||||
@Deprecated
|
||||
public static String convBySocialIME(String org) {
|
||||
return conv(org, false);
|
||||
}
|
||||
|
||||
// 変換の実行
|
||||
private static String conv(String org, boolean isGoogleIME) {
|
||||
|
||||
if ( org.length() == 0 ) {
|
||||
return "";
|
||||
}
|
||||
|
||||
HttpURLConnection urlconn = null;
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
String baseurl;
|
||||
String encode;
|
||||
if ( isGoogleIME ) {
|
||||
baseurl = GOOGLE_IME_URL + URLEncoder.encode(org , "UTF-8");
|
||||
encode = "UTF-8";
|
||||
} else {
|
||||
baseurl = SOCIAL_IME_URL + URLEncoder.encode(org , "UTF-8");
|
||||
encode = "EUC_JP";
|
||||
}
|
||||
URL url = new URL(baseurl);
|
||||
|
||||
urlconn = (HttpURLConnection)url.openConnection();
|
||||
urlconn.setRequestMethod("GET");
|
||||
urlconn.setInstanceFollowRedirects(false);
|
||||
urlconn.connect();
|
||||
|
||||
reader = new BufferedReader(
|
||||
new InputStreamReader(urlconn.getInputStream(), encode));
|
||||
|
||||
String json = CharStreams.toString(reader);
|
||||
String parsed = GoogleIME.parseJson(json);
|
||||
// if ( !Utility.isCB19orLater() ) {
|
||||
// parsed = YukiKanaConverter.fixBrackets(parsed);
|
||||
// }
|
||||
|
||||
return parsed;
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if ( urlconn != null ) {
|
||||
urlconn.disconnect();
|
||||
}
|
||||
if ( reader != null ) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) { // do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
// デバッグ用エントリ
|
||||
public static void main(String[] args) {
|
||||
String testee = "sonnnakotohanak(ry)";
|
||||
System.out.println("original : " + testee);
|
||||
System.out.println("kana : " + YukiKanaConverter.conv(testee));
|
||||
System.out.println("GoogleIME : " + convByGoogleIME(YukiKanaConverter.conv(testee)));
|
||||
System.out.println("SocialIME : " + convBySocialIME(YukiKanaConverter.conv(testee)));
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.github.ucchyocean.lc.japanize;
|
||||
|
||||
/**
|
||||
* 日本語変換タイプ
|
||||
* @author ucchy
|
||||
*/
|
||||
public enum JapanizeType {
|
||||
|
||||
/** 日本語変換をしない */
|
||||
NONE("none"),
|
||||
|
||||
/** カナ変換のみする */
|
||||
KANA("kana"),
|
||||
|
||||
/** カナ変換後、GoogleIMEで漢字変換 */
|
||||
GOOGLE_IME("googleime");
|
||||
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param id
|
||||
*/
|
||||
JapanizeType(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列表記を返す
|
||||
* @see java.lang.Enum#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列表記からJapanizeTypeを作成して返す
|
||||
* @param id ID
|
||||
* @param def デフォルト
|
||||
* @return
|
||||
*/
|
||||
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 def;
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* @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,381 +0,0 @@
|
||||
package com.github.ucchyocean.lc.japanize;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
|
||||
/**
|
||||
* 「ローマ字」から「かな文字」へ正確に変換するクラス
|
||||
*
|
||||
* @author YukiLeafX
|
||||
* @see <a href="https://support.microsoft.com/ja-jp/help/883232">参考</a>
|
||||
*/
|
||||
public class YukiKanaConverter {
|
||||
|
||||
private static final ImmutableMap<String, String> MAP;
|
||||
|
||||
private static final String[] ROMAJI_LIST;
|
||||
private static final String[] HIRAGANA_LIST;
|
||||
|
||||
protected YukiKanaConverter() {
|
||||
}
|
||||
|
||||
static {
|
||||
ImmutableSortedMap.Builder<String, String> builder = ImmutableSortedMap.reverseOrder();
|
||||
|
||||
// ひらがな
|
||||
builder.put("a", "あ");
|
||||
builder.put("i", "い").put("yi", "い");
|
||||
builder.put("u", "う").put("wu", "う").put("whu", "う");
|
||||
builder.put("e", "え");
|
||||
builder.put("o", "お");
|
||||
|
||||
builder.put("wha", "うぁ");
|
||||
builder.put("whi", "うぃ").put("wi", "うぃ");
|
||||
//
|
||||
builder.put("whe", "うぇ").put("we", "うぇ");
|
||||
builder.put("who", "うぉ");
|
||||
|
||||
//
|
||||
builder.put("wyi", "ゐ");
|
||||
//
|
||||
builder.put("wye", "ゑ");
|
||||
//
|
||||
|
||||
builder.put("la", "ぁ").put("xa", "ぁ");
|
||||
builder.put("li", "ぃ").put("xi", "ぃ").put("lyi", "ぃ").put("xyi", "ぃ");
|
||||
builder.put("lu", "ぅ").put("xu", "ぅ");
|
||||
builder.put("le", "ぇ").put("xe", "ぇ").put("lye", "ぇ").put("xye", "ぇ");
|
||||
builder.put("lo", "ぉ").put("xo", "ぉ");
|
||||
|
||||
//
|
||||
builder.put("ye", "いぇ");
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
builder.put("ka", "か").put("ca", "か");
|
||||
builder.put("ki", "き");
|
||||
builder.put("ku", "く").put("cu", "く").put("qu", "く");
|
||||
builder.put("ke", "け");
|
||||
builder.put("ko", "こ").put("co", "こ");
|
||||
|
||||
builder.put("kya", "きゃ");
|
||||
builder.put("kyi", "きぃ");
|
||||
builder.put("kyu", "きゅ");
|
||||
builder.put("kye", "きぇ");
|
||||
builder.put("kyo", "きょ");
|
||||
|
||||
builder.put("qya", "くゃ");
|
||||
//
|
||||
builder.put("qyu", "くゅ");
|
||||
//
|
||||
builder.put("qyo", "くょ");
|
||||
|
||||
builder.put("qwa", "くぁ").put("qa", "くぁ").put("kwa", "くぁ");
|
||||
builder.put("qwi", "くぃ").put("qi", "くぃ").put("qyi", "くぃ");
|
||||
builder.put("qwu", "くぅ");
|
||||
builder.put("qwe", "くぇ").put("qe", "くぇ").put("qye", "くぇ");
|
||||
builder.put("qwo", "くぉ").put("qo", "くぉ").put("kwo", "くぉ");
|
||||
|
||||
builder.put("ga", "が");
|
||||
builder.put("gi", "ぎ");
|
||||
builder.put("gu", "ぐ");
|
||||
builder.put("ge", "げ");
|
||||
builder.put("go", "ご");
|
||||
|
||||
builder.put("gya", "ぎゃ");
|
||||
builder.put("gyi", "ぎぃ");
|
||||
builder.put("gyu", "ぎゅ");
|
||||
builder.put("gye", "ぎぇ");
|
||||
builder.put("gyo", "ぎょ");
|
||||
|
||||
builder.put("gwa", "ぐぁ");
|
||||
builder.put("gwi", "ぐぃ");
|
||||
builder.put("gwu", "ぐぅ");
|
||||
builder.put("gwe", "ぐぇ");
|
||||
builder.put("gwo", "ぐぉ");
|
||||
|
||||
builder.put("lka", "ヵ").put("xka", "ヵ");
|
||||
//
|
||||
//
|
||||
builder.put("lke", "ヶ").put("xke", "ヶ");
|
||||
//
|
||||
|
||||
builder.put("sa", "さ");
|
||||
builder.put("si", "し").put("ci", "し").put("shi", "し");
|
||||
builder.put("su", "す");
|
||||
builder.put("se", "せ").put("ce", "せ");
|
||||
builder.put("so", "そ");
|
||||
|
||||
builder.put("sya", "しゃ").put("sha", "しゃ");
|
||||
builder.put("syi", "しぃ");
|
||||
builder.put("syu", "しゅ").put("shu", "しゅ");
|
||||
builder.put("sye", "しぇ").put("she", "しぇ");
|
||||
builder.put("syo", "しょ").put("sho", "しょ");
|
||||
|
||||
builder.put("swa", "すぁ");
|
||||
builder.put("swi", "すぃ");
|
||||
builder.put("swu", "すぅ");
|
||||
builder.put("swe", "すぇ");
|
||||
builder.put("swo", "すぉ");
|
||||
|
||||
builder.put("za", "ざ");
|
||||
builder.put("zi", "じ").put("ji", "じ");
|
||||
builder.put("zu", "ず");
|
||||
builder.put("ze", "ぜ");
|
||||
builder.put("zo", "ぞ");
|
||||
|
||||
builder.put("zya", "じゃ").put("ja", "じゃ").put("jya", "じゃ");
|
||||
builder.put("zyi", "じぃ")/* */.put("jyi", "じぃ");
|
||||
builder.put("zyu", "じゅ").put("ju", "じゅ").put("jyu", "じゅ");
|
||||
builder.put("zye", "じぇ").put("je", "じぇ").put("jye", "じぇ");
|
||||
builder.put("zyo", "じょ").put("jo", "じょ").put("jyo", "じょ");
|
||||
|
||||
builder.put("ta", "た");
|
||||
builder.put("ti", "ち").put("chi", "ち");
|
||||
builder.put("tu", "つ").put("tsu", "つ");
|
||||
builder.put("te", "て");
|
||||
builder.put("to", "と");
|
||||
|
||||
builder.put("tya", "ちゃ").put("cha", "ちゃ").put("cya", "ちゃ");
|
||||
builder.put("tyi", "ちぃ")/* */.put("cyi", "ちぃ");
|
||||
builder.put("tyu", "ちゅ").put("chu", "ちゅ").put("cyu", "ちゅ");
|
||||
builder.put("tye", "ちぇ").put("che", "ちぇ").put("cye", "ちぇ");
|
||||
builder.put("tyo", "ちょ").put("cho", "ちょ").put("cyo", "ちょ");
|
||||
|
||||
builder.put("tsa", "つぁ");
|
||||
builder.put("tsi", "つぃ");
|
||||
//
|
||||
builder.put("tse", "つぇ");
|
||||
builder.put("tso", "つぉ");
|
||||
|
||||
builder.put("tha", "てゃ");
|
||||
builder.put("thi", "てぃ");
|
||||
builder.put("thu", "てゅ");
|
||||
builder.put("the", "てぇ");
|
||||
builder.put("tho", "てょ");
|
||||
|
||||
builder.put("twa", "とぁ");
|
||||
builder.put("twi", "とぃ");
|
||||
builder.put("twu", "とぅ");
|
||||
builder.put("twe", "とぇ");
|
||||
builder.put("two", "とぉ");
|
||||
|
||||
builder.put("da", "だ");
|
||||
builder.put("di", "ぢ");
|
||||
builder.put("du", "づ");
|
||||
builder.put("de", "で");
|
||||
builder.put("do", "ど");
|
||||
|
||||
builder.put("dya", "ぢゃ");
|
||||
builder.put("dyi", "ぢぃ");
|
||||
builder.put("dyu", "ぢゅ");
|
||||
builder.put("dye", "ぢぇ");
|
||||
builder.put("dyo", "ぢょ");
|
||||
|
||||
builder.put("dha", "でゃ");
|
||||
builder.put("dhi", "でぃ");
|
||||
builder.put("dhu", "でゅ");
|
||||
builder.put("dhe", "でぇ");
|
||||
builder.put("dho", "でょ");
|
||||
|
||||
builder.put("dwa", "どぁ");
|
||||
builder.put("dwi", "どぃ");
|
||||
builder.put("dwu", "どぅ");
|
||||
builder.put("dwe", "どぇ");
|
||||
builder.put("dwo", "どぉ");
|
||||
|
||||
//
|
||||
//
|
||||
builder.put("ltu", "っ").put("xtu", "っ").put("ltsu", "っ").put("xtsu", "っ");
|
||||
//
|
||||
//
|
||||
|
||||
builder.put("na", "な");
|
||||
builder.put("ni", "に");
|
||||
builder.put("nu", "ぬ");
|
||||
builder.put("ne", "ね");
|
||||
builder.put("no", "の");
|
||||
|
||||
builder.put("nya", "にゃ");
|
||||
builder.put("nyi", "にぃ");
|
||||
builder.put("nyu", "にゅ");
|
||||
builder.put("nye", "にぇ");
|
||||
builder.put("nyo", "にょ");
|
||||
|
||||
builder.put("ha", "は");
|
||||
builder.put("hi", "ひ");
|
||||
builder.put("hu", "ふ").put("fu", "ふ");
|
||||
builder.put("he", "へ");
|
||||
builder.put("ho", "ほ");
|
||||
|
||||
builder.put("hya", "ひゃ");
|
||||
builder.put("hyi", "ひぃ");
|
||||
builder.put("hyu", "ひゅ");
|
||||
builder.put("hye", "ひぇ");
|
||||
builder.put("hyo", "ひょ");
|
||||
|
||||
builder.put("fwa", "ふぁ").put("fa", "ふぁ");
|
||||
builder.put("fwi", "ふぃ").put("fi", "ふぃ").put("fyi", "ふぃ");
|
||||
builder.put("fwu", "ふぅ");
|
||||
builder.put("fwe", "ふぇ").put("fe", "ふぇ").put("fye", "ふぇ");
|
||||
builder.put("fwo", "ふぉ").put("fo", "ふぉ");
|
||||
|
||||
builder.put("fya", "ふゃ");
|
||||
//
|
||||
builder.put("fyu", "ふゅ");
|
||||
//
|
||||
builder.put("fyo", "ふょ");
|
||||
|
||||
builder.put("ba", "ば");
|
||||
builder.put("bi", "び");
|
||||
builder.put("bu", "ぶ");
|
||||
builder.put("be", "べ");
|
||||
builder.put("bo", "ぼ");
|
||||
|
||||
builder.put("bya", "びゃ");
|
||||
builder.put("byi", "びぃ");
|
||||
builder.put("byu", "びゅ");
|
||||
builder.put("bye", "びぇ");
|
||||
builder.put("byo", "びょ");
|
||||
|
||||
builder.put("va", "ヴぁ");
|
||||
builder.put("vi", "ヴぃ");
|
||||
builder.put("vu", "ヴ");
|
||||
builder.put("ve", "ヴぇ");
|
||||
builder.put("vo", "ヴぉ");
|
||||
|
||||
builder.put("vya", "ヴゃ");
|
||||
builder.put("vyi", "ヴぃ");
|
||||
builder.put("vyu", "ヴゅ");
|
||||
builder.put("vye", "ヴぇ");
|
||||
builder.put("vyo", "ヴょ");
|
||||
|
||||
builder.put("pa", "ぱ");
|
||||
builder.put("pi", "ぴ");
|
||||
builder.put("pu", "ぷ");
|
||||
builder.put("pe", "ぺ");
|
||||
builder.put("po", "ぽ");
|
||||
|
||||
builder.put("pya", "ぴゃ");
|
||||
builder.put("pyi", "ぴぃ");
|
||||
builder.put("pyu", "ぴゅ");
|
||||
builder.put("pye", "ぴぇ");
|
||||
builder.put("pyo", "ぴょ");
|
||||
|
||||
builder.put("ma", "ま");
|
||||
builder.put("mi", "み");
|
||||
builder.put("mu", "む");
|
||||
builder.put("me", "め");
|
||||
builder.put("mo", "も");
|
||||
|
||||
builder.put("mya", "みゃ");
|
||||
builder.put("myi", "みぃ");
|
||||
builder.put("myu", "みゅ");
|
||||
builder.put("mye", "みぇ");
|
||||
builder.put("myo", "みょ");
|
||||
|
||||
builder.put("ya", "や");
|
||||
//
|
||||
builder.put("yu", "ゆ");
|
||||
//
|
||||
builder.put("yo", "よ");
|
||||
|
||||
builder.put("lya", "ゃ").put("xya", "ゃ");
|
||||
//
|
||||
builder.put("lyu", "ゅ").put("xyu", "ゅ");
|
||||
//
|
||||
builder.put("lyo", "ょ").put("xyo", "ょ");
|
||||
|
||||
builder.put("ra", "ら");
|
||||
builder.put("ri", "り");
|
||||
builder.put("ru", "る");
|
||||
builder.put("re", "れ");
|
||||
builder.put("ro", "ろ");
|
||||
|
||||
builder.put("rya", "りゃ");
|
||||
builder.put("ryi", "りぃ");
|
||||
builder.put("ryu", "りゅ");
|
||||
builder.put("rye", "りぇ");
|
||||
builder.put("ryo", "りょ");
|
||||
|
||||
builder.put("wa", "わ");
|
||||
//
|
||||
//
|
||||
//
|
||||
builder.put("wo", "を");
|
||||
|
||||
builder.put("lwa", "ゎ").put("xwa", "ゎ");
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
builder.put("n", "ん").put("nn", "ん").put("n'", "ん").put("xn", "ん");
|
||||
|
||||
// 促音を追加する
|
||||
for ( Map.Entry<String, String> entry : builder.build().entrySet() ) {
|
||||
String romaji = entry.getKey();
|
||||
String hiragana = entry.getValue();
|
||||
if ( canStartFromSokuon(romaji) ) {
|
||||
builder.put(romaji.charAt(0) + romaji, "っ" + hiragana);
|
||||
}
|
||||
}
|
||||
|
||||
// 記号とか
|
||||
builder.put("-", "ー");
|
||||
builder.put(",", "、");
|
||||
builder.put(".", "。");
|
||||
builder.put("?", "?");
|
||||
builder.put("!", "!");
|
||||
builder.put("[", "「").put("]", "」");
|
||||
builder.put("<", "<").put(">", ">");
|
||||
builder.put("&", "&");
|
||||
builder.put("\"", "”");
|
||||
builder.put("(", "(").put(")", ")");
|
||||
|
||||
MAP = builder.build();
|
||||
|
||||
ROMAJI_LIST = MAP.keySet().toArray(new String[0]);
|
||||
HIRAGANA_LIST = MAP.values().toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 「っ」や「ッ」などの促音から開始できるかどうか
|
||||
*
|
||||
* @param romaji 検証したい「ローマ字」
|
||||
* @return 促音から開始できるかどうか
|
||||
* @since 2.8.10
|
||||
*/
|
||||
private static boolean canStartFromSokuon(String romaji) {
|
||||
return !StringUtils.startsWithAny(romaji, "a", "i", "u", "e", "o", "n");
|
||||
}
|
||||
|
||||
/**
|
||||
* 「ローマ字」から「かな文字」に変換する
|
||||
*
|
||||
* @param romaji 変換元の「ローマ字」
|
||||
* @return 変換後の「かな文字」
|
||||
* @since 2.8.10
|
||||
*/
|
||||
public static String conv(String romaji) {
|
||||
return StringUtils.replaceEach(romaji, ROMAJI_LIST, HIRAGANA_LIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* 全角カッコを半角カッコに変換する (1.8以下のサーバーで全角カッコは表示できないため)
|
||||
*
|
||||
* @param text 変換元のテキスト
|
||||
* @return 全角カッコが半角カッコになったテキスト
|
||||
* @since 2.8.10
|
||||
*/
|
||||
public static String fixBrackets(String text) {
|
||||
String[] full = new String[] { "(", ")" };
|
||||
String[] half = new String[] { "(", ")" };
|
||||
return StringUtils.replaceEach(text, full, half);
|
||||
}
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.member;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.LunaChatMode;
|
||||
|
||||
/**
|
||||
* チャンネルメンバーの抽象クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public abstract class ChannelMember implements Comparable<ChannelMember> {
|
||||
|
||||
/**
|
||||
* オンラインかどうか
|
||||
* @return オンラインかどうか
|
||||
*/
|
||||
public abstract boolean isOnline();
|
||||
|
||||
/**
|
||||
* プレイヤー名を返す
|
||||
* @return プレイヤー名
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* プレイヤー表示名を返す
|
||||
* @return プレイヤー表示名
|
||||
*/
|
||||
public abstract String getDisplayName();
|
||||
|
||||
/**
|
||||
* プレフィックスを返す
|
||||
* @return プレフィックス
|
||||
*/
|
||||
public abstract String getPrefix();
|
||||
|
||||
/**
|
||||
* サフィックスを返す
|
||||
* @return サフィックス
|
||||
*/
|
||||
public abstract String getSuffix();
|
||||
|
||||
/**
|
||||
* メッセージを送る
|
||||
* @param message 送るメッセージ
|
||||
*/
|
||||
public abstract void sendMessage(String message);
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドのワールド名を取得する
|
||||
* @return ワールド名
|
||||
*/
|
||||
public abstract String getWorldName();
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードの権限を持っているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 権限を持っているかどうか
|
||||
*/
|
||||
public abstract boolean hasPermission(String node);
|
||||
|
||||
/**
|
||||
* 文字列表現を返す
|
||||
* @return 名前管理なら名前、UUID管理なら "$" + UUID を返す
|
||||
*/
|
||||
@Override
|
||||
public abstract String toString();
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードが定義されているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 定義を持っているかどうか
|
||||
*/
|
||||
public abstract boolean isPermissionSet(String node);
|
||||
|
||||
/**
|
||||
* 同一のオブジェクトかどうかを返す
|
||||
* @param other 他方のオブジェクト
|
||||
* @return 同一かどうか
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if ( !(other instanceof ChannelMember) ) {
|
||||
return false;
|
||||
}
|
||||
return this.toString().equals(other.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* インスタンス同士の比較を行う。このメソッドを実装しておくことで、
|
||||
* Java8でのHashMapのキー挿入における高速化が期待できる(らしい)。
|
||||
* @param other
|
||||
* @return
|
||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(ChannelMember other) {
|
||||
return this.toString().compareTo(other.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 名前またはUUIDから、ChannelMemberを作成して返す
|
||||
* @param nameOrUuid 名前、または、"$" + UUID
|
||||
* @return ChannelMember
|
||||
*/
|
||||
public static ChannelMember getChannelMember(String nameOrUuid) {
|
||||
if ( LunaChat.getMode() == LunaChatMode.BUKKIT ) {
|
||||
return ChannelMemberPlayer.getChannelMember(nameOrUuid);
|
||||
} else if ( LunaChat.getMode() == LunaChatMode.BUNGEE ) {
|
||||
return ChannelMemberProxiedPlayer.getChannelMember(nameOrUuid);
|
||||
}
|
||||
return null; // TODO standalone用のChannelMemberを返す
|
||||
}
|
||||
|
||||
/**
|
||||
* オブジェクトから、ChannelMemberを作成して返す
|
||||
* @param obj
|
||||
* @return ChannelMember
|
||||
*/
|
||||
public static ChannelMember getChannelMember(Object obj) {
|
||||
if ( LunaChat.getMode() == LunaChatMode.BUKKIT ) {
|
||||
return ChannelMemberBukkit.getChannelMemberBukkit(obj);
|
||||
} else if ( LunaChat.getMode() == LunaChatMode.BUNGEE ) {
|
||||
return ChannelMemberBungee.getChannelMemberBungee(obj);
|
||||
}
|
||||
return null; // TODO standalone用のChannelMemberを返す
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.member;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* ChannelMemberのBukkit-BlockCommandSender実装
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ChannelMemberBlock extends ChannelMemberBukkit {
|
||||
|
||||
BlockCommandSender sender;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param sender コマンドブロック
|
||||
*/
|
||||
public ChannelMemberBlock(BlockCommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* オンラインかどうか
|
||||
* @return 常にtrue
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#isOnline()
|
||||
*/
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤー名を返す
|
||||
* @return プレイヤー名
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤー表示名を返す
|
||||
* @return プレイヤー表示名
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getDisplayName()
|
||||
*/
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* プレフィックスを返す
|
||||
* @return 常に空文字列
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getPrefix()
|
||||
*/
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* サフィックスを返す
|
||||
* @return 常に空文字列
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getSuffix()
|
||||
*/
|
||||
@Override
|
||||
public String getSuffix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを送る、実際は何もせずにメッセージを捨てる
|
||||
* @param message
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#sendMessage(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* BukkitのPlayerを取得する
|
||||
* @return 常にnullが返される
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getPlayer()
|
||||
*/
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドのワールド名を取得する
|
||||
* @return 常に "-" が返される。
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getWorldName()
|
||||
*/
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
return "-";
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いる位置を取得する
|
||||
* @return 発言者の位置
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getLocation()
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
if ( sender != null ) {
|
||||
return sender.getBlock().getLocation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードの権限を持っているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 権限を持っているかどうか
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#hasPermission(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードが定義されているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 定義を持っているかどうか
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#isPermissionSet(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean isPermissionSet(String node) {
|
||||
return sender.isPermissionSet(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* IDを返す
|
||||
* @return 名前をそのまま返す
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getID()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return sender.getBlock().getWorld();
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.member;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* チャンネルメンバーのBukkit抽象クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public abstract class ChannelMemberBukkit extends ChannelMember {
|
||||
|
||||
/**
|
||||
* BukkitのPlayerを取得する
|
||||
* @return Player
|
||||
*/
|
||||
public abstract Player getPlayer();
|
||||
|
||||
/**
|
||||
* 発言者が今いる位置を取得する
|
||||
* @return 発言者の位置
|
||||
*/
|
||||
public abstract Location getLocation();
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドを取得する
|
||||
* @return 発言者の位置
|
||||
*/
|
||||
public abstract World getWorld();
|
||||
|
||||
/**
|
||||
* CommandSenderから、ChannelMemberを作成して返す
|
||||
* @param sender
|
||||
* @return ChannelMember
|
||||
*/
|
||||
public static ChannelMemberBukkit getChannelMemberBukkit(Object sender) {
|
||||
if ( sender == null || !(sender instanceof CommandSender) ) return null;
|
||||
if ( sender instanceof BlockCommandSender ) {
|
||||
return new ChannelMemberBlock((BlockCommandSender)sender);
|
||||
} else if ( sender instanceof ConsoleCommandSender ) {
|
||||
return new ChannelMemberBukkitConsole((ConsoleCommandSender)sender);
|
||||
} else {
|
||||
return ChannelMemberPlayer.getChannelPlayer((CommandSender)sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.member;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* ChannelMemberのBukkit-ConsoleCommandSender実装
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ChannelMemberBukkitConsole extends ChannelMemberBukkit {
|
||||
|
||||
ConsoleCommandSender sender;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param sender コンソール
|
||||
*/
|
||||
public ChannelMemberBukkitConsole(ConsoleCommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* オンラインかどうか
|
||||
* @return 常にtrue
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#isOnline()
|
||||
*/
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤー名を返す
|
||||
* @return プレイヤー名
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤー表示名を返す
|
||||
* @return プレイヤー表示名
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getDisplayName()
|
||||
*/
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* プレフィックスを返す
|
||||
* @return 常に空文字列
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getPrefix()
|
||||
*/
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* サフィックスを返す
|
||||
* @return 常に空文字列
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getSuffix()
|
||||
*/
|
||||
@Override
|
||||
public String getSuffix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを送る
|
||||
* @param message 送信するメッセージ
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#sendMessage(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* BukkitのPlayerを取得する
|
||||
* @return 常にnullが返される
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getPlayer()
|
||||
*/
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドのワールド名を取得する
|
||||
* @return 常に "-" が返される。
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getWorldName()
|
||||
*/
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
return "-";
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いる位置を取得する
|
||||
* @return 常にnullが返される
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getLocation()
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードの権限を持っているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 権限を持っているかどうか
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#hasPermission(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードが定義されているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 定義を持っているかどうか
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#isPermissionSet(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean isPermissionSet(String node) {
|
||||
return sender.isPermissionSet(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* IDを返す
|
||||
* @return 名前をそのまま返す
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getID()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.member;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
|
||||
/**
|
||||
* チャンネルメンバーのBungee抽象クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public abstract class ChannelMemberBungee extends ChannelMember {
|
||||
|
||||
/**
|
||||
* BungeeのProxiedPlayerを取得する
|
||||
* @return ProxiedPlayer
|
||||
*/
|
||||
public abstract ProxiedPlayer getPlayer();
|
||||
|
||||
/**
|
||||
* 発言者が今いるサーバーを取得する
|
||||
* @return サーバー
|
||||
*/
|
||||
public abstract Server getServer();
|
||||
|
||||
/**
|
||||
* CommandSenderから、ChannelMemberを作成して返す
|
||||
* @param sender
|
||||
* @return ChannelMember
|
||||
*/
|
||||
public static ChannelMemberBungee getChannelMemberBungee(Object sender) {
|
||||
if ( sender == null || !(sender instanceof CommandSender) ) return null;
|
||||
if ( sender instanceof ProxiedPlayer ) {
|
||||
return new ChannelMemberProxiedPlayer(((ProxiedPlayer)sender).getUniqueId());
|
||||
} else {
|
||||
return new ChannelMemberBungeeConsole((CommandSender)sender);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.member;
|
||||
|
||||
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.connection.Server;
|
||||
|
||||
/**
|
||||
* ChannelMemberのBungee-ConsoleCommandSender実装
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ChannelMemberBungeeConsole extends ChannelMemberBungee {
|
||||
|
||||
private CommandSender sender;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param sender ConsoleのCommandSender
|
||||
*/
|
||||
public ChannelMemberBungeeConsole(CommandSender sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* BungeeのProxiedPlayerを取得する
|
||||
* @return 常にnullが返される
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMemberBungee#getPlayer()
|
||||
*/
|
||||
@Override
|
||||
public ProxiedPlayer getPlayer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるサーバーを取得する
|
||||
* @return 常にnullが返される
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMemberBungee#getServer()
|
||||
*/
|
||||
@Override
|
||||
public Server getServer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者がオンラインかどうかを取得する
|
||||
* @return 常にtrueが返される
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMember#isOnline()
|
||||
*/
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者名を取得する
|
||||
* @return 発言者名
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMember#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者の表示名を取得する
|
||||
* @return 発言者の表示名
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMember#getDisplayName()
|
||||
*/
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return sender.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* プレフィックスを返す
|
||||
* @return 常に空文字列
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMember#getPrefix()
|
||||
*/
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* サフィックスを返す
|
||||
* @return 常に空文字列
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMember#getSuffix()
|
||||
*/
|
||||
@Override
|
||||
public String getSuffix() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者にメッセージを送信する
|
||||
* @param message メッセージ
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMember#sendMessage(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
sender.sendMessage(TextComponent.fromLegacyText(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールド名を返す
|
||||
* @return 常に"-"が返される
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMember#getWorldName()
|
||||
*/
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
return "-";
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードの権限を持っているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 権限を持っているかどうか
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMember#hasPermission(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
return sender.hasPermission(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードが定義されているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 定義を持っているかどうか
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMember#isPermissionSet(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean isPermissionSet(String node) {
|
||||
return sender.getPermissions().contains(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* IDを返す
|
||||
* @return 名前をそのまま返す
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMember#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
@@ -1,263 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.member;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc.bridge.VaultChatBridge;
|
||||
import com.github.ucchyocean.lc.bukkit.LunaChatBukkit;
|
||||
|
||||
/**
|
||||
* ChannelMemberのBukkitPlayer実装
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ChannelMemberPlayer extends ChannelMemberBukkit {
|
||||
|
||||
private UUID id;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param id プレイヤーID
|
||||
*/
|
||||
public ChannelMemberPlayer(String id) {
|
||||
this.id = UUID.fromString(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param id UUID
|
||||
*/
|
||||
public ChannelMemberPlayer(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤー名からUUIDを取得してChannelMemberPlayerを作成して返す
|
||||
* @param name プレイヤー名
|
||||
* @return ChannelMemberPlayer
|
||||
*/
|
||||
public static ChannelMemberPlayer getChannelMemberPlayerFromName(String name) {
|
||||
Player player = Bukkit.getPlayerExact(name);
|
||||
if ( player != null ) {
|
||||
return new ChannelMemberPlayer(player.getUniqueId());
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer offline = Bukkit.getOfflinePlayer(name);
|
||||
if ( offline != null && offline.getUniqueId() != null ) {
|
||||
return new ChannelMemberPlayer(offline.getUniqueId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* CommandSenderから、ChannelPlayerを作成して返す
|
||||
* @param sender
|
||||
* @return ChannelPlayer
|
||||
*/
|
||||
public static ChannelMemberPlayer getChannelPlayer(CommandSender sender) {
|
||||
if ( sender instanceof Player ) {
|
||||
return new ChannelMemberPlayer(((Player)sender).getUniqueId());
|
||||
}
|
||||
return new ChannelMemberPlayer(sender.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* オンラインかどうか
|
||||
* @return オンラインかどうか
|
||||
*/
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
Player player = Bukkit.getPlayer(id);
|
||||
return (player != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤー名を返す
|
||||
* @return プレイヤー名
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
Player player = Bukkit.getPlayer(id);
|
||||
if ( player != null ) {
|
||||
return player.getName();
|
||||
}
|
||||
OfflinePlayer offlineplayer = Bukkit.getOfflinePlayer(id);
|
||||
if ( offlineplayer != null ) {
|
||||
String name = offlineplayer.getName();
|
||||
return name;
|
||||
}
|
||||
return id.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤー表示名を返す
|
||||
* @return プレイヤー表示名
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getDisplayName()
|
||||
*/
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
Player player = getPlayer();
|
||||
if ( player != null ) {
|
||||
return player.getDisplayName();
|
||||
}
|
||||
return getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* プレフィックスを返す
|
||||
* @return プレフィックス
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getPrefix()
|
||||
*/
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
VaultChatBridge vault = LunaChatBukkit.getInstance().getVaultChat();
|
||||
if ( vault == null ) {
|
||||
return "";
|
||||
}
|
||||
Player player = getPlayer();
|
||||
if ( player != null ) {
|
||||
return vault.getPlayerPrefix(player);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* サフィックスを返す
|
||||
* @return サフィックス
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getSuffix()
|
||||
*/
|
||||
@Override
|
||||
public String getSuffix() {
|
||||
VaultChatBridge vault = LunaChatBukkit.getInstance().getVaultChat();
|
||||
if ( vault == null ) {
|
||||
return "";
|
||||
}
|
||||
Player player = getPlayer();
|
||||
if ( player != null ) {
|
||||
return vault.getPlayerSuffix(player);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを送る
|
||||
* @param message 送るメッセージ
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#sendMessage(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
Player player = getPlayer();
|
||||
if ( player != null ) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BukkitのPlayerを取得する
|
||||
* @return Player
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getPlayer()
|
||||
*/
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
return Bukkit.getPlayer(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドのワールド名を取得する
|
||||
* @return ワールド名
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getWorldName()
|
||||
*/
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
Player player = getPlayer();
|
||||
if ( player != null ) {
|
||||
return player.getWorld().getName();
|
||||
}
|
||||
return "-";
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いる位置を取得する
|
||||
* @return 発言者の位置
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getLocation()
|
||||
*/
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
Player player = getPlayer();
|
||||
if ( player != null ) {
|
||||
return player.getLocation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードの権限を持っているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 権限を持っているかどうか
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#hasPermission(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
Player player = getPlayer();
|
||||
if ( player == null ) {
|
||||
return false;
|
||||
} else {
|
||||
return player.hasPermission(node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードが定義されているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 定義を持っているかどうか
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#isPermissionSet(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean isPermissionSet(String node) {
|
||||
Player player = getPlayer();
|
||||
if ( player == null ) {
|
||||
return false;
|
||||
} else {
|
||||
return player.isPermissionSet(node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* IDを返す
|
||||
* @return "$" + UUID を返す
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getID()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "$" + id.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
Player player = getPlayer();
|
||||
if ( player != null ) return player.getWorld();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ChannelMemberPlayer getChannelMember(String nameOrUuid) {
|
||||
if ( nameOrUuid.startsWith("$") ) {
|
||||
return new ChannelMemberPlayer(nameOrUuid.substring(1));
|
||||
} else {
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(nameOrUuid);
|
||||
if ( op == null ) return null;
|
||||
return new ChannelMemberPlayer(op.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.member;
|
||||
|
||||
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;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
|
||||
/**
|
||||
* ChannelMemberのBungeeCord-ProxiedPlayer実装
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ChannelMemberProxiedPlayer extends ChannelMemberBungee {
|
||||
|
||||
private UUID id;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param id プレイヤーID
|
||||
*/
|
||||
public ChannelMemberProxiedPlayer(String id) {
|
||||
this.id = UUID.fromString(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param id UUID
|
||||
*/
|
||||
public ChannelMemberProxiedPlayer(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤー名からUUIDを取得してChannelMemberProxiedPlayerを作成して返す
|
||||
* @param nameOrUuid 名前、または、"$" + UUID
|
||||
* @return ChannelMemberProxiedPlayer
|
||||
*/
|
||||
public static ChannelMemberProxiedPlayer getChannelMember(String nameOrUuid) {
|
||||
ProxiedPlayer player = null;
|
||||
if ( nameOrUuid.startsWith("$") ) {
|
||||
player = ProxyServer.getInstance().getPlayer(
|
||||
UUID.fromString(nameOrUuid.substring(1)));
|
||||
} else {
|
||||
player = ProxyServer.getInstance().getPlayer(nameOrUuid);
|
||||
}
|
||||
if ( player != null ) {
|
||||
return new ChannelMemberProxiedPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
// TODO オフラインプレイヤーのUUIDを取得する方法を検討する
|
||||
|
||||
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 オンラインかどうか
|
||||
*/
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return (ProxyServer.getInstance().getPlayer(id) != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤー名を返す
|
||||
* @return プレイヤー名
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
ProxiedPlayer player = getPlayer();
|
||||
if ( player != null ) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
// TODO 接続していないプレイヤーのUUIDを取得する方法を検討する
|
||||
|
||||
return id.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤー表示名を返す
|
||||
* @return プレイヤー表示名
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getDisplayName()
|
||||
*/
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
ProxiedPlayer player = getPlayer();
|
||||
if ( player != null ) {
|
||||
return player.getDisplayName();
|
||||
}
|
||||
return getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* プレフィックスを返す
|
||||
* @return プレフィックス
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getPrefix()
|
||||
*/
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
|
||||
// TODO 未実装
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* サフィックスを返す
|
||||
* @return サフィックス
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getSuffix()
|
||||
*/
|
||||
@Override
|
||||
public String getSuffix() {
|
||||
|
||||
// TODO 未実装
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを送る
|
||||
* @param message 送るメッセージ
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#sendMessage(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
ProxiedPlayer player = getPlayer();
|
||||
if ( player != null ) {
|
||||
player.sendMessage(TextComponent.fromLegacyText(message));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドのワールド名を取得する
|
||||
* @return ワールド名
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getWorldName()
|
||||
*/
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
return "-";
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードの権限を持っているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 権限を持っているかどうか
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#hasPermission(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
ProxiedPlayer player = getPlayer();
|
||||
if ( player == null ) {
|
||||
return false;
|
||||
} else {
|
||||
return player.hasPermission(node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* IDを返す
|
||||
* @return "$" + UUID を返す
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getID()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "$" + id.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* ProxiedPlayerを取得して返す
|
||||
* @return ProxiedPlayer
|
||||
*/
|
||||
@Override
|
||||
public @Nullable ProxiedPlayer getPlayer() {
|
||||
return ProxyServer.getInstance().getPlayer(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるサーバーを取得する
|
||||
* @return サーバー
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMemberBungee#getServer()
|
||||
*/
|
||||
@Override
|
||||
public @Nullable Server getServer() {
|
||||
ProxiedPlayer player = getPlayer();
|
||||
if ( player != null ) {
|
||||
return player.getServer();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードが定義されているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
* @return 定義を持っているかどうか
|
||||
* @see com.github.ucchyocean.lc.member.ChannelMember#isPermissionSet(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean isPermissionSet(String node) {
|
||||
// TODO 要テスト
|
||||
ProxiedPlayer player = getPlayer();
|
||||
if ( player != null ) {
|
||||
return player.getPermissions().contains(node);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc.standalone;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import com.github.ucchyocean.lc.LunaChat;
|
||||
import com.github.ucchyocean.lc.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc.LunaChatLogger;
|
||||
import com.github.ucchyocean.lc.LunaChatMode;
|
||||
import com.github.ucchyocean.lc.PluginInterface;
|
||||
import com.github.ucchyocean.lc.channel.ChannelManager;
|
||||
|
||||
/**
|
||||
* LunaChatのスタンドアロンサーバー
|
||||
* @author ucchy
|
||||
*/
|
||||
public class LunaChatStandalone implements PluginInterface {
|
||||
|
||||
private LunaChatConfig config;
|
||||
private ChannelManager manager;
|
||||
|
||||
public void onEnable() {
|
||||
|
||||
LunaChat.setPlugin(this);
|
||||
LunaChat.setMode(LunaChatMode.STANDALONE);
|
||||
|
||||
// 初期化
|
||||
manager = new ChannelManager();
|
||||
|
||||
// コンフィグ取得
|
||||
config = new LunaChatConfig(getDataFolder(), getPluginJarFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getPluginJarFile() {
|
||||
try {
|
||||
return new File(LunaChatStandalone.class
|
||||
.getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LunaChatConfig getLunaChatConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LunaChatAPI getLunaChatAPI() {
|
||||
return manager ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
|
||||
// 現在のフォルダ下にLunaChatフォルダを作成して返す
|
||||
String cd = new File(".").getAbsoluteFile().getParent();
|
||||
File folder = new File(cd, "LunaChat");
|
||||
if ( !folder.exists() ) folder.mkdirs();
|
||||
return folder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LunaChatLogger getNormalChatLogger() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする