diff --git a/src/main/java/io/wdsj/asw/event/ASWFilterEvent.java b/src/main/java/io/wdsj/asw/event/ASWFilterEvent.java index 6290a17..832ac06 100644 --- a/src/main/java/io/wdsj/asw/event/ASWFilterEvent.java +++ b/src/main/java/io/wdsj/asw/event/ASWFilterEvent.java @@ -75,7 +75,7 @@ public List 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 diff --git a/src/main/java/io/wdsj/asw/listener/AnvilListener.java b/src/main/java/io/wdsj/asw/listener/AnvilListener.java index 9af539e..cd52183 100644 --- a/src/main/java/io/wdsj/asw/listener/AnvilListener.java +++ b/src/main/java/io/wdsj/asw/listener/AnvilListener.java @@ -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 { @@ -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 censoredWords = AdvancedSensitiveWords.sensitiveWordBs.findAll(originalItemName); if (!censoredWords.isEmpty()) { long startTime = System.currentTimeMillis(); diff --git a/src/main/java/io/wdsj/asw/listener/BookListener.java b/src/main/java/io/wdsj/asw/listener/BookListener.java index b4a2db5..e926424 100644 --- a/src/main/java/io/wdsj/asw/listener/BookListener.java +++ b/src/main/java/io/wdsj/asw/listener/BookListener.java @@ -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 { @@ -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 censoredWordList = isBookCached && isCacheEnabled ? BookCache.getCachedBookSensitiveWordList(originalPage) : AdvancedSensitiveWords.sensitiveWordBs.findAll(originalPage); if (!censoredWordList.isEmpty()) { @@ -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 censoredWordListAuthor = AdvancedSensitiveWords.sensitiveWordBs.findAll(originalAuthor); if (!censoredWordListAuthor.isEmpty()) { String processedAuthor = AdvancedSensitiveWords.sensitiveWordBs.replace(originalAuthor); @@ -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 censoredWordListTitle = AdvancedSensitiveWords.sensitiveWordBs.findAll(originalTitle); if (!censoredWordListTitle.isEmpty()) { String processedTitle = AdvancedSensitiveWords.sensitiveWordBs.replace(originalTitle); diff --git a/src/main/java/io/wdsj/asw/listener/BroadCastListener.java b/src/main/java/io/wdsj/asw/listener/BroadCastListener.java index d3e2760..e76f1c8 100644 --- a/src/main/java/io/wdsj/asw/listener/BroadCastListener.java +++ b/src/main/java/io/wdsj/asw/listener/BroadCastListener.java @@ -11,7 +11,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 BroadCastListener implements Listener { @@ -19,7 +18,7 @@ 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 censoredWordList = sensitiveWordBs.findAll(originalMessage); if (!censoredWordList.isEmpty()) { diff --git a/src/main/java/io/wdsj/asw/listener/PlayerHeldItemListener.java b/src/main/java/io/wdsj/asw/listener/PlayerHeldItemListener.java index def2cf3..8c276ed 100644 --- a/src/main/java/io/wdsj/asw/listener/PlayerHeldItemListener.java +++ b/src/main/java/io/wdsj/asw/listener/PlayerHeldItemListener.java @@ -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 { @@ -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 censoredWordList = sensitiveWordBs.findAll(originalName); if (!censoredWordList.isEmpty()) { diff --git a/src/main/java/io/wdsj/asw/listener/SignListener.java b/src/main/java/io/wdsj/asw/listener/SignListener.java index b9862a3..531d8f4 100644 --- a/src/main/java/io/wdsj/asw/listener/SignListener.java +++ b/src/main/java/io/wdsj/asw/listener/SignListener.java @@ -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 { @@ -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 censoredWordList = AdvancedSensitiveWords.sensitiveWordBs.findAll(originalMessage); if (!censoredWordList.isEmpty()) { diff --git a/src/main/java/io/wdsj/asw/listener/packet/ASWPacketListener.java b/src/main/java/io/wdsj/asw/listener/packet/ASWPacketListener.java index b74e390..fb9fabd 100644 --- a/src/main/java/io/wdsj/asw/listener/packet/ASWPacketListener.java +++ b/src/main/java/io/wdsj/asw/listener/packet/ASWPacketListener.java @@ -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 @@ -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 censoredWords = AdvancedSensitiveWords.sensitiveWordBs.findAll(originalCommand); diff --git a/src/main/java/io/wdsj/asw/listener/packet/ProtocolLibListener.java b/src/main/java/io/wdsj/asw/listener/packet/ProtocolLibListener.java index f513176..5c948fd 100644 --- a/src/main/java/io/wdsj/asw/listener/packet/ProtocolLibListener.java +++ b/src/main/java/io/wdsj/asw/listener/packet/ProtocolLibListener.java @@ -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)) { diff --git a/src/main/java/io/wdsj/asw/method/CharIgnore.java b/src/main/java/io/wdsj/asw/method/CharIgnore.java index b8999f0..18a4d52 100644 --- a/src/main/java/io/wdsj/asw/method/CharIgnore.java +++ b/src/main/java/io/wdsj/asw/method/CharIgnore.java @@ -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; @@ -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 SET = StringUtil.toCharSet(settingsManager.getProperty(PluginSettings.IGNORE_CHAR)); char c = chars[i]; return SET.contains(c);