Skip to content

Commit

Permalink
Some revert & improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Mar 10, 2024
1 parent 6daabf1 commit a38fcd6
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/wdsj/asw/event/ASWFilterEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public List<String> getFilteredWordList() {

/**
* Get the event type.
* Available event types: CHAT, BOOK, NAME, SIGN, ANVIL
* Available event types: CHAT, BOOK, NAME, SIGN, ANVIL, ITEM
* @return the event type.
*/
@NotNull
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/io/wdsj/asw/listener/AnvilListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import static io.wdsj.asw.AdvancedSensitiveWords.*;
import static io.wdsj.asw.util.TimingUtils.addProcessStatistic;
import static io.wdsj.asw.util.Utils.getIgnoreFormatCodeRegex;
import static io.wdsj.asw.util.Utils.messagesFilteredNum;

public class AnvilListener implements Listener {
Expand All @@ -40,7 +39,6 @@ public void onAnvil(InventoryClickEvent event) {
ItemMeta itemMeta = outputItem.getItemMeta();
if (itemMeta != null && itemMeta.hasDisplayName()) {
String originalItemName = itemMeta.getDisplayName();
if (settingsManager.getProperty(PluginSettings.IGNORE_FORMAT_CODE)) originalItemName = originalItemName.replaceAll(getIgnoreFormatCodeRegex(), "");
List<String> censoredWords = AdvancedSensitiveWords.sensitiveWordBs.findAll(originalItemName);
if (!censoredWords.isEmpty()) {
long startTime = System.currentTimeMillis();
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/io/wdsj/asw/listener/BookListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import static io.wdsj.asw.AdvancedSensitiveWords.*;
import static io.wdsj.asw.util.TimingUtils.addProcessStatistic;
import static io.wdsj.asw.util.Utils.getIgnoreFormatCodeRegex;
import static io.wdsj.asw.util.Utils.messagesFilteredNum;

public class BookListener implements Listener {
Expand All @@ -44,7 +43,6 @@ public void onBook(PlayerEditBookEvent event) {
if (bookMeta.hasPages()) {
for (String originalPage : originalPages) {
if (skipReturnLine) originalPage = originalPage.replace("\n", "").replace("§0", "");
if (settingsManager.getProperty(PluginSettings.IGNORE_FORMAT_CODE)) originalPage = originalPage.replaceAll(getIgnoreFormatCodeRegex(), "");
boolean isBookCached = BookCache.isBookCached(originalPage);
List<String> censoredWordList = isBookCached && isCacheEnabled ? BookCache.getCachedBookSensitiveWordList(originalPage) : AdvancedSensitiveWords.sensitiveWordBs.findAll(originalPage);
if (!censoredWordList.isEmpty()) {
Expand All @@ -69,7 +67,6 @@ public void onBook(PlayerEditBookEvent event) {
}
String originalAuthor = event.getNewBookMeta().getAuthor();
if (originalAuthor != null) {
if (settingsManager.getProperty(PluginSettings.IGNORE_FORMAT_CODE)) originalAuthor = originalAuthor.replaceAll(getIgnoreFormatCodeRegex(), "");
List<String> censoredWordListAuthor = AdvancedSensitiveWords.sensitiveWordBs.findAll(originalAuthor);
if (!censoredWordListAuthor.isEmpty()) {
String processedAuthor = AdvancedSensitiveWords.sensitiveWordBs.replace(originalAuthor);
Expand All @@ -88,8 +85,6 @@ public void onBook(PlayerEditBookEvent event) {

String originalTitle = event.getNewBookMeta().getTitle();
if (originalTitle != null) {
if (settingsManager.getProperty(PluginSettings.IGNORE_FORMAT_CODE))
originalTitle = originalTitle.replaceAll(getIgnoreFormatCodeRegex(), "");
List<String> censoredWordListTitle = AdvancedSensitiveWords.sensitiveWordBs.findAll(originalTitle);
if (!censoredWordListTitle.isEmpty()) {
String processedTitle = AdvancedSensitiveWords.sensitiveWordBs.replace(originalTitle);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/wdsj/asw/listener/BroadCastListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@

import static io.wdsj.asw.AdvancedSensitiveWords.*;
import static io.wdsj.asw.util.TimingUtils.addProcessStatistic;
import static io.wdsj.asw.util.Utils.getIgnoreFormatCodeRegex;
import static io.wdsj.asw.util.Utils.messagesFilteredNum;

public class BroadCastListener implements Listener {

@EventHandler(priority = EventPriority.LOWEST)
public void onBroadCast(BroadcastMessageEvent event) {
if (!isInitialized || !settingsManager.getProperty(PluginSettings.CHAT_BROADCAST_CHECK)) return;
String originalMessage = settingsManager.getProperty(PluginSettings.IGNORE_FORMAT_CODE) ? event.getMessage().replaceAll(getIgnoreFormatCodeRegex(), "") : event.getMessage();
String originalMessage = event.getMessage();
long startTime = System.currentTimeMillis();
List<String> censoredWordList = sensitiveWordBs.findAll(originalMessage);
if (!censoredWordList.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.List;

import static io.wdsj.asw.AdvancedSensitiveWords.*;
import static io.wdsj.asw.util.Utils.getIgnoreFormatCodeRegex;
import static io.wdsj.asw.util.Utils.messagesFilteredNum;

public class PlayerHeldItemListener implements Listener {
Expand All @@ -34,7 +33,6 @@ public void onPlayerHeldItem(PlayerItemHeldEvent event) {
ItemMeta meta = item.getItemMeta();
if (meta != null && meta.hasDisplayName()) {
String originalName = meta.getDisplayName();
if (settingsManager.getProperty(PluginSettings.IGNORE_FORMAT_CODE)) originalName = originalName.replaceAll(getIgnoreFormatCodeRegex(), "");
long startTime = System.currentTimeMillis();
List<String> censoredWordList = sensitiveWordBs.findAll(originalName);
if (!censoredWordList.isEmpty()) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/io/wdsj/asw/listener/SignListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import static io.wdsj.asw.AdvancedSensitiveWords.*;
import static io.wdsj.asw.util.TimingUtils.addProcessStatistic;
import static io.wdsj.asw.util.Utils.getIgnoreFormatCodeRegex;
import static io.wdsj.asw.util.Utils.messagesFilteredNum;

public class SignListener implements Listener {
Expand All @@ -41,7 +40,6 @@ public void onSign(SignChangeEvent event) {
StringBuilder originalMultiMessages = new StringBuilder();
for (int line = 0; line < 4; ++line) {
String originalMessage = event.getLine(line);
if (settingsManager.getProperty(PluginSettings.IGNORE_FORMAT_CODE) && originalMessage != null) originalMessage = originalMessage.replaceAll(getIgnoreFormatCodeRegex(), "");
assert originalMessage != null;
List<String> censoredWordList = AdvancedSensitiveWords.sensitiveWordBs.findAll(originalMessage);
if (!censoredWordList.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void onPacketReceive(PacketReceiveEvent event) {
String userName = user.getName();
if (packetType == PacketType.Play.Client.CHAT_MESSAGE) {
WrapperPlayClientChatMessage wrapperPlayClientChatMessage = new WrapperPlayClientChatMessage(event);
String originalMessage = settingsManager.getProperty(PluginSettings.IGNORE_FORMAT_CODE) ? wrapperPlayClientChatMessage.getMessage().replaceAll(getIgnoreFormatCodeRegex(), "") : wrapperPlayClientChatMessage.getMessage();
String originalMessage = wrapperPlayClientChatMessage.getMessage();
if (shouldNotProcess(player, originalMessage)) return;
long startTime = System.currentTimeMillis();
// Word check
Expand Down Expand Up @@ -110,7 +110,7 @@ public void onPacketReceive(PacketReceiveEvent event) {
}
} else if (packetType == PacketType.Play.Client.CHAT_COMMAND) {
WrapperPlayClientChatCommand wrapperPlayClientChatCommand = new WrapperPlayClientChatCommand(event);
String originalCommand = settingsManager.getProperty(PluginSettings.IGNORE_FORMAT_CODE) ? wrapperPlayClientChatCommand.getCommand().replaceAll(getIgnoreFormatCodeRegex(), "") : wrapperPlayClientChatCommand.getCommand();
String originalCommand = wrapperPlayClientChatCommand.getCommand();
if (shouldNotProcess(player, "/" + originalCommand)) return;
long startTime = System.currentTimeMillis();
List<String> censoredWords = AdvancedSensitiveWords.sensitiveWordBs.findAll(originalCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent
if (event.getPacketType() == com.comphenix.protocol.PacketType.Play.Client.CHAT && isInitialized) {
Player player = event.getPlayer();
assert player != null; // In some cases, player maybe null
String message = settingsManager.getProperty(PluginSettings.IGNORE_FORMAT_CODE) ? event.getPacket().getStrings().read(0).replaceAll(getIgnoreFormatCodeRegex(), "") : event.getPacket().getStrings().read(0);
String message = event.getPacket().getStrings().read(0);
if (isCommandAndWhiteListed(message) || player.hasPermission("advancedsensitivewords.bypass"))
return;
if (isAuthMeAvailable && settingsManager.getProperty(PluginSettings.ENABLE_AUTHME_COMPATIBILITY)) {
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/wdsj/asw/method/CharIgnore.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.houbb.sensitive.word.api.ISensitiveWordCharIgnore;
import com.github.houbb.sensitive.word.api.context.InnerSensitiveWordContext;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.Utils;

import java.util.Set;

Expand All @@ -12,6 +13,23 @@
public class CharIgnore implements ISensitiveWordCharIgnore {
@Override
public boolean ignore(int i, char[] chars, InnerSensitiveWordContext innerSensitiveWordContext) {
if (settingsManager.getProperty(PluginSettings.IGNORE_FORMAT_CODE)) {
String regex = Utils.getIgnoreFormatCodeRegex();
if (i + 1 < chars.length) {
String nextTwoChars = String.valueOf(chars[i]) +
chars[i + 1];
if (nextTwoChars.matches(regex)) {
return true;
}
}
if (i - 1 >= 0) {
String nextTwoChars = String.valueOf(chars[i - 1]) +
chars[i];
if (nextTwoChars.matches(regex)) {
return true;
}
}
}
Set<Character> SET = StringUtil.toCharSet(settingsManager.getProperty(PluginSettings.IGNORE_CHAR));
char c = chars[i];
return SET.contains(c);
Expand Down

0 comments on commit a38fcd6

Please sign in to comment.