LunaChat v1.4.1 : Fixed issue #16.
このコミットが含まれているのは:
1 親
c3e0a32118
コミット
0912c7d7f9
6ファイル変更
+130
-1
検索条件に一致するファイルはありません
@@ -32,6 +32,13 @@ public class Channel {
|
||||
private static final String MSG_JOIN = Resources.get("joinMessage");
|
||||
private static final String MSG_QUIT = Resources.get("quitMessage");
|
||||
|
||||
private static final String PREINFO = Resources.get("infoPrefix");
|
||||
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");
|
||||
|
||||
// ngwordPrefix
|
||||
|
||||
/** 参加者 */
|
||||
protected List<String> members;
|
||||
|
||||
@@ -96,6 +103,16 @@ public class Channel {
|
||||
*/
|
||||
protected void chat(Player player, String message) {
|
||||
|
||||
// NGワード発言をしたかどうかのチェック
|
||||
boolean isNG = false;
|
||||
for ( String word : LunaChat.config.ngword ) {
|
||||
if ( message.contains(word) ) {
|
||||
message = message.replace(
|
||||
word, getAstariskString(word.length()));
|
||||
isNG = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Japanize変換
|
||||
if ( LunaChat.config.displayJapanize ) {
|
||||
// 2byteコードを含まない場合にのみ、処理を行う
|
||||
@@ -125,6 +142,30 @@ public class Channel {
|
||||
if ( LunaChat.config.loggingChat ) {
|
||||
LunaChat.log(msg);
|
||||
}
|
||||
|
||||
// NGワード発言者に、NGワードアクションを実行する
|
||||
// ただしグローバルチャンネルの場合は、アクションは実行されない
|
||||
if ( isNG && !LunaChat.config.globalChannel.equals(name) ) {
|
||||
if ( LunaChat.config.ngwordAction == NGWordAction.BAN ) {
|
||||
// BANする
|
||||
|
||||
banned.add(player.getName());
|
||||
removeMember(player.getName());
|
||||
String temp = PREINFO + NGWORD_PREFIX + MSG_BANNED;
|
||||
String m = String.format(
|
||||
Utility.replaceColorCode(temp), name);
|
||||
player.sendMessage(m);
|
||||
|
||||
} else if ( LunaChat.config.ngwordAction == NGWordAction.KICK ) {
|
||||
// キックする
|
||||
|
||||
removeMember(player.getName());
|
||||
String temp = PREINFO + NGWORD_PREFIX + MSG_KICKED;
|
||||
String m = String.format(
|
||||
Utility.replaceColorCode(temp), name);
|
||||
player.sendMessage(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,4 +383,17 @@ public class Channel {
|
||||
|
||||
return members.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された文字数のアスタリスクの文字列を返す
|
||||
* @param length アスタリスクの個数
|
||||
* @return 指定された文字数のアスタリスク
|
||||
*/
|
||||
private String getAstariskString(int length) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for ( int i=0; i<length; i++ ) {
|
||||
buf.append("*");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
@@ -40,6 +41,15 @@ public class LunaChatConfig {
|
||||
* 参加させない場合は、から文字列 "" を指定すること。 */
|
||||
protected String globalChannel;
|
||||
|
||||
/** NGワードの設定 */
|
||||
protected List<String> ngword;
|
||||
|
||||
/** NGワードを発言した人に対して実行するアクション<br>
|
||||
* mask = マスクするのみ<br>
|
||||
* kick = マスクしてチャンネルからキックする<br>
|
||||
* ban = マスクしてチャンネルからBANする */
|
||||
protected NGWordAction ngwordAction;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
*/
|
||||
@@ -69,6 +79,8 @@ public class LunaChatConfig {
|
||||
createChannelOnJoinCommand =
|
||||
config.getBoolean("createChannelOnJoinCommand", true);
|
||||
globalChannel = config.getString("globalChannel", "");
|
||||
ngword = config.getStringList("ngword");
|
||||
ngwordAction = NGWordAction.fromID(config.getString("ngwordAction", "mask"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license GPLv3
|
||||
* @copyright Copyright ucchy 2013
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
|
||||
/**
|
||||
* @author ucchy
|
||||
* NGワードを発言した人に与えるアクションの設定の種類
|
||||
*/
|
||||
public enum NGWordAction {
|
||||
|
||||
/** マスクするのみ */
|
||||
MASK("mask"),
|
||||
|
||||
/** マスクしつつ、チャンネルからキックする */
|
||||
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;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする