This commit is contained in:
@@ -11,6 +11,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -996,6 +997,18 @@ public class ChatFilterManager {
|
|||||||
*/
|
*/
|
||||||
public String applyPunishment(Player player,
|
public String applyPunishment(Player player,
|
||||||
int violation) {
|
int violation) {
|
||||||
|
return applyPunishment(player, violation,
|
||||||
|
"触发敏感词", "系统");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用处罚规则(可指定原因和执行人)。
|
||||||
|
* 自动通知管理员,kick/ban/banip 全服广播,mute 给详细消息。
|
||||||
|
*/
|
||||||
|
public String applyPunishment(Player player,
|
||||||
|
int violation,
|
||||||
|
String reason,
|
||||||
|
String issuer) {
|
||||||
String type = "warn";
|
String type = "warn";
|
||||||
int duration = muteDuration;
|
int duration = muteDuration;
|
||||||
int maxRule = 0;
|
int maxRule = 0;
|
||||||
@@ -1014,36 +1027,56 @@ public class ChatFilterManager {
|
|||||||
if (type.equals("mute")) {
|
if (type.equals("mute")) {
|
||||||
if (isMuted(player.getName()))
|
if (isMuted(player.getName()))
|
||||||
return "already_muted";
|
return "already_muted";
|
||||||
|
long expireMs = System.currentTimeMillis()
|
||||||
|
+ (long) duration * 1000L;
|
||||||
mutedPlayers.put(player.getName(),
|
mutedPlayers.put(player.getName(),
|
||||||
System.currentTimeMillis()
|
expireMs);
|
||||||
+ (long) duration
|
if (reason != null && !reason.isEmpty())
|
||||||
* 1000L);
|
muteReasons.put(player.getName(),
|
||||||
|
reason);
|
||||||
}
|
}
|
||||||
final String fType = type;
|
final String fType = type;
|
||||||
final int fDur = duration;
|
final int fDur = duration;
|
||||||
final int fV = violation;
|
|
||||||
final String fName = player.getName();
|
final String fName = player.getName();
|
||||||
|
final String fReason = reason != null
|
||||||
|
? reason : "触发敏感词";
|
||||||
|
final String fIssuer = issuer != null
|
||||||
|
? issuer : "系统";
|
||||||
Bukkit.getScheduler().runTask(plugin,
|
Bukkit.getScheduler().runTask(plugin,
|
||||||
() -> {
|
() -> {
|
||||||
Player p = Bukkit.getPlayer(fName);
|
Player p = Bukkit.getPlayer(fName);
|
||||||
if (p == null) return;
|
if (p == null) return;
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
long endMs = now
|
||||||
|
+ (long) fDur * 1000L;
|
||||||
|
String startStr = new SimpleDateFormat(
|
||||||
|
"yyyy年M月d日 HH点mm分")
|
||||||
|
.format(new Date(now));
|
||||||
|
String endStr = new SimpleDateFormat(
|
||||||
|
"yyyy年M月d日 HH点mm分")
|
||||||
|
.format(new Date(endMs));
|
||||||
|
String durStr = fmtDuration(fDur);
|
||||||
switch (fType) {
|
switch (fType) {
|
||||||
case "warn":
|
case "warn":
|
||||||
// 警告不处罚,只提示
|
|
||||||
break;
|
break;
|
||||||
case "mute":
|
case "mute":
|
||||||
p.sendMessage(
|
p.sendMessage("§c§l你因为" + fReason
|
||||||
msg("chat_muted"));
|
+ "被" + fIssuer
|
||||||
|
+ "执行禁言" + durStr
|
||||||
|
+ ",处罚开始时间:"
|
||||||
|
+ startStr
|
||||||
|
+ " 处罚到期时间:"
|
||||||
|
+ endStr);
|
||||||
break;
|
break;
|
||||||
case "kick":
|
case "kick":
|
||||||
p.kickPlayer(
|
p.kickPlayer("§c你因" + fReason
|
||||||
msg("chat_muted"));
|
+ "被踢出服务器");
|
||||||
break;
|
break;
|
||||||
case "ban":
|
case "ban":
|
||||||
Bukkit.dispatchCommand(
|
Bukkit.dispatchCommand(
|
||||||
Bukkit.getConsoleSender(),
|
Bukkit.getConsoleSender(),
|
||||||
"ban " + fName
|
"ban " + fName
|
||||||
+ " §c多次发送违规链接");
|
+ " §c" + fReason);
|
||||||
break;
|
break;
|
||||||
case "banip":
|
case "banip":
|
||||||
InetSocketAddress addr =
|
InetSocketAddress addr =
|
||||||
@@ -1055,10 +1088,37 @@ public class ChatFilterManager {
|
|||||||
Bukkit.dispatchCommand(
|
Bukkit.dispatchCommand(
|
||||||
Bukkit.getConsoleSender(),
|
Bukkit.getConsoleSender(),
|
||||||
"ban-ip " + ip
|
"ban-ip " + ip
|
||||||
+ " §c发送违规链接");
|
+ " §c" + fReason);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// 非 warn → 通知在线管理员
|
||||||
|
if (!"warn".equals(fType)) {
|
||||||
|
String adminMsg = "§c[聊天监控] §f玩家 "
|
||||||
|
+ fName + " 因" + fReason
|
||||||
|
+ "被" + fIssuer + "处罚:"
|
||||||
|
+ fType;
|
||||||
|
if ("mute".equals(fType))
|
||||||
|
adminMsg += " " + durStr;
|
||||||
|
for (Player op :
|
||||||
|
Bukkit.getOnlinePlayers()) {
|
||||||
|
if (op.hasPermission(
|
||||||
|
"sdf1.admin")
|
||||||
|
|| op.isOp()) {
|
||||||
|
op.sendMessage(adminMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// kick/ban/banip → 全服公告
|
||||||
|
if (fType.equals("kick")
|
||||||
|
|| fType.equals("ban")
|
||||||
|
|| fType.equals("banip")) {
|
||||||
|
Bukkit.broadcastMessage(
|
||||||
|
"§c[公告] §f玩家 " + fName
|
||||||
|
+ " 因" + fReason
|
||||||
|
+ "被" + fIssuer
|
||||||
|
+ "处罚");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3386,7 +3386,10 @@ public class Main extends JavaPlugin
|
|||||||
}
|
}
|
||||||
chatFilter.incrementViolation(p.getName());
|
chatFilter.incrementViolation(p.getName());
|
||||||
int sc = chatFilter.getViolationCount(p.getName());
|
int sc = chatFilter.getViolationCount(p.getName());
|
||||||
String ptype = chatFilter.applyPunishment(p, sc);
|
String swReason = "说出敏感词("
|
||||||
|
+ ms.get(0) + ")";
|
||||||
|
String ptype = chatFilter.applyPunishment(
|
||||||
|
p, sc, swReason, "系统");
|
||||||
if (!"warn".equals(ptype)) {
|
if (!"warn".equals(ptype)) {
|
||||||
chatFilter.resetViolationCount(p.getName());
|
chatFilter.resetViolationCount(p.getName());
|
||||||
}
|
}
|
||||||
@@ -3452,7 +3455,8 @@ public class Main extends JavaPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处罚
|
// 处罚
|
||||||
chatFilter.applyPunishment(p, count);
|
chatFilter.applyPunishment(p, count,
|
||||||
|
"发送违规链接", "系统");
|
||||||
|
|
||||||
// ===== 广告机检测(独立于URL过滤) =====
|
// ===== 广告机检测(独立于URL过滤) =====
|
||||||
if (chatFilter.checkAdBotBehavior(p.getName(), msg)) {
|
if (chatFilter.checkAdBotBehavior(p.getName(), msg)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user