LunaChat v2.6.0 : Refactored. Devide implements from Channel.
このコミットが含まれているのは:
1 親
4eae2d9785
コミット
cf719a8bd4
10ファイル変更
+811
-639
検索条件に一致するファイルはありません
@@ -13,7 +13,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import com.github.ucchyocean.lc.bridge.DynmapBridge;
|
||||
import com.github.ucchyocean.lc.bridge.VaultChatBridge;
|
||||
@@ -38,20 +37,13 @@ public class LunaChat extends JavaPlugin {
|
||||
private VaultChatBridge vaultchat;
|
||||
private DynmapBridge dynmap;
|
||||
|
||||
private BukkitTask expireCheckerTask;
|
||||
private ExpireCheckTask expireCheckerTask;
|
||||
|
||||
private LunaChatCommand lunachatCommand;
|
||||
private LunaChatMessageCommand messageCommand;
|
||||
private LunaChatReplyCommand replyCommand;
|
||||
private LunaChatJapanizeCommand lcjapanizeCommand;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
*/
|
||||
public LunaChat() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* プラグインが有効化されたときに呼び出されるメソッド
|
||||
* @see org.bukkit.plugin.java.JavaPlugin#onEnable()
|
||||
@@ -92,9 +84,8 @@ public class LunaChat extends JavaPlugin {
|
||||
ConfigurationSerialization.registerClass(Channel.class, "Channel");
|
||||
|
||||
// 期限チェッカータスクの起動
|
||||
expireCheckerTask =
|
||||
getServer().getScheduler().runTaskTimer(
|
||||
this, new ExpireCheckTask(), 100, 1200);
|
||||
expireCheckerTask = new ExpireCheckTask();
|
||||
expireCheckerTask.runTaskTimer(this, 100, 1200);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +97,7 @@ public class LunaChat extends JavaPlugin {
|
||||
|
||||
// 期限チェッカータスクの停止
|
||||
if ( expireCheckerTask != null ) {
|
||||
getServer().getScheduler().cancelTask(expireCheckerTask.getTaskId());
|
||||
expireCheckerTask.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,12 @@ public class LunaChatConfig {
|
||||
/** formatコマンド実行時に、必ず含まれる必要があるキーワード。 */
|
||||
private List<String> formatConstraint;
|
||||
|
||||
/** チャンネルを作成したときに、デフォルトで設定されるフォーマット */
|
||||
private String defaultFormat;
|
||||
|
||||
/** プライベートメッセージを送信するときに、適用されるフォーマット */
|
||||
private String defaultFormatForPrivateMessage;
|
||||
|
||||
/** ブロードキャストチャンネルの発言内容を、dynmapに送信するかどうか。<br/>
|
||||
* dynmapがロードされていない場合は、この設定は無視される(false扱い)。 */
|
||||
private boolean sendBroadcastChannelChatToDynmap;
|
||||
@@ -164,6 +170,12 @@ public class LunaChatConfig {
|
||||
formatConstraint.add("%msg");
|
||||
}
|
||||
|
||||
defaultFormat = config.getString("defaultFormat",
|
||||
"&f[%color%ch&f]%prefix%username%suffix&a:&f %msg");
|
||||
defaultFormatForPrivateMessage =
|
||||
config.getString("defaultFormatForPrivateMessage",
|
||||
"&7[%player > %to] %msg");
|
||||
|
||||
sendBroadcastChannelChatToDynmap =
|
||||
config.getBoolean("sendBroadcastChannelChatToDynmap", true);
|
||||
sendFormattedMessageToDynmap =
|
||||
@@ -293,6 +305,22 @@ public class LunaChatConfig {
|
||||
return formatConstraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルを作成したときに、デフォルトで設定されるフォーマット。
|
||||
* @return defaultFormatを返す
|
||||
*/
|
||||
public String getDefaultFormat() {
|
||||
return defaultFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* プライベートメッセージを送信するときに、適用されるフォーマット。
|
||||
* @return defaultFormatForPrivateMessageを返す
|
||||
*/
|
||||
public String getDefaultFormatForPrivateMessage() {
|
||||
return defaultFormatForPrivateMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* NGワード
|
||||
* @return ngwordを返す
|
||||
|
||||
@@ -19,10 +19,8 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
*/
|
||||
public class LunaChatLogger {
|
||||
|
||||
private static final SimpleDateFormat lformat =
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private static final SimpleDateFormat dformat =
|
||||
new SimpleDateFormat("yyyy-MM-dd");
|
||||
private SimpleDateFormat lformat;
|
||||
private SimpleDateFormat dformat;
|
||||
|
||||
private File file;
|
||||
private String dirPath;
|
||||
@@ -34,6 +32,9 @@ public class LunaChatLogger {
|
||||
*/
|
||||
public LunaChatLogger(String name) {
|
||||
|
||||
lformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
dformat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
this.name = name;
|
||||
checkDir();
|
||||
}
|
||||
@@ -80,8 +81,7 @@ public class LunaChatLogger {
|
||||
private void checkDir() {
|
||||
|
||||
String temp = LunaChat.getInstance().getDataFolder() +
|
||||
File.separator + "logs" + File.separator +
|
||||
dformat.format(new Date());
|
||||
File.separator + "logs" + File.separator + dformat.format(new Date());
|
||||
|
||||
if ( temp.equals(dirPath) ) {
|
||||
return;
|
||||
|
||||
@@ -14,8 +14,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
@@ -25,63 +23,18 @@ 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.NGWordAction;
|
||||
import com.github.ucchyocean.lc.Resources;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.bridge.DynmapBridge;
|
||||
import com.github.ucchyocean.lc.bridge.VaultChatBridge;
|
||||
import com.github.ucchyocean.lc.event.LunaChatChannelChatEvent;
|
||||
import com.github.ucchyocean.lc.event.LunaChatChannelMemberChangedEvent;
|
||||
import com.github.ucchyocean.lc.event.LunaChatChannelMessageEvent;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
|
||||
/**
|
||||
* チャンネル
|
||||
* @author ucchy
|
||||
*/
|
||||
@SerializableAs("Channel")
|
||||
public class Channel implements ConfigurationSerializable {
|
||||
public abstract class Channel implements ConfigurationSerializable {
|
||||
|
||||
private static final String FOLDER_NAME_CHANNELS = "channels";
|
||||
|
||||
private static final String INFO_FIRSTLINE = Resources.get("channelInfoFirstLine");
|
||||
private static final String INFO_PREFIX = Resources.get("channelInfoPrefix");
|
||||
private static final String INFO_GLOBAL = Resources.get("channelInfoGlobal");
|
||||
private static final String INFO_BROADCAST = Resources.get("channelInfoBroadcast");
|
||||
private static final String INFO_SECRET = Resources.get("channelInfoSecret");
|
||||
private static final String INFO_PASSWORD = Resources.get("channelInfoPassword");
|
||||
private static final String INFO_WORLDCHAT = Resources.get("channelInfoWorldChat");
|
||||
private static final String INFO_RANGECHAT = Resources.get("channelInfoRangeChat");
|
||||
private static final String INFO_FORMAT = Resources.get("channelInfoFormat");
|
||||
private static final String INFO_BANNED = Resources.get("channelInfoBanned");
|
||||
private static final String INFO_MUTED = Resources.get("channelInfoMuted");
|
||||
|
||||
private static final String LIST_ENDLINE = Resources.get("listEndLine");
|
||||
private static final String LIST_FORMAT = Resources.get("listFormat");
|
||||
|
||||
private static final String DEFAULT_FORMAT = Resources.get("defaultFormat");
|
||||
private static final String DEFAULT_FORMAT_FOR_PERSONAL =
|
||||
Resources.get("defaultFormatForPersonalChat");
|
||||
private static final String MSG_JOIN = Resources.get("joinMessage");
|
||||
private static final String MSG_QUIT = Resources.get("quitMessage");
|
||||
private static final String MSG_BAN_EXPIRED = Resources.get("expiredBan");
|
||||
private static final String MSG_MUTE_EXPIRED = Resources.get("expiredMute");
|
||||
private static final String MSG_BAN_EXPIRED_PLAYER = Resources.get("cmdmsgPardoned");
|
||||
private static final String MSG_MUTE_EXPIRED_PLAYER = Resources.get("cmdmsgUnmuted");
|
||||
|
||||
private static final String PREINFO = Resources.get("infoPrefix");
|
||||
private static final String PREERR = Resources.get("errorPrefix");
|
||||
|
||||
private static final String NGWORD_PREFIX = Resources.get("ngwordPrefix");
|
||||
private static final String MSG_KICKED = Resources.get("cmdmsgKicked");
|
||||
private static final String MSG_BANNED = Resources.get("cmdmsgBanned");
|
||||
private static final String MSG_MUTED = Resources.get("cmdmsgMuted");
|
||||
|
||||
private static final String MSG_NO_RECIPIENT = Resources.get("noRecipientMessage");
|
||||
|
||||
private static final String ERRMSG_MUTED = Resources.get("errmsgMuted");
|
||||
|
||||
private static final String KEY_NAME = "name";
|
||||
private static final String KEY_DESC = "desc";
|
||||
private static final String KEY_FORMAT = "format";
|
||||
@@ -158,24 +111,12 @@ public class Channel implements ConfigurationSerializable {
|
||||
/** 1:1チャットの相手名 */
|
||||
private String privateMessageTo;
|
||||
|
||||
/** ロガー */
|
||||
private LunaChatLogger logger;
|
||||
|
||||
/** コンフィグ */
|
||||
private LunaChatConfig config;
|
||||
|
||||
/** API */
|
||||
private LunaChatAPI api;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param name チャンネルの名称
|
||||
*/
|
||||
protected Channel(String name) {
|
||||
|
||||
this.config = LunaChat.getInstance().getLunaChatConfig();
|
||||
this.api = LunaChat.getInstance().getLunaChatAPI();
|
||||
|
||||
this.name = name;
|
||||
this.description = "";
|
||||
this.members = new ArrayList<String>();
|
||||
@@ -193,11 +134,11 @@ public class Channel implements ConfigurationSerializable {
|
||||
this.muteExpires = new HashMap<String, Long>();
|
||||
this.privateMessageTo = "";
|
||||
|
||||
LunaChatConfig config = LunaChat.getInstance().getLunaChatConfig();
|
||||
if ( isPersonalChat() ) {
|
||||
this.format = DEFAULT_FORMAT_FOR_PERSONAL;
|
||||
this.format = config.getDefaultFormatForPrivateMessage();
|
||||
} else {
|
||||
this.format = DEFAULT_FORMAT;
|
||||
logger = new LunaChatLogger(name);
|
||||
this.format = config.getDefaultFormat();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,14 +160,16 @@ public class Channel implements ConfigurationSerializable {
|
||||
* @return グローバルチャンネルかどうか
|
||||
*/
|
||||
public boolean isGlobalChannel() {
|
||||
return name.equals(config.getGlobalChannel());
|
||||
LunaChatConfig config = LunaChat.getInstance().getLunaChatConfig();
|
||||
return getName().equals(config.getGlobalChannel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 強制参加チャンネルかどうか
|
||||
*/
|
||||
public boolean isForceJoinChannel() {
|
||||
return config.getForceJoinChannels().contains(name);
|
||||
LunaChatConfig config = LunaChat.getInstance().getLunaChatConfig();
|
||||
return config.getForceJoinChannels().contains(getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,127 +187,7 @@ public class Channel implements ConfigurationSerializable {
|
||||
* @param player 発言をするプレイヤー
|
||||
* @param message 発言をするメッセージ
|
||||
*/
|
||||
public void chat(Player player, String message) {
|
||||
|
||||
// Muteされているかどうかを確認する
|
||||
if ( player != null && muted.contains(player.getName()) ) {
|
||||
player.sendMessage( PREERR + ERRMSG_MUTED );
|
||||
return;
|
||||
}
|
||||
|
||||
String preReplaceMessage = message;
|
||||
|
||||
// 一時的にJapanizeスキップ設定かどうかを確認する
|
||||
boolean skipJapanize = false;
|
||||
String marker = config.getNoneJapanizeMarker();
|
||||
if ( !marker.equals("") && message.startsWith(marker) ) {
|
||||
skipJapanize = true;
|
||||
message = message.substring(marker.length());
|
||||
}
|
||||
|
||||
// NGワード発言をしたかどうかのチェックとマスク
|
||||
boolean isNG = false;
|
||||
String maskedMessage = message;
|
||||
for ( String word : config.getNgword() ) {
|
||||
if ( maskedMessage.contains(word) ) {
|
||||
maskedMessage = maskedMessage.replace(
|
||||
word, Utility.getAstariskString(word.length()));
|
||||
isNG = true;
|
||||
}
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
String msgFormat = replaceKeywords(format, player);
|
||||
|
||||
// カラーコード置き換え
|
||||
maskedMessage = Utility.replaceColorCode(maskedMessage);
|
||||
|
||||
// イベントコール
|
||||
LunaChatChannelChatEvent event =
|
||||
new LunaChatChannelChatEvent(this.name, player,
|
||||
preReplaceMessage, maskedMessage, msgFormat);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if ( event.isCancelled() ) {
|
||||
return;
|
||||
}
|
||||
msgFormat = event.getMessageFormat();
|
||||
maskedMessage = event.getNgMaskedMessage();
|
||||
|
||||
// 2byteコードを含むか、半角カタカナのみなら、Japanize変換は行わない
|
||||
if ( !skipJapanize &&
|
||||
( message.getBytes().length > message.length() ||
|
||||
message.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
skipJapanize = true;
|
||||
}
|
||||
|
||||
// Japanize変換タスクを作成する
|
||||
boolean isIncludeSyncChat = true;
|
||||
DelayedJapanizeConvertTask delayedTask = null;
|
||||
if ( !skipJapanize &&
|
||||
api.isPlayerJapanize(player.getName()) &&
|
||||
config.getJapanizeType() != JapanizeType.NONE ) {
|
||||
|
||||
int lineType = config.getJapanizeDisplayLine();
|
||||
String jpFormat;
|
||||
String messageFormat = null;
|
||||
if ( lineType == 1 ) {
|
||||
jpFormat = config.getJapanizeLine1Format();
|
||||
messageFormat = msgFormat;
|
||||
isIncludeSyncChat = false;
|
||||
} else {
|
||||
jpFormat = config.getJapanizeLine2Format();
|
||||
}
|
||||
|
||||
// タスクを作成しておく
|
||||
delayedTask = new DelayedJapanizeConvertTask(maskedMessage,
|
||||
config.getJapanizeType(),
|
||||
this, player, jpFormat, messageFormat);
|
||||
}
|
||||
|
||||
if ( isIncludeSyncChat ) {
|
||||
// メッセージの送信
|
||||
sendMessage(player, maskedMessage, msgFormat, true);
|
||||
}
|
||||
|
||||
// 非同期実行タスクがある場合、追加で実行する
|
||||
if ( delayedTask != null ) {
|
||||
delayedTask.runTaskAsynchronously(LunaChat.getInstance());
|
||||
}
|
||||
|
||||
// NGワード発言者に、NGワードアクションを実行する
|
||||
if ( isNG && player != null ) {
|
||||
if ( config.getNgwordAction() == NGWordAction.BAN ) {
|
||||
// BANする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
banned.add(player.getName());
|
||||
removeMember(player.getName());
|
||||
String temp = PREINFO + NGWORD_PREFIX + MSG_BANNED;
|
||||
String m = String.format(temp, name);
|
||||
player.sendMessage(m);
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.KICK ) {
|
||||
// キックする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
removeMember(player.getName());
|
||||
String temp = PREINFO + NGWORD_PREFIX + MSG_KICKED;
|
||||
String m = String.format(temp, name);
|
||||
player.sendMessage(m);
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.MUTE ) {
|
||||
// Muteする
|
||||
|
||||
muted.add(player.getName());
|
||||
save();
|
||||
String temp = PREINFO + NGWORD_PREFIX + MSG_MUTED;
|
||||
String m = String.format(temp, name);
|
||||
player.sendMessage(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
public abstract void chat(Player player, String message);
|
||||
|
||||
/**
|
||||
* ほかの連携先などから、このチャットに発言する
|
||||
@@ -372,32 +195,7 @@ public class Channel implements ConfigurationSerializable {
|
||||
* @param source 連携元を判別する文字列
|
||||
* @param message メッセージ
|
||||
*/
|
||||
public void chatFromOtherSource(String player, String source, String message) {
|
||||
|
||||
// 表示名
|
||||
String name = player + "@" + source;
|
||||
|
||||
// NGワード発言のマスク
|
||||
String maskedMessage = message;
|
||||
for ( String word : config.getNgword() ) {
|
||||
if ( maskedMessage.contains(word) ) {
|
||||
maskedMessage = maskedMessage.replace(
|
||||
word, Utility.getAstariskString(word.length()));
|
||||
}
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
String msgFormat = replaceKeywords(format, null);
|
||||
msgFormat = msgFormat.replace("%username", name);
|
||||
msgFormat = msgFormat.replace("%prefix", "");
|
||||
msgFormat = msgFormat.replace("%suffix", "");
|
||||
|
||||
// カラーコード置き換え
|
||||
maskedMessage = Utility.replaceColorCode(maskedMessage);
|
||||
|
||||
// メッセージの送信
|
||||
sendMessage(null, maskedMessage, msgFormat, false);
|
||||
}
|
||||
public abstract void chatFromOtherSource(String player, String source, String message);
|
||||
|
||||
/**
|
||||
* メンバーを追加する
|
||||
@@ -405,23 +203,30 @@ public class Channel implements ConfigurationSerializable {
|
||||
*/
|
||||
public void addMember(String name) {
|
||||
|
||||
// 既に参加しているなら、何もしない
|
||||
if ( members.contains(name) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 変更後のメンバーリストを作成
|
||||
ArrayList<String> after = new ArrayList<String>(members);
|
||||
after.add(name);
|
||||
|
||||
// イベントコール
|
||||
LunaChatChannelMemberChangedEvent event =
|
||||
new LunaChatChannelMemberChangedEvent(this.name, this.members);
|
||||
new LunaChatChannelMemberChangedEvent(this.name, this.members, after);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if ( event.isCancelled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// メンバー追加
|
||||
// メンバー更新
|
||||
if ( members.size() == 0 && moderator.size() == 0 ) {
|
||||
moderator.add(name);
|
||||
}
|
||||
if ( !members.contains(name) ) {
|
||||
members.add(name);
|
||||
sendJoinQuitMessage(true, name);
|
||||
save();
|
||||
}
|
||||
members = after;
|
||||
sendJoinQuitMessage(true, name);
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -430,9 +235,18 @@ public class Channel implements ConfigurationSerializable {
|
||||
*/
|
||||
public void removeMember(String name) {
|
||||
|
||||
// 既に削除しているなら、何もしない
|
||||
if ( !members.contains(name) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 変更後のメンバーリストを作成
|
||||
ArrayList<String> after = new ArrayList<String>(members);
|
||||
after.remove(name);
|
||||
|
||||
// イベントコール
|
||||
LunaChatChannelMemberChangedEvent event =
|
||||
new LunaChatChannelMemberChangedEvent(this.name, this.members);
|
||||
new LunaChatChannelMemberChangedEvent(this.name, this.members, after);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if ( event.isCancelled() ) {
|
||||
return;
|
||||
@@ -440,21 +254,21 @@ public class Channel implements ConfigurationSerializable {
|
||||
|
||||
// デフォルト発言先が退出するチャンネルと一致する場合、
|
||||
// デフォルト発言先を削除する
|
||||
LunaChatAPI api = LunaChat.getInstance().getLunaChatAPI();
|
||||
Channel def = api.getDefaultChannel(name);
|
||||
if ( def != null && def.name.equals(this.name) ) {
|
||||
api.removeDefaultChannel(name);
|
||||
}
|
||||
|
||||
// 実際にメンバーから削除する
|
||||
if ( members.contains(name) ) {
|
||||
members.remove(name);
|
||||
sendJoinQuitMessage(false, name);
|
||||
if ( config.isZeroMemberRemove() && members.size() <= 0 ) {
|
||||
api.removeChannel(this.name);
|
||||
return;
|
||||
} else {
|
||||
save();
|
||||
}
|
||||
members.remove(name);
|
||||
sendJoinQuitMessage(false, name);
|
||||
|
||||
// 0人で削除する設定がオンで、0人になったなら、チャンネルを削除する
|
||||
LunaChatConfig config = LunaChat.getInstance().getLunaChatConfig();
|
||||
if ( config.isZeroMemberRemove() && members.size() <= 0 ) {
|
||||
api.removeChannel(this.name);
|
||||
return;
|
||||
}
|
||||
|
||||
// 非表示設定プレイヤーだったら、リストから削除する
|
||||
@@ -466,6 +280,8 @@ public class Channel implements ConfigurationSerializable {
|
||||
if ( moderator.contains(name) ) {
|
||||
moderator.remove(name);
|
||||
}
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -473,25 +289,7 @@ public class Channel implements ConfigurationSerializable {
|
||||
* @param isJoin 入室かどうか(falseなら退室)
|
||||
* @param player 入退室したプレイヤー名
|
||||
*/
|
||||
private void sendJoinQuitMessage(boolean isJoin, String player) {
|
||||
|
||||
// 1:1チャットなら、入退室メッセージは表示しない
|
||||
if ( isPersonalChat() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
String msg;
|
||||
if ( isJoin ) {
|
||||
msg = MSG_JOIN;
|
||||
} else {
|
||||
msg = MSG_QUIT;
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
msg = replaceKeywordsForSystemMessages(msg, player);
|
||||
|
||||
sendMessage(null, msg, null, false);
|
||||
}
|
||||
protected abstract void sendJoinQuitMessage(boolean isJoin, String player);
|
||||
|
||||
/**
|
||||
* メッセージを表示します。指定したプレイヤーの発言として処理されます。
|
||||
@@ -500,235 +298,15 @@ public class Channel implements ConfigurationSerializable {
|
||||
* @param format フォーマット
|
||||
* @param sendDynmap dynmapへ送信するかどうか
|
||||
*/
|
||||
protected void sendMessage(Player player, String message,
|
||||
String format, boolean sendDynmap) {
|
||||
|
||||
String originalMessage = new String(message);
|
||||
|
||||
// 受信者を設定する
|
||||
ArrayList<Player> recipients = new ArrayList<Player>();
|
||||
boolean isRangeChat = false;
|
||||
|
||||
if ( isBroadcastChannel() ) {
|
||||
// ブロードキャストチャンネル
|
||||
|
||||
if ( isWorldRange && player != null ) {
|
||||
isRangeChat = true;
|
||||
World w = player.getWorld();
|
||||
|
||||
if ( chatRange > 0 ) {
|
||||
// 範囲チャット
|
||||
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
if ( p.getWorld().equals(w) &&
|
||||
player.getLocation().distance(p.getLocation()) <= chatRange &&
|
||||
!hided.contains(p.getName()) ) {
|
||||
recipients.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// ワールドチャット
|
||||
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
if ( p.getWorld().equals(w) && !hided.contains(p.getName()) ) {
|
||||
recipients.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// 通常ブロードキャスト(全員へ送信)
|
||||
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
if ( !hided.contains(p.getName()) ) {
|
||||
recipients.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// 通常チャンネル
|
||||
|
||||
for ( String name : members ) {
|
||||
Player p = Utility.getPlayerExact(name);
|
||||
if ( p != null && !hided.contains(p.getName()) ) {
|
||||
recipients.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// フォーマットがある場合は置き換える
|
||||
if ( format != null ) {
|
||||
message = format.replace("%msg", message);
|
||||
}
|
||||
|
||||
// イベントコール
|
||||
LunaChatChannelMessageEvent event =
|
||||
new LunaChatChannelMessageEvent(
|
||||
name, player, message, recipients);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
message = event.getMessage();
|
||||
recipients = event.getRecipients();
|
||||
|
||||
// 通常ブロードキャストなら、設定に応じてdynmapへ送信する
|
||||
DynmapBridge dynmap = LunaChat.getInstance().getDynmap();
|
||||
if ( config.isSendBroadcastChannelChatToDynmap() &&
|
||||
sendDynmap &&
|
||||
dynmap != null &&
|
||||
isBroadcastChannel() &&
|
||||
!isWorldRange ) {
|
||||
if ( config.isSendFormattedMessageToDynmap() ) {
|
||||
if ( player != null ) {
|
||||
dynmap.chat(player, message);
|
||||
} else {
|
||||
dynmap.broadcast(message);
|
||||
}
|
||||
} else {
|
||||
if ( player != null ) {
|
||||
dynmap.chat(player, originalMessage);
|
||||
} else {
|
||||
dynmap.broadcast(originalMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 送信する
|
||||
for ( Player p : recipients ) {
|
||||
p.sendMessage(message);
|
||||
}
|
||||
|
||||
// 受信者が自分以外いない場合は、メッセージを表示する
|
||||
if ( isRangeChat && (
|
||||
recipients.size() == 0 ||
|
||||
(recipients.size() == 1 &&
|
||||
recipients.get(0).getName().equals(player.getName()) ) ) ) {
|
||||
String msg = replaceKeywordsForSystemMessages(MSG_NO_RECIPIENT, "");
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
|
||||
// ロギング
|
||||
log(message);
|
||||
}
|
||||
protected abstract void sendMessage(
|
||||
Player player, String message, String format, boolean sendDynmap);
|
||||
|
||||
/**
|
||||
* チャンネル情報を返す
|
||||
* @param forModerator モデレータ向けの情報を含めるかどうか
|
||||
* @return チャンネル情報
|
||||
*/
|
||||
public ArrayList<String> getInfo(boolean forModerator) {
|
||||
|
||||
ArrayList<String> info = new ArrayList<String>();
|
||||
info.add(INFO_FIRSTLINE);
|
||||
|
||||
// チャンネル名、参加人数、総人数、チャンネル説明文
|
||||
info.add( String.format(
|
||||
LIST_FORMAT, name, getOnlineNum(), getTotalNum(), description) );
|
||||
|
||||
// 参加メンバー一覧
|
||||
if ( isGlobalChannel() ) {
|
||||
info.add(INFO_GLOBAL);
|
||||
} else if ( isBroadcastChannel() ) {
|
||||
info.add(INFO_BROADCAST);
|
||||
} else {
|
||||
// メンバーを、5人ごとに表示する
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX);
|
||||
|
||||
for ( int i=0; i<members.size(); i++ ) {
|
||||
|
||||
if ( i%5 == 0 && i != 0 ) {
|
||||
info.add(buf.toString());
|
||||
buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX);
|
||||
}
|
||||
|
||||
String name = members.get(i);
|
||||
String disp;
|
||||
if ( moderator.contains(name) ) {
|
||||
name = "@" + name;
|
||||
}
|
||||
if ( isOnlinePlayer(members.get(i)) ) {
|
||||
if ( hided.contains(members.get(i)) )
|
||||
disp = ChatColor.DARK_AQUA + name;
|
||||
else
|
||||
disp = ChatColor.WHITE + name;
|
||||
} else {
|
||||
disp = ChatColor.GRAY + name;
|
||||
}
|
||||
buf.append(disp + ",");
|
||||
}
|
||||
|
||||
info.add(buf.toString());
|
||||
}
|
||||
|
||||
// シークレットチャンネルかどうか
|
||||
if ( !visible ) {
|
||||
info.add(INFO_SECRET);
|
||||
}
|
||||
|
||||
// パスワード設定があるかどうか
|
||||
if ( password.length() > 0 ) {
|
||||
if ( !forModerator ) {
|
||||
info.add(INFO_PASSWORD);
|
||||
} else {
|
||||
info.add(INFO_PASSWORD + " " + password);
|
||||
}
|
||||
}
|
||||
|
||||
// 範囲チャット、ワールドチャット
|
||||
if ( isWorldRange && chatRange > 0 ) {
|
||||
info.add(String.format(INFO_RANGECHAT, chatRange));
|
||||
} else if ( isWorldRange ) {
|
||||
info.add(INFO_WORLDCHAT);
|
||||
}
|
||||
|
||||
if ( forModerator ) {
|
||||
|
||||
// フォーマット情報
|
||||
info.add(INFO_FORMAT + format);
|
||||
|
||||
// Muteリスト情報、5人ごとに表示する
|
||||
if ( muted.size() > 0 ) {
|
||||
info.add(INFO_MUTED);
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX + ChatColor.WHITE);
|
||||
for ( int i=0; i<muted.size(); i++ ) {
|
||||
if ( i%5 == 0 && i != 0 ) {
|
||||
info.add(buf.toString());
|
||||
buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX + ChatColor.WHITE);
|
||||
}
|
||||
buf.append(muted.get(i) + ",");
|
||||
}
|
||||
|
||||
info.add(buf.toString());
|
||||
}
|
||||
|
||||
// BANリスト情報、5人ごとに表示する
|
||||
if ( banned.size() > 0 ) {
|
||||
info.add(INFO_BANNED);
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX + ChatColor.WHITE);
|
||||
for ( int i=0; i<banned.size(); i++ ) {
|
||||
if ( i%5 == 0 && i != 0 ) {
|
||||
info.add(buf.toString());
|
||||
buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX + ChatColor.WHITE);
|
||||
}
|
||||
buf.append(banned.get(i) + ",");
|
||||
}
|
||||
|
||||
info.add(buf.toString());
|
||||
}
|
||||
}
|
||||
|
||||
info.add(LIST_ENDLINE);
|
||||
|
||||
return info;
|
||||
}
|
||||
public abstract ArrayList<String> getInfo(boolean forModerator);
|
||||
|
||||
/**
|
||||
* 指定された名前のプレイヤーがオンラインかどうかを確認する
|
||||
@@ -740,73 +318,6 @@ public class Channel implements ConfigurationSerializable {
|
||||
return ( p != null && p.isOnline() );
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param player プレイヤー
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
private String replaceKeywords(String format, Player player) {
|
||||
|
||||
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", name);
|
||||
//msg = msg.replace("%msg", message);
|
||||
msg = msg.replace("%color", colorCode);
|
||||
msg = msg.replace("%to", privateMessageTo);
|
||||
|
||||
if ( player != null ) {
|
||||
msg = msg.replace("%username", player.getDisplayName());
|
||||
msg = msg.replace("%player", player.getName());
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
String prefix = "";
|
||||
String suffix = "";
|
||||
VaultChatBridge vaultchat = LunaChat.getInstance().getVaultChat();
|
||||
if ( vaultchat != null ) {
|
||||
prefix = vaultchat.getPlayerPrefix(player);
|
||||
suffix = vaultchat.getPlayerSuffix(player);
|
||||
}
|
||||
msg = msg.replace("%prefix", prefix);
|
||||
msg = msg.replace("%suffix", suffix);
|
||||
}
|
||||
} else {
|
||||
msg = msg.replace("%username", "");
|
||||
msg = msg.replace("%player", "");
|
||||
msg = msg.replace("%prefix", "");
|
||||
msg = msg.replace("%suffix", "");
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param playerName プレイヤー名
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
private String replaceKeywordsForSystemMessages(String format, String playerName) {
|
||||
|
||||
String msg = format;
|
||||
msg = msg.replace("%ch", name);
|
||||
msg = msg.replace("%color", colorCode);
|
||||
msg = msg.replace("%username", playerName);
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルのオンライン人数を返す
|
||||
* @return オンライン人数
|
||||
@@ -845,56 +356,7 @@ public class Channel implements ConfigurationSerializable {
|
||||
/**
|
||||
* 期限付きBanや期限付きMuteをチェックし、期限が切れていたら解除を行う
|
||||
*/
|
||||
public void checkExpires() {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
// 期限付きBANのチェック
|
||||
for ( String name : banExpires.keySet() ) {
|
||||
if ( banExpires.get(name) <= now ) {
|
||||
|
||||
// 期限マップから削除し、BANを解除
|
||||
banExpires.remove(name);
|
||||
if ( banned.contains(name) ) {
|
||||
banned.remove(name);
|
||||
save();
|
||||
|
||||
// メッセージ通知を流す
|
||||
String msg = String.format(MSG_BAN_EXPIRED, this.name, name);
|
||||
sendMessage(null, msg, null, false);
|
||||
|
||||
Player player = Utility.getPlayerExact(name);
|
||||
if ( player != null ) {
|
||||
msg = PREINFO + String.format(MSG_BAN_EXPIRED_PLAYER, this.name);
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 期限付きMuteのチェック
|
||||
for ( String name : muteExpires.keySet() ) {
|
||||
if ( muteExpires.get(name) <= now ) {
|
||||
|
||||
// 期限マップから削除し、Muteを解除
|
||||
muteExpires.remove(name);
|
||||
if ( muted.contains(name) ) {
|
||||
muted.remove(name);
|
||||
save();
|
||||
|
||||
// メッセージ通知を流す
|
||||
String msg = String.format(MSG_MUTE_EXPIRED, this.name, name);
|
||||
sendMessage(null, msg, null, false);
|
||||
|
||||
Player player = Utility.getPlayerExact(name);
|
||||
if ( player != null ) {
|
||||
msg = PREINFO + String.format(MSG_MUTE_EXPIRED_PLAYER, this.name);
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public abstract void checkExpires();
|
||||
|
||||
/**
|
||||
* シリアライズ<br>
|
||||
@@ -933,13 +395,17 @@ public class Channel implements ConfigurationSerializable {
|
||||
public static Channel deserialize(Map<String, Object> data) {
|
||||
|
||||
String name = castWithDefault(data.get(KEY_NAME), (String)null);
|
||||
List<String> members = castToStringList(data.get(KEY_MEMBERS));
|
||||
if ( name == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Channel channel = new Channel(name);
|
||||
channel.members = members;
|
||||
String defaultFormat =
|
||||
LunaChat.getInstance().getLunaChatConfig().getDefaultFormat();
|
||||
|
||||
Channel channel = new ChannelImpl(name);
|
||||
channel.members = castToStringList(data.get(KEY_MEMBERS));
|
||||
channel.description = castWithDefault(data.get(KEY_DESC), "");
|
||||
channel.format =
|
||||
castWithDefault(data.get(KEY_FORMAT), DEFAULT_FORMAT);
|
||||
channel.format = castWithDefault(data.get(KEY_FORMAT), defaultFormat);
|
||||
channel.banned = castToStringList(data.get(KEY_BANNED));
|
||||
channel.muted = castToStringList(data.get(KEY_MUTED));
|
||||
channel.hided = castToStringList(data.get(KEY_HIDED));
|
||||
@@ -1180,7 +646,7 @@ public class Channel implements ConfigurationSerializable {
|
||||
* チャットの可聴範囲を設定する
|
||||
* @param range 可聴範囲
|
||||
*/
|
||||
public void setRange(int range) {
|
||||
public void setChatRange(int range) {
|
||||
this.chatRange = range;
|
||||
}
|
||||
|
||||
@@ -1200,6 +666,22 @@ public class Channel implements ConfigurationSerializable {
|
||||
this.privateMessageTo = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* ワールドチャットかどうか
|
||||
* @return ワールドチャットかどうか
|
||||
*/
|
||||
public boolean isWorldRange() {
|
||||
return isWorldRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットの可聴範囲、0の場合は無制限
|
||||
* @return チャットの可聴範囲
|
||||
*/
|
||||
public int getChatRange() {
|
||||
return chatRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルの情報をファイルに保存する。
|
||||
* @return 保存をしたかどうか。
|
||||
@@ -1290,18 +772,4 @@ public class Channel implements ConfigurationSerializable {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* ログを記録する
|
||||
* @param message 記録するメッセージ
|
||||
*/
|
||||
private void log(String message) {
|
||||
|
||||
if ( config.isDisplayChatOnConsole() ) {
|
||||
Bukkit.getLogger().info(ChatColor.stripColor(message));
|
||||
}
|
||||
if ( config.isLoggingChat() && logger != null ) {
|
||||
logger.log(ChatColor.stripColor(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,666 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2014
|
||||
*/
|
||||
package com.github.ucchyocean.lc.channel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
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.LunaChatLogger;
|
||||
import com.github.ucchyocean.lc.NGWordAction;
|
||||
import com.github.ucchyocean.lc.Resources;
|
||||
import com.github.ucchyocean.lc.Utility;
|
||||
import com.github.ucchyocean.lc.bridge.DynmapBridge;
|
||||
import com.github.ucchyocean.lc.bridge.VaultChatBridge;
|
||||
import com.github.ucchyocean.lc.event.LunaChatChannelChatEvent;
|
||||
import com.github.ucchyocean.lc.event.LunaChatChannelMessageEvent;
|
||||
import com.github.ucchyocean.lc.japanize.JapanizeType;
|
||||
|
||||
/**
|
||||
* チャンネルの実装クラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ChannelImpl extends Channel {
|
||||
|
||||
private static final String INFO_FIRSTLINE = Resources.get("channelInfoFirstLine");
|
||||
private static final String INFO_PREFIX = Resources.get("channelInfoPrefix");
|
||||
private static final String INFO_GLOBAL = Resources.get("channelInfoGlobal");
|
||||
private static final String INFO_BROADCAST = Resources.get("channelInfoBroadcast");
|
||||
private static final String INFO_SECRET = Resources.get("channelInfoSecret");
|
||||
private static final String INFO_PASSWORD = Resources.get("channelInfoPassword");
|
||||
private static final String INFO_WORLDCHAT = Resources.get("channelInfoWorldChat");
|
||||
private static final String INFO_RANGECHAT = Resources.get("channelInfoRangeChat");
|
||||
private static final String INFO_FORMAT = Resources.get("channelInfoFormat");
|
||||
private static final String INFO_BANNED = Resources.get("channelInfoBanned");
|
||||
private static final String INFO_MUTED = Resources.get("channelInfoMuted");
|
||||
|
||||
private static final String LIST_ENDLINE = Resources.get("listEndLine");
|
||||
private static final String LIST_FORMAT = Resources.get("listFormat");
|
||||
|
||||
private static final String MSG_JOIN = Resources.get("joinMessage");
|
||||
private static final String MSG_QUIT = Resources.get("quitMessage");
|
||||
|
||||
private static final String MSG_BAN_EXPIRED = Resources.get("expiredBan");
|
||||
private static final String MSG_MUTE_EXPIRED = Resources.get("expiredMute");
|
||||
private static final String MSG_BAN_EXPIRED_PLAYER = Resources.get("cmdmsgPardoned");
|
||||
private static final String MSG_MUTE_EXPIRED_PLAYER = Resources.get("cmdmsgUnmuted");
|
||||
|
||||
private static final String PREINFO = Resources.get("infoPrefix");
|
||||
private static final String PREERR = Resources.get("errorPrefix");
|
||||
|
||||
private static final String NGWORD_PREFIX = Resources.get("ngwordPrefix");
|
||||
private static final String MSG_KICKED = Resources.get("cmdmsgKicked");
|
||||
private static final String MSG_BANNED = Resources.get("cmdmsgBanned");
|
||||
private static final String MSG_MUTED = Resources.get("cmdmsgMuted");
|
||||
|
||||
private static final String MSG_NO_RECIPIENT = Resources.get("noRecipientMessage");
|
||||
|
||||
private static final String ERRMSG_MUTED = Resources.get("errmsgMuted");
|
||||
|
||||
/** ロガー */
|
||||
private LunaChatLogger logger;
|
||||
|
||||
/** コンフィグ */
|
||||
private LunaChatConfig config;
|
||||
|
||||
/** API */
|
||||
private LunaChatAPI api;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param name チャンネル名
|
||||
*/
|
||||
protected ChannelImpl(String name) {
|
||||
|
||||
super(name);
|
||||
|
||||
config = LunaChat.getInstance().getLunaChatConfig();
|
||||
api = LunaChat.getInstance().getLunaChatAPI();
|
||||
logger = new LunaChatLogger(name.replace(">", "-"));
|
||||
}
|
||||
|
||||
/**
|
||||
* このチャットに発言をする
|
||||
* @param player 発言をするプレイヤー
|
||||
* @param message 発言をするメッセージ
|
||||
*/
|
||||
@Override
|
||||
public void chat(Player player, String message) {
|
||||
|
||||
// Muteされているかどうかを確認する
|
||||
if ( player != null && getMuted().contains(player.getName()) ) {
|
||||
player.sendMessage( PREERR + ERRMSG_MUTED );
|
||||
return;
|
||||
}
|
||||
|
||||
String preReplaceMessage = message;
|
||||
|
||||
// 一時的にJapanizeスキップ設定かどうかを確認する
|
||||
boolean skipJapanize = false;
|
||||
String marker = config.getNoneJapanizeMarker();
|
||||
if ( !marker.equals("") && message.startsWith(marker) ) {
|
||||
skipJapanize = true;
|
||||
message = message.substring(marker.length());
|
||||
}
|
||||
|
||||
// NGワード発言をしたかどうかのチェックとマスク
|
||||
boolean isNG = false;
|
||||
String maskedMessage = message;
|
||||
for ( String word : config.getNgword() ) {
|
||||
if ( maskedMessage.contains(word) ) {
|
||||
maskedMessage = maskedMessage.replace(
|
||||
word, Utility.getAstariskString(word.length()));
|
||||
isNG = true;
|
||||
}
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
String msgFormat = replaceKeywords(getFormat(), player);
|
||||
|
||||
// カラーコード置き換え
|
||||
maskedMessage = Utility.replaceColorCode(maskedMessage);
|
||||
|
||||
// イベントコール
|
||||
LunaChatChannelChatEvent event =
|
||||
new LunaChatChannelChatEvent(getName(), player,
|
||||
preReplaceMessage, maskedMessage, msgFormat);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if ( event.isCancelled() ) {
|
||||
return;
|
||||
}
|
||||
msgFormat = event.getMessageFormat();
|
||||
maskedMessage = event.getNgMaskedMessage();
|
||||
|
||||
// 2byteコードを含むか、半角カタカナのみなら、Japanize変換は行わない
|
||||
if ( !skipJapanize &&
|
||||
( message.getBytes().length > message.length() ||
|
||||
message.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
skipJapanize = true;
|
||||
}
|
||||
|
||||
// Japanize変換タスクを作成する
|
||||
boolean isIncludeSyncChat = true;
|
||||
DelayedJapanizeConvertTask delayedTask = null;
|
||||
if ( !skipJapanize &&
|
||||
api.isPlayerJapanize(player.getName()) &&
|
||||
config.getJapanizeType() != JapanizeType.NONE ) {
|
||||
|
||||
int lineType = config.getJapanizeDisplayLine();
|
||||
String jpFormat;
|
||||
String messageFormat = null;
|
||||
if ( lineType == 1 ) {
|
||||
jpFormat = config.getJapanizeLine1Format();
|
||||
messageFormat = msgFormat;
|
||||
isIncludeSyncChat = false;
|
||||
} else {
|
||||
jpFormat = config.getJapanizeLine2Format();
|
||||
}
|
||||
|
||||
// タスクを作成しておく
|
||||
delayedTask = new DelayedJapanizeConvertTask(maskedMessage,
|
||||
config.getJapanizeType(),
|
||||
this, player, jpFormat, messageFormat);
|
||||
}
|
||||
|
||||
if ( isIncludeSyncChat ) {
|
||||
// メッセージの送信
|
||||
sendMessage(player, maskedMessage, msgFormat, true);
|
||||
}
|
||||
|
||||
// 非同期実行タスクがある場合、追加で実行する
|
||||
if ( delayedTask != null ) {
|
||||
delayedTask.runTaskAsynchronously(LunaChat.getInstance());
|
||||
}
|
||||
|
||||
// NGワード発言者に、NGワードアクションを実行する
|
||||
if ( isNG && player != null ) {
|
||||
if ( config.getNgwordAction() == NGWordAction.BAN ) {
|
||||
// BANする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
getBanned().add(player.getName());
|
||||
removeMember(player.getName());
|
||||
String temp = PREINFO + NGWORD_PREFIX + MSG_BANNED;
|
||||
String m = String.format(temp, getName());
|
||||
player.sendMessage(m);
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.KICK ) {
|
||||
// キックする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
removeMember(player.getName());
|
||||
String temp = PREINFO + NGWORD_PREFIX + MSG_KICKED;
|
||||
String m = String.format(temp, getName());
|
||||
player.sendMessage(m);
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.MUTE ) {
|
||||
// Muteする
|
||||
|
||||
getMuted().add(player.getName());
|
||||
save();
|
||||
String temp = PREINFO + NGWORD_PREFIX + MSG_MUTED;
|
||||
String m = String.format(temp, getName());
|
||||
player.sendMessage(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ほかの連携先などから、このチャットに発言する
|
||||
* @param player プレイヤー名
|
||||
* @param source 連携元を判別する文字列
|
||||
* @param message メッセージ
|
||||
*/
|
||||
@Override
|
||||
public void chatFromOtherSource(String player, String source, String message) {
|
||||
|
||||
// 表示名
|
||||
String name = player + "@" + source;
|
||||
|
||||
// NGワード発言のマスク
|
||||
String maskedMessage = message;
|
||||
for ( String word : config.getNgword() ) {
|
||||
if ( maskedMessage.contains(word) ) {
|
||||
maskedMessage = maskedMessage.replace(
|
||||
word, Utility.getAstariskString(word.length()));
|
||||
}
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
String msgFormat = replaceKeywords(getFormat(), null);
|
||||
msgFormat = msgFormat.replace("%username", name);
|
||||
msgFormat = msgFormat.replace("%player", name);
|
||||
msgFormat = msgFormat.replace("%prefix", "");
|
||||
msgFormat = msgFormat.replace("%suffix", "");
|
||||
|
||||
// カラーコード置き換え
|
||||
maskedMessage = Utility.replaceColorCode(maskedMessage);
|
||||
|
||||
// メッセージの送信
|
||||
sendMessage(null, maskedMessage, msgFormat, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 入退室メッセージを流す
|
||||
* @param isJoin 入室かどうか(falseなら退室)
|
||||
* @param player 入退室したプレイヤー名
|
||||
*/
|
||||
@Override
|
||||
protected void sendJoinQuitMessage(boolean isJoin, String player) {
|
||||
|
||||
// 1:1チャットなら、入退室メッセージは表示しない
|
||||
if ( isPersonalChat() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
String msg;
|
||||
if ( isJoin ) {
|
||||
msg = MSG_JOIN;
|
||||
} else {
|
||||
msg = MSG_QUIT;
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
msg = msg.replace("%ch", getName());
|
||||
msg = msg.replace("%color", getColorCode());
|
||||
msg = msg.replace("%username", player);
|
||||
|
||||
sendMessage(null, msg, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを表示します。指定したプレイヤーの発言として処理されます。
|
||||
* @param player プレイヤー(ワールドチャット、範囲チャットの場合は必須です)
|
||||
* @param message メッセージ
|
||||
* @param format フォーマット
|
||||
* @param sendDynmap dynmapへ送信するかどうか
|
||||
*/
|
||||
@Override
|
||||
protected void sendMessage(Player player, String message,
|
||||
String format, boolean sendDynmap) {
|
||||
|
||||
String originalMessage = new String(message);
|
||||
|
||||
// 受信者を設定する
|
||||
ArrayList<Player> recipients = new ArrayList<Player>();
|
||||
boolean isRangeChat = false;
|
||||
|
||||
if ( isBroadcastChannel() ) {
|
||||
// ブロードキャストチャンネル
|
||||
|
||||
if ( isWorldRange() && player != null ) {
|
||||
isRangeChat = true;
|
||||
World w = player.getWorld();
|
||||
|
||||
if ( getChatRange() > 0 ) {
|
||||
// 範囲チャット
|
||||
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
if ( p.getWorld().equals(w) &&
|
||||
player.getLocation().distance(p.getLocation()) <= getChatRange() &&
|
||||
!getHided().contains(p.getName()) ) {
|
||||
recipients.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// ワールドチャット
|
||||
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
if ( p.getWorld().equals(w) && !getHided().contains(p.getName()) ) {
|
||||
recipients.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// 通常ブロードキャスト(全員へ送信)
|
||||
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
if ( !getHided().contains(p.getName()) ) {
|
||||
recipients.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// 通常チャンネル
|
||||
|
||||
for ( String name : getMembers() ) {
|
||||
Player p = Utility.getPlayerExact(name);
|
||||
if ( p != null && !getHided().contains(p.getName()) ) {
|
||||
recipients.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// フォーマットがある場合は置き換える
|
||||
if ( format != null ) {
|
||||
message = format.replace("%msg", message);
|
||||
}
|
||||
|
||||
// イベントコール
|
||||
LunaChatChannelMessageEvent event =
|
||||
new LunaChatChannelMessageEvent(
|
||||
getName(), player, message, recipients);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
message = event.getMessage();
|
||||
recipients = event.getRecipients();
|
||||
|
||||
// 通常ブロードキャストなら、設定に応じてdynmapへ送信する
|
||||
DynmapBridge dynmap = LunaChat.getInstance().getDynmap();
|
||||
if ( config.isSendBroadcastChannelChatToDynmap() &&
|
||||
sendDynmap &&
|
||||
dynmap != null &&
|
||||
isBroadcastChannel() &&
|
||||
!isWorldRange() ) {
|
||||
if ( config.isSendFormattedMessageToDynmap() ) {
|
||||
if ( player != null ) {
|
||||
dynmap.chat(player, message);
|
||||
} else {
|
||||
dynmap.broadcast(message);
|
||||
}
|
||||
} else {
|
||||
if ( player != null ) {
|
||||
dynmap.chat(player, originalMessage);
|
||||
} else {
|
||||
dynmap.broadcast(originalMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 送信する
|
||||
for ( Player p : recipients ) {
|
||||
p.sendMessage(message);
|
||||
}
|
||||
|
||||
// 受信者が自分以外いない場合は、メッセージを表示する
|
||||
if ( isRangeChat && (
|
||||
recipients.size() == 0 ||
|
||||
(recipients.size() == 1 &&
|
||||
recipients.get(0).getName().equals(player.getName()) ) ) ) {
|
||||
String msg = replaceKeywordsForSystemMessages(MSG_NO_RECIPIENT, "");
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
|
||||
// ロギング
|
||||
log(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネル情報を返す
|
||||
* @param forModerator モデレータ向けの情報を含めるかどうか
|
||||
* @return チャンネル情報
|
||||
*/
|
||||
@Override
|
||||
public ArrayList<String> getInfo(boolean forModerator) {
|
||||
|
||||
ArrayList<String> info = new ArrayList<String>();
|
||||
info.add(INFO_FIRSTLINE);
|
||||
|
||||
// チャンネル名、参加人数、総人数、チャンネル説明文
|
||||
info.add( String.format(
|
||||
LIST_FORMAT, getName(), getOnlineNum(), getTotalNum(), getDescription()) );
|
||||
|
||||
// 参加メンバー一覧
|
||||
if ( isGlobalChannel() ) {
|
||||
info.add(INFO_GLOBAL);
|
||||
} else if ( isBroadcastChannel() ) {
|
||||
info.add(INFO_BROADCAST);
|
||||
} else {
|
||||
// メンバーを、5人ごとに表示する
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX);
|
||||
|
||||
for ( int i=0; i<getMembers().size(); i++ ) {
|
||||
|
||||
if ( i%5 == 0 && i != 0 ) {
|
||||
info.add(buf.toString());
|
||||
buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX);
|
||||
}
|
||||
|
||||
String name = getMembers().get(i);
|
||||
String disp;
|
||||
if ( getModerator().contains(name) ) {
|
||||
name = "@" + name;
|
||||
}
|
||||
if ( isOnlinePlayer(getMembers().get(i)) ) {
|
||||
if ( getHided().contains(getMembers().get(i)) )
|
||||
disp = ChatColor.DARK_AQUA + name;
|
||||
else
|
||||
disp = ChatColor.WHITE + name;
|
||||
} else {
|
||||
disp = ChatColor.GRAY + name;
|
||||
}
|
||||
buf.append(disp + ",");
|
||||
}
|
||||
|
||||
info.add(buf.toString());
|
||||
}
|
||||
|
||||
// シークレットチャンネルかどうか
|
||||
if ( !isVisible() ) {
|
||||
info.add(INFO_SECRET);
|
||||
}
|
||||
|
||||
// パスワード設定があるかどうか
|
||||
if ( getPassword().length() > 0 ) {
|
||||
if ( !forModerator ) {
|
||||
info.add(INFO_PASSWORD);
|
||||
} else {
|
||||
info.add(INFO_PASSWORD + " " + getPassword());
|
||||
}
|
||||
}
|
||||
|
||||
// 範囲チャット、ワールドチャット
|
||||
if ( isWorldRange() && getChatRange() > 0 ) {
|
||||
info.add(String.format(INFO_RANGECHAT, getChatRange()));
|
||||
} else if ( isWorldRange() ) {
|
||||
info.add(INFO_WORLDCHAT);
|
||||
}
|
||||
|
||||
if ( forModerator ) {
|
||||
|
||||
// フォーマット情報
|
||||
info.add(INFO_FORMAT + getFormat());
|
||||
|
||||
// Muteリスト情報、5人ごとに表示する
|
||||
if ( getMuted().size() > 0 ) {
|
||||
info.add(INFO_MUTED);
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX + ChatColor.WHITE);
|
||||
for ( int i=0; i<getMuted().size(); i++ ) {
|
||||
if ( i%5 == 0 && i != 0 ) {
|
||||
info.add(buf.toString());
|
||||
buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX + ChatColor.WHITE);
|
||||
}
|
||||
buf.append(getMuted().get(i) + ",");
|
||||
}
|
||||
|
||||
info.add(buf.toString());
|
||||
}
|
||||
|
||||
// BANリスト情報、5人ごとに表示する
|
||||
if ( getBanned().size() > 0 ) {
|
||||
info.add(INFO_BANNED);
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX + ChatColor.WHITE);
|
||||
for ( int i=0; i<getBanned().size(); i++ ) {
|
||||
if ( i%5 == 0 && i != 0 ) {
|
||||
info.add(buf.toString());
|
||||
buf = new StringBuffer();
|
||||
buf.append(INFO_PREFIX + ChatColor.WHITE);
|
||||
}
|
||||
buf.append(getBanned().get(i) + ",");
|
||||
}
|
||||
|
||||
info.add(buf.toString());
|
||||
}
|
||||
}
|
||||
|
||||
info.add(LIST_ENDLINE);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 期限付きBanや期限付きMuteをチェックし、期限が切れていたら解除を行う
|
||||
*/
|
||||
@Override
|
||||
public void checkExpires() {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
// 期限付きBANのチェック
|
||||
for ( String name : getBanExpires().keySet() ) {
|
||||
if ( getBanExpires().get(name) <= now ) {
|
||||
|
||||
// 期限マップから削除し、BANを解除
|
||||
getBanExpires().remove(name);
|
||||
if ( getBanned().contains(name) ) {
|
||||
getBanned().remove(name);
|
||||
save();
|
||||
|
||||
// メッセージ通知を流す
|
||||
String msg = String.format(MSG_BAN_EXPIRED, getName(), name);
|
||||
sendMessage(null, msg, null, false);
|
||||
|
||||
Player player = Utility.getPlayerExact(name);
|
||||
if ( player != null ) {
|
||||
msg = PREINFO + String.format(MSG_BAN_EXPIRED_PLAYER, getName());
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 期限付きMuteのチェック
|
||||
for ( String name : getMuteExpires().keySet() ) {
|
||||
if ( getMuteExpires().get(name) <= now ) {
|
||||
|
||||
// 期限マップから削除し、Muteを解除
|
||||
getMuteExpires().remove(name);
|
||||
if ( getMuted().contains(name) ) {
|
||||
getMuted().remove(name);
|
||||
save();
|
||||
|
||||
// メッセージ通知を流す
|
||||
String msg = String.format(MSG_MUTE_EXPIRED, getName(), name);
|
||||
sendMessage(null, msg, null, false);
|
||||
|
||||
Player player = Utility.getPlayerExact(name);
|
||||
if ( player != null ) {
|
||||
msg = PREINFO + String.format(MSG_MUTE_EXPIRED_PLAYER, getName());
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param player プレイヤー
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
private String replaceKeywords(String format, Player player) {
|
||||
|
||||
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 ( player != null ) {
|
||||
msg = msg.replace("%username", player.getDisplayName());
|
||||
msg = msg.replace("%player", player.getName());
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
String prefix = "";
|
||||
String suffix = "";
|
||||
VaultChatBridge vaultchat = LunaChat.getInstance().getVaultChat();
|
||||
if ( vaultchat != null ) {
|
||||
prefix = vaultchat.getPlayerPrefix(player);
|
||||
suffix = vaultchat.getPlayerSuffix(player);
|
||||
}
|
||||
msg = msg.replace("%prefix", prefix);
|
||||
msg = msg.replace("%suffix", suffix);
|
||||
}
|
||||
} else {
|
||||
msg = msg.replace("%username", "");
|
||||
msg = msg.replace("%player", "");
|
||||
msg = msg.replace("%prefix", "");
|
||||
msg = msg.replace("%suffix", "");
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された名前のプレイヤーがオンラインかどうかを確認する
|
||||
* @param playerName プレイヤー名
|
||||
* @return オンラインかどうか
|
||||
*/
|
||||
private boolean isOnlinePlayer(String playerName) {
|
||||
Player p = Utility.getPlayerExact(playerName);
|
||||
return ( p != null && p.isOnline() );
|
||||
}
|
||||
|
||||
/**
|
||||
* ログを記録する
|
||||
* @param message 記録するメッセージ
|
||||
*/
|
||||
private void log(String message) {
|
||||
|
||||
if ( config.isDisplayChatOnConsole() ) {
|
||||
Bukkit.getLogger().info(ChatColor.stripColor(message));
|
||||
}
|
||||
if ( config.isLoggingChat() && logger != null ) {
|
||||
logger.log(ChatColor.stripColor(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -346,7 +346,7 @@ public class ChannelManager implements LunaChatAPI {
|
||||
}
|
||||
String name = event.getChannelName();
|
||||
|
||||
Channel channel = new Channel(name);
|
||||
Channel channel = new ChannelImpl(name);
|
||||
channels.put(name.toLowerCase(), channel);
|
||||
channel.save();
|
||||
return channel;
|
||||
|
||||
@@ -239,19 +239,19 @@ public class OptionCommand extends SubCommandAbst {
|
||||
|
||||
if ( value.equals("") ) {
|
||||
channel.setWorldRange(false);
|
||||
channel.setRange(0);
|
||||
channel.setChatRange(0);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "range", "無効");
|
||||
setOption = true;
|
||||
} else if ( value.equalsIgnoreCase("world") ) {
|
||||
channel.setWorldRange(true);
|
||||
channel.setRange(0);
|
||||
channel.setChatRange(0);
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "range", "world");
|
||||
setOption = true;
|
||||
} else if ( value.matches("[0-9]+") ) {
|
||||
channel.setWorldRange(true);
|
||||
channel.setRange(Integer.parseInt(value));
|
||||
channel.setChatRange(Integer.parseInt(value));
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "range", value);
|
||||
setOption = true;
|
||||
|
||||
@@ -13,18 +13,35 @@ import java.util.List;
|
||||
*/
|
||||
public class LunaChatChannelMemberChangedEvent extends LunaChatBaseCancellableEvent {
|
||||
|
||||
private List<String> members;
|
||||
private List<String> before;
|
||||
private List<String> after;
|
||||
|
||||
public LunaChatChannelMemberChangedEvent(String channelName, List<String> members) {
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param channelName チャンネル名
|
||||
* @param before 変更前のメンバー
|
||||
* @param after 変更後のメンバー
|
||||
*/
|
||||
public LunaChatChannelMemberChangedEvent(
|
||||
String channelName, List<String> before, List<String> after) {
|
||||
super(channelName);
|
||||
this.members = members;
|
||||
this.before = before;
|
||||
this.after = after;
|
||||
}
|
||||
|
||||
/**
|
||||
* 変更前のメンバーリストをかえす
|
||||
* @return
|
||||
*/
|
||||
public List<String> getMembersBefore() {
|
||||
return before;
|
||||
}
|
||||
|
||||
/**
|
||||
* 変更後のメンバーリストをかえす
|
||||
* @return
|
||||
*/
|
||||
public List<String> getMembers() {
|
||||
return members;
|
||||
public List<String> getMembersAfter() {
|
||||
return after;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする