LunaChat v3-k2 : tidied up channel classes.
このコミットが含まれているのは:
1 親
75fe8a98ec
コミット
1fbbba5a80
15ファイル変更
+282
-457
検索条件に一致するファイルはありません
@@ -170,9 +170,14 @@ public class Channel {
|
||||
*/
|
||||
public void sendMessage(
|
||||
ChannelPlayer player, String message, String format, boolean sendDynmap, String displayName) {
|
||||
channel.sendMessage(
|
||||
ChannelMember.getChannelMember(player.toString()),
|
||||
message, format, sendDynmap, displayName);
|
||||
if ( format != null ) {
|
||||
message = format.replace("%msg", message);
|
||||
}
|
||||
if ( player != null ) {
|
||||
channel.chat(ChannelMember.getChannelMember(player.toString()), message);
|
||||
} else {
|
||||
channel.chatFromOtherSource(displayName, null, message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,4 +66,8 @@ public class LunaChat {
|
||||
public static UUIDCacheData getUUIDCacheData() {
|
||||
return instance.getUUIDCacheData();
|
||||
}
|
||||
|
||||
public static void runAsyncTask(Runnable task) {
|
||||
instance.runAsyncTask(task);
|
||||
}
|
||||
}
|
||||
@@ -280,4 +280,14 @@ public class LunaChatBukkit extends JavaPlugin implements PluginInterface {
|
||||
public UUIDCacheData getUUIDCacheData() {
|
||||
return uuidCacheData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 非同期タスクを実行する
|
||||
* @param task タスク
|
||||
* @see com.github.ucchyocean.lc3.PluginInterface#runAsyncTask(java.lang.Runnable)
|
||||
*/
|
||||
@Override
|
||||
public void runAsyncTask(Runnable task) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, task);
|
||||
}
|
||||
}
|
||||
@@ -186,4 +186,14 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
|
||||
public UUIDCacheData getUUIDCacheData() {
|
||||
return uuidCacheData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 非同期タスクを実行する
|
||||
* @param task タスク
|
||||
* @see com.github.ucchyocean.lc3.PluginInterface#runAsyncTask(java.lang.Runnable)
|
||||
*/
|
||||
@Override
|
||||
public void runAsyncTask(Runnable task) {
|
||||
ProxyServer.getInstance().getScheduler().runAsync(this, task);
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class LunaChatLogger {
|
||||
checkDir();
|
||||
|
||||
// 以降の処理を、発言処理の負荷軽減のため、非同期実行にする。(see issue #40.)
|
||||
new Thread(new Runnable() {
|
||||
LunaChat.runAsyncTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -76,7 +76,7 @@ public class LunaChatLogger {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -95,4 +95,14 @@ public class LunaChatStandalone implements PluginInterface {
|
||||
public UUIDCacheData getUUIDCacheData() {
|
||||
return uuidCacheData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 非同期タスクを実行する
|
||||
* @param task タスク
|
||||
* @see com.github.ucchyocean.lc3.PluginInterface#runAsyncTask(java.lang.Runnable)
|
||||
*/
|
||||
@Override
|
||||
public void runAsyncTask(Runnable task) {
|
||||
new Thread(task).start();
|
||||
}
|
||||
}
|
||||
@@ -63,4 +63,10 @@ public interface PluginInterface {
|
||||
* @return UUIDキャッシュデータ
|
||||
*/
|
||||
public UUIDCacheData getUUIDCacheData();
|
||||
|
||||
/**
|
||||
* 非同期タスクを実行する
|
||||
* @param task タスク
|
||||
*/
|
||||
public void runAsyncTask(Runnable task);
|
||||
}
|
||||
@@ -5,13 +5,10 @@
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.channel;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
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;
|
||||
@@ -24,13 +21,10 @@ import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatBukkit;
|
||||
import com.github.ucchyocean.lc3.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.NGWordAction;
|
||||
import com.github.ucchyocean.lc3.Utility;
|
||||
import com.github.ucchyocean.lc3.UtilityBukkit;
|
||||
import com.github.ucchyocean.lc3.bridge.DynmapBridge;
|
||||
import com.github.ucchyocean.lc3.bukkit.event.LunaChatBukkitChannelChatEvent;
|
||||
import com.github.ucchyocean.lc3.bukkit.event.LunaChatBukkitChannelMessageEvent;
|
||||
import com.github.ucchyocean.lc3.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberBukkit;
|
||||
|
||||
@@ -40,8 +34,6 @@ import com.github.ucchyocean.lc3.member.ChannelMemberBukkit;
|
||||
*/
|
||||
public class BukkitChannel extends Channel {
|
||||
|
||||
private static final String PERMISSION_SPEAK_PREFIX = "lunachat.speak";
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
|
||||
@@ -57,197 +49,6 @@ public class BukkitChannel extends Channel {
|
||||
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) ) {
|
||||
player.sendMessage(Messages.errmsgPermission(node));
|
||||
return;
|
||||
}
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
// Muteされているかどうかを確認する
|
||||
if ( getMuted().contains(player) ) {
|
||||
player.sendMessage(Messages.errmsgMuted());
|
||||
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);
|
||||
}
|
||||
|
||||
// イベントコール
|
||||
LunaChatBukkitChannelChatEvent event =
|
||||
new LunaChatBukkitChannelChatEvent(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(StandardCharsets.UTF_8).length > kanaTemp.length() ||
|
||||
kanaTemp.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
skipJapanize = true;
|
||||
}
|
||||
|
||||
// Japanize変換タスクを作成する
|
||||
boolean isIncludeSyncChat = true;
|
||||
ChannelChatJapanizeTask 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 ChannelChatJapanizeTask(maskedMessage,
|
||||
japanizeType, this, player, jpFormat, messageFormat);
|
||||
}
|
||||
|
||||
if ( isIncludeSyncChat ) {
|
||||
// メッセージの送信
|
||||
sendMessage(player, maskedMessage, msgFormat, true, player.getDisplayName());
|
||||
}
|
||||
|
||||
// 非同期実行タスクがある場合、追加で実行する
|
||||
if ( delayedTask != null ) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(
|
||||
LunaChatBukkit.getInstance(), delayedTask);
|
||||
}
|
||||
|
||||
// NGワード発言者に、NGワードアクションを実行する
|
||||
if ( isNG ) {
|
||||
if ( config.getNgwordAction() == NGWordAction.BAN ) {
|
||||
// BANする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
getBanned().add(player);
|
||||
removeMember(player);
|
||||
if ( !Messages.banNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.banNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.KICK ) {
|
||||
// キックする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
removeMember(player);
|
||||
if ( !Messages.kickNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.kickNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.MUTE ) {
|
||||
// Muteする
|
||||
|
||||
getMuted().add(player);
|
||||
save();
|
||||
if ( !Messages.muteNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.muteNGWordMessage(getColorCode(), getName(), 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 player プレイヤー(ワールドチャット、範囲チャットの場合は必須です)
|
||||
@@ -257,7 +58,7 @@ public class BukkitChannel extends Channel {
|
||||
* @param name 発言者名
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(ChannelMember player, String message,
|
||||
protected void sendMessage(ChannelMember player, String message,
|
||||
String format, boolean sendDynmap, String name) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
@@ -531,23 +332,6 @@ public class BukkitChannel extends Channel {
|
||||
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 発言者
|
||||
|
||||
@@ -5,24 +5,18 @@
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.channel;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
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 com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatBungee;
|
||||
import com.github.ucchyocean.lc3.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.NGWordAction;
|
||||
import com.github.ucchyocean.lc3.Utility;
|
||||
import com.github.ucchyocean.lc3.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberProxiedPlayer;
|
||||
|
||||
@@ -35,8 +29,6 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
*/
|
||||
public class BungeeChannel extends Channel {
|
||||
|
||||
private static final String PERMISSION_SPEAK_PREFIX = "lunachat.speak";
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
|
||||
@@ -52,198 +44,6 @@ public class BungeeChannel extends Channel {
|
||||
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) ) {
|
||||
player.sendMessage(Messages.errmsgPermission(node));
|
||||
return;
|
||||
}
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
// Muteされているかどうかを確認する
|
||||
if ( getMuted().contains(player) ) {
|
||||
player.sendMessage(Messages.errmsgMuted());
|
||||
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(StandardCharsets.UTF_8).length > kanaTemp.length() ||
|
||||
kanaTemp.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
skipJapanize = true;
|
||||
}
|
||||
|
||||
// Japanize変換タスクを作成する
|
||||
boolean isIncludeSyncChat = true;
|
||||
ChannelChatJapanizeTask 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 ChannelChatJapanizeTask(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 ( !Messages.banNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.banNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.KICK ) {
|
||||
// キックする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
removeMember(player);
|
||||
if ( !Messages.kickNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.kickNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.MUTE ) {
|
||||
// Muteする
|
||||
|
||||
getMuted().add(player);
|
||||
save();
|
||||
if ( !Messages.muteNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.muteNGWordMessage(getColorCode(), getName(), 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 player プレイヤー(ワールドチャット、範囲チャットの場合は必須です)
|
||||
@@ -253,7 +53,7 @@ public class BungeeChannel extends Channel {
|
||||
* @param name 発言者名
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(ChannelMember player, String message,
|
||||
protected void sendMessage(ChannelMember player, String message,
|
||||
String format, boolean sendDynmap, String name) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
@@ -465,23 +265,6 @@ public class BungeeChannel extends Channel {
|
||||
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 発言者
|
||||
|
||||
@@ -8,10 +8,13 @@ package com.github.ucchyocean.lc3.channel;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.ucchyocean.lc3.ChatColor;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
@@ -20,6 +23,8 @@ import com.github.ucchyocean.lc3.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc3.LunaChatLogger;
|
||||
import com.github.ucchyocean.lc3.LunaChatMode;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.NGWordAction;
|
||||
import com.github.ucchyocean.lc3.Utility;
|
||||
import com.github.ucchyocean.lc3.YamlConfig;
|
||||
import com.github.ucchyocean.lc3.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
@@ -30,6 +35,8 @@ import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
*/
|
||||
public abstract class Channel {
|
||||
|
||||
private static final String PERMISSION_SPEAK_PREFIX = "lunachat.speak";
|
||||
|
||||
private static final String FOLDER_NAME_CHANNELS = "channels";
|
||||
|
||||
private static final String KEY_NAME = "name";
|
||||
@@ -208,7 +215,151 @@ public abstract class Channel {
|
||||
* @param player 発言をするプレイヤー
|
||||
* @param message 発言をするメッセージ
|
||||
*/
|
||||
public abstract void chat(ChannelMember player, String message);
|
||||
public void chat(ChannelMember player, String message) {
|
||||
|
||||
// 発言権限を確認する
|
||||
String node = PERMISSION_SPEAK_PREFIX + "." + getName();
|
||||
if ( player.isPermissionSet(node) && !player.hasPermission(node) ) {
|
||||
player.sendMessage(Messages.errmsgPermission(node));
|
||||
return;
|
||||
}
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
// Muteされているかどうかを確認する
|
||||
if ( getMuted().contains(player) ) {
|
||||
player.sendMessage(Messages.errmsgMuted());
|
||||
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(StandardCharsets.UTF_8).length > kanaTemp.length() ||
|
||||
kanaTemp.matches("[ \\uFF61-\\uFF9F]+") ) ) {
|
||||
skipJapanize = true;
|
||||
}
|
||||
|
||||
// Japanize変換タスクを作成する
|
||||
boolean isIncludeSyncChat = true;
|
||||
ChannelChatJapanizeTask 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 ChannelChatJapanizeTask(maskedMessage,
|
||||
japanizeType, this, player, jpFormat, messageFormat);
|
||||
}
|
||||
|
||||
if ( isIncludeSyncChat ) {
|
||||
// メッセージの送信
|
||||
sendMessage(player, maskedMessage, msgFormat, true, player.getDisplayName());
|
||||
}
|
||||
|
||||
// 非同期実行タスクがある場合、追加で実行する
|
||||
if ( delayedTask != null ) {
|
||||
LunaChat.runAsyncTask(delayedTask);
|
||||
}
|
||||
|
||||
// NGワード発言者に、NGワードアクションを実行する
|
||||
if ( isNG ) {
|
||||
if ( config.getNgwordAction() == NGWordAction.BAN ) {
|
||||
// BANする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
getBanned().add(player);
|
||||
removeMember(player);
|
||||
if ( !Messages.banNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.banNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.KICK ) {
|
||||
// キックする
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
removeMember(player);
|
||||
if ( !Messages.kickNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.kickNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
} else if ( config.getNgwordAction() == NGWordAction.MUTE ) {
|
||||
// Muteする
|
||||
|
||||
getMuted().add(player);
|
||||
save();
|
||||
if ( !Messages.muteNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.muteNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ほかの連携先などから、このチャットに発言する
|
||||
@@ -216,7 +367,52 @@ public abstract class Channel {
|
||||
* @param source 連携元を判別する文字列
|
||||
* @param message メッセージ
|
||||
*/
|
||||
public abstract void chatFromOtherSource(String player, String source, String message);
|
||||
public void chatFromOtherSource(String player, String source, String message) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
// 表示名
|
||||
String name;
|
||||
if ( source != null && !source.isEmpty() ) {
|
||||
name = player + "@" + source;
|
||||
} else {
|
||||
name = player;
|
||||
}
|
||||
|
||||
// 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 message メッセージ
|
||||
* @param sendDynmap Dynmapにも表示するかどうか
|
||||
* @param name 発言者の表示名
|
||||
*/
|
||||
public void sendSystemMessage(String message, boolean sendDynmap, String name) {
|
||||
sendMessage(null, message, null, sendDynmap, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* メンバーを追加する
|
||||
@@ -364,7 +560,7 @@ public abstract class Channel {
|
||||
* @param sendDynmap dynmapへ送信するかどうか
|
||||
* @param displayName 発言者の表示名(APIに使用されます)
|
||||
*/
|
||||
public abstract void sendMessage(
|
||||
protected abstract void sendMessage(
|
||||
ChannelMember player, String message, String format, boolean sendDynmap, String displayName);
|
||||
|
||||
/**
|
||||
@@ -1006,6 +1202,23 @@ public abstract class Channel {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* List<ChannelMember>を、List<String>に変換する。
|
||||
* @param org 変換元
|
||||
|
||||
@@ -154,13 +154,13 @@ public class BanCommand extends LunaChatSubCommand {
|
||||
|
||||
// チャンネルに通知メッセージを出す
|
||||
if ( expireMinutes != -1 ) {
|
||||
channel.sendMessage(null, Messages.banWithExpireMessage(
|
||||
channel.sendSystemMessage(Messages.banWithExpireMessage(
|
||||
channel.getColorCode(), channel.getName(), kicked.getName(), expireMinutes),
|
||||
null, true, "system");
|
||||
true, "system");
|
||||
} else {
|
||||
channel.sendMessage(null, Messages.banMessage(
|
||||
channel.sendSystemMessage(Messages.banMessage(
|
||||
channel.getColorCode(), channel.getName(), kicked.getName()),
|
||||
null, true, "system");
|
||||
true, "system");
|
||||
}
|
||||
|
||||
// BANされた人に通知メッセージを出す
|
||||
|
||||
@@ -120,9 +120,9 @@ public class KickCommand extends LunaChatSubCommand {
|
||||
sender.sendMessage(Messages.cmdmsgKick(kickedName, channel.getName()));
|
||||
|
||||
// チャンネルに通知メッセージを出す
|
||||
channel.sendMessage(null,
|
||||
channel.sendSystemMessage(
|
||||
Messages.kickMessage(channel.getColorCode(), channel.getName(), kicked),
|
||||
null, true, "system");
|
||||
true, "system");
|
||||
|
||||
// キックされた人に通知メッセージを出す
|
||||
if ( kicked != null && kicked.isOnline() ) {
|
||||
|
||||
@@ -147,13 +147,13 @@ public class MuteCommand extends LunaChatSubCommand {
|
||||
|
||||
// チャンネルに通知メッセージを出す
|
||||
if ( expireMinutes != -1 ) {
|
||||
channel.sendMessage(null, Messages.muteWithExpireMessage(
|
||||
channel.sendSystemMessage(Messages.muteWithExpireMessage(
|
||||
channel.getColorCode(), channel.getName(), kicked.getName(), expireMinutes),
|
||||
null, true, "system");
|
||||
true, "system");
|
||||
} else {
|
||||
channel.sendMessage(null, Messages.muteMessage(
|
||||
channel.sendSystemMessage(Messages.muteMessage(
|
||||
channel.getColorCode(), channel.getName(), kicked.getName()),
|
||||
null, true, "system");
|
||||
true, "system");
|
||||
}
|
||||
|
||||
// BANされた人に通知メッセージを出す
|
||||
|
||||
@@ -117,9 +117,9 @@ public class PardonCommand extends LunaChatSubCommand {
|
||||
sender.sendMessage(Messages.cmdmsgPardon(kickedName, channel.getName()));
|
||||
|
||||
// チャンネルに通知メッセージを出す
|
||||
channel.sendMessage(null, Messages.pardonMessage(
|
||||
channel.sendSystemMessage(Messages.pardonMessage(
|
||||
channel.getColorCode(), channel.getName(), kicked.getName()),
|
||||
null, true, "system");
|
||||
true, "system");
|
||||
|
||||
// BANされていた人に通知メッセージを出す
|
||||
if ( kicked != null && kicked.isOnline() ) {
|
||||
|
||||
@@ -117,9 +117,9 @@ public class UnmuteCommand extends LunaChatSubCommand {
|
||||
sender.sendMessage(Messages.cmdmsgUnmute(kickedName, channel.getName()));
|
||||
|
||||
// チャンネルに通知メッセージを出す
|
||||
channel.sendMessage(null, Messages.unmuteMessage(
|
||||
channel.sendSystemMessage(Messages.unmuteMessage(
|
||||
channel.getColorCode(), channel.getName(), kicked.getName()),
|
||||
null, true, "system");
|
||||
true, "system");
|
||||
|
||||
// BANされていた人に通知メッセージを出す
|
||||
if ( kicked != null && kicked.isOnline() ) {
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする