Skip to content

Commit

Permalink
Add op notice
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Mar 11, 2024
1 parent d297000 commit cb7b28f
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/main/java/io/wdsj/asw/command/ConstructCommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.NO_PERMISSION)));
return true;
}
if (args[0].equalsIgnoreCase("help") && (sender.hasPermission("advancedsensitivewords.help") || sender instanceof ConsoleCommandSender)) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.MESSAGE_ON_COMMAND_HELP)));
return true;
}
if (args[0].equalsIgnoreCase("help")) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.NO_PERMISSION)));
return true;
}
}
if (args.length >= 1) {
if (args[0].equalsIgnoreCase("test") && (sender.hasPermission("advancedsensitivewords.test") || sender instanceof ConsoleCommandSender)) {
Expand Down Expand Up @@ -74,7 +82,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return true;
}
}
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.MESSAGE_ON_COMMAND_HELP)));
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.UNKNOWN_COMMAND)));
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/wdsj/asw/command/ConstructTabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
tabComplete.add("status");
} else if (player.hasPermission("advancedsensitivewords.test") && args[0].startsWith("t")) {
tabComplete.add("test");
} else if (player.hasPermission("advancedsensitivewords.help") && args[0].startsWith("h")) {
tabComplete.add("help");
} else if (player.hasPermission("advancedsensitivewords.reload") ||
player.hasPermission("advancedsensitivewords.status") || player.hasPermission("advancedsensitivewords.test")) {
player.hasPermission("advancedsensitivewords.status") || player.hasPermission("advancedsensitivewords.test") || player.hasPermission("advancedsensitivewords.help")) {
tabComplete.add("help");
tabComplete.add("reload");
tabComplete.add("status");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/wdsj/asw/listener/AnvilListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.wdsj.asw.AdvancedSensitiveWords;
import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.Utils;
Expand Down Expand Up @@ -66,6 +67,7 @@ public void onAnvil(InventoryClickEvent event) {
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.ANVIL, originalItemName);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/wdsj/asw/listener/BookListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.impl.list.AdvancedList;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.Utils;
Expand Down Expand Up @@ -111,6 +112,7 @@ public void onBook(PlayerEditBookEvent event) {
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.BOOK, outMessage);
}

if (settingsManager.getProperty(PluginSettings.BOOK_SEND_MESSAGE) && shouldSendMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.TimingUtils;
Expand Down Expand Up @@ -56,6 +57,7 @@ public void onPlayerHeldItem(PlayerItemHeldEvent event) {
}
long endTime = System.currentTimeMillis();
TimingUtils.addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.ITEM, originalName);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/wdsj/asw/listener/PlayerLoginListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.wdsj.asw.AdvancedSensitiveWords;
import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.PlayerUtils;
Expand Down Expand Up @@ -55,6 +56,7 @@ public void onLogin(PlayerLoginEvent event) {
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.NAME, playerName);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/io/wdsj/asw/listener/SignListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.impl.list.AdvancedList;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.Utils;
Expand Down Expand Up @@ -95,6 +96,7 @@ public void onSign(SignChangeEvent event) {
messagesFilteredNum.getAndIncrement();
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.SIGN, outMessage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.wdsj.asw.AdvancedSensitiveWords;
import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.Utils;
Expand Down Expand Up @@ -76,6 +77,7 @@ public void onPacketReceive(PacketReceiveEvent event) {
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.CHAT, originalMessage);
return;
}

Expand Down Expand Up @@ -105,6 +107,7 @@ public void onPacketReceive(PacketReceiveEvent event) {
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.CHAT, originalContext);
}
}
} else if (packetType == PacketType.Play.Client.CHAT_COMMAND) {
Expand Down Expand Up @@ -137,6 +140,7 @@ public void onPacketReceive(PacketReceiveEvent event) {
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.CHAT, "/" + originalCommand);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.wdsj.asw.AdvancedSensitiveWords;
import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.Utils;
Expand Down Expand Up @@ -73,6 +74,7 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.CHAT, message);
return;
}

Expand All @@ -99,6 +101,7 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent
}
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.CHAT, originalContext);
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/io/wdsj/asw/manage/notice/Notifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.wdsj.asw.manage.notice;

import io.wdsj.asw.event.EventType;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import java.util.Collection;

import static io.wdsj.asw.AdvancedSensitiveWords.messagesManager;
import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager;

public class Notifier {
public static void notice(Player violatedPlayer, EventType eventType, String originalMessage) {
if (!settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) return;
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
for (Player player : players) {
if (player.hasPermission("advancedsensitivewords.notice")) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.ADMIN_REMINDER).replace("%player%", violatedPlayer.getName()).replace("%type%", eventType.toString()).replace("%message%", originalMessage)));
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/io/wdsj/asw/setting/PluginMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class PluginMessages implements SettingsHolder {
public static final Property<String> MESSAGE_ON_COMMAND_TEST_NOT_INIT = newProperty("Plugin.commandTest.testNotInit", "&c插件还没有初始化完毕喵");
@Comment("没有权限执行该指令")
public static final Property<String> NO_PERMISSION = newProperty("Plugin.noPermission", "&c你没有权限执行该指令.");
@Comment("未知命令")
public static final Property<String> UNKNOWN_COMMAND = newProperty("Plugin.unknownCommand", "&c未知命令, 请使用 &7/asw help");
@Comment("管理员提醒消息")
public static final Property<String> ADMIN_REMINDER = newProperty("Plugin.noticeOperator", "&f[&bASW&7Notify&f]&7玩家 &c%player% &7触发了敏感词检测(%type%)(原消息: %message%)");

@Override
public void registerComments(CommentsConfiguration conf) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/wdsj/asw/setting/PluginSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class PluginSettings implements SettingsHolder {
@Comment({"是否记录违规消息(存储在violations.log中)",
"Whether to log violations (stored in violations.log)"})
public static final Property<Boolean> LOG_VIOLATION = newProperty("Plugin.logViolation", true);
@Comment({"玩家违规时是否提醒管理员(需权限advancedsensitivewords.notice)",
"Notify operators when player violated"})
public static final Property<Boolean> NOTICE_OPERATOR = newProperty("Plugin.noticeOperator", true);

@Comment({"是否在插件启动时自动清除旧的日志文件",
"Whether to automatically clear old log files on plugin startup"})
Expand Down Expand Up @@ -84,8 +87,8 @@ public class PluginSettings implements SettingsHolder {
@Comment({"忽略格式化符号§",
"Ignore format codes"})
public static final Property<Boolean> IGNORE_FORMAT_CODE = newProperty("Plugin.ignoreFormatCode", false);
@Comment({"备用格式化符号",
"Alternate code codes"})
@Comment({"忽略备用格式化符号",
"Alternate code codes to ignore"})
public static final Property<String> ALT_COLOR_CODE = newProperty("Plugin.altColorCode", "&");

@Comment({"检测大小写",
Expand Down
7 changes: 0 additions & 7 deletions src/main/resources/dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56673,13 +56673,6 @@ z以留吧以其以武
高压锅炸弹制作步骤
高压锅炸弹制造图
高压麻醉枪出售
高原奈美种子
高原流美种子
高原珠里种子
高句丽
高品质香烟
高哌啶
高嘉
高官
高官互调
高官子女
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/messages_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ Plugin:
testNotInit: '&cPlugin has not been initialized'
#No permission
noPermission: '&cYou do not have permission to execute the command.'
#Unknown command
unknownCommand: '&cUnknown command, please use &7/asw help.'
#Admin notice
noticeOperator: '&f[&bASW&7Notify&f]&7Player &c%player% &7failed anti-swear check(%type%)(Message: %message%)'
4 changes: 4 additions & 0 deletions src/main/resources/messages_zhcn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ Plugin:
testNotInit: '&c插件还没有初始化完毕喵'
# 没有权限执行该指令
noPermission: '&c你没有权限执行该指令.'
# 未知命令
unknownCommand: '&c未知命令, 请使用 &7/asw help'
# 管理员提醒消息
noticeOperator: '&f[&bASW&7Notify&f]&7玩家 &c%player% &7触发了敏感词检测(%type%)(原消息: %message%)'
6 changes: 6 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@ permissions:
advancedsensitivewords.test:
description: Test the Advanced Sensitive Words filter.
default: op
advancedsensitivewords.help:
description: Show the Advanced Sensitive Words filter help.
default: op
advancedsensitivewords.notice:
description: Retrive the notice message when player violated.
default: op
# Love you
# Support me on Afdian https://afdian.net/a/114514woxiuyuan/

0 comments on commit cb7b28f

Please sign in to comment.