diff --git a/pom.xml b/pom.xml index 4669b02..7cc7913 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ ChatEx 2024 - 3.2.0 + 3.2.1 ChatManagement plugin for Bukkit https://www.spigotmc.org/resources/chatex-continued.71041/ diff --git a/src/main/java/de/jeter/chatex/ChatListener.java b/src/main/java/de/jeter/chatex/ChatListener.java index aea6839..2160225 100644 --- a/src/main/java/de/jeter/chatex/ChatListener.java +++ b/src/main/java/de/jeter/chatex/ChatListener.java @@ -24,7 +24,6 @@ import de.jeter.chatex.utils.adManager.AdManager; import de.jeter.chatex.utils.adManager.SimpleAdManager; import de.jeter.chatex.utils.adManager.SmartAdManager; -import de.jeter.chatex.utils.blockedWords.BlockedWords; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -39,8 +38,6 @@ public class ChatListener implements Listener { private final AdManager adManager = Config.ADS_SMART_MANAGER.getBoolean() ? new SmartAdManager() : new SimpleAdManager(); - private final BlockedWords blockedWords = new BlockedWords(); - @EventHandler(priority = EventPriority.LOWEST) public void onLowest(final AsyncPlayerChatEvent event) { @@ -132,15 +129,18 @@ private void executeChatEvent(AsyncPlayerChatEvent event) { LogHelper.debug("Player did not activate the AdBlocker. Continuing..."); - if (blockedWords.isBlocked(chatMessage)) { - String message = Locales.MESSAGES_BLOCKED.getString(null); - MessageContainsBlockedWordEvent messageContainsBlockedWordEvent = new MessageContainsBlockedWordEvent(player, chatMessage, message); - Bukkit.getPluginManager().callEvent(messageContainsBlockedWordEvent); - event.setCancelled(!messageContainsBlockedWordEvent.isCancelled()); - chatMessage = messageContainsBlockedWordEvent.getMessage(); - if (!messageContainsBlockedWordEvent.isCancelled()) { - event.getPlayer().sendMessage(messageContainsBlockedWordEvent.getPluginMessage()); - return; + for(String block : Config.BLOCKED_WORDS.getStringList()) { + if(chatMessage.contains(block)) { + LogHelper.debug("Player activated wordblocker! ChatMessage: " + chatMessage + " contains blockedWord: " + block); + String message = Locales.MESSAGES_BLOCKED.getString(null); + MessageContainsBlockedWordEvent messageContainsBlockedWordEvent = new MessageContainsBlockedWordEvent(player, chatMessage, message); + Bukkit.getPluginManager().callEvent(messageContainsBlockedWordEvent); + event.setCancelled(!messageContainsBlockedWordEvent.isCancelled()); + chatMessage = messageContainsBlockedWordEvent.getMessage(); + if (!messageContainsBlockedWordEvent.isCancelled()) { + event.getPlayer().sendMessage(messageContainsBlockedWordEvent.getPluginMessage()); + return; + } } } diff --git a/src/main/java/de/jeter/chatex/utils/blockedWords/BlockedWords.java b/src/main/java/de/jeter/chatex/utils/blockedWords/BlockedWords.java deleted file mode 100644 index be44c77..0000000 --- a/src/main/java/de/jeter/chatex/utils/blockedWords/BlockedWords.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.jeter.chatex.utils.blockedWords; - -import de.jeter.chatex.ChatEx; -import de.jeter.chatex.utils.Config; - -import java.util.LinkedList; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -public class BlockedWords { - public static final String REGEX_PREFIX = "%reg:"; - private final LinkedList blockers = new LinkedList<>(); - - public BlockedWords() { - for (String word : Config.BLOCKED_WORDS.getStringList()) { - if (word.startsWith(REGEX_PREFIX)) { - String stringPattern = word.substring(REGEX_PREFIX.length()); - try { - Pattern pattern = Pattern.compile(stringPattern); - blockers.add(new RegexBlocker(pattern)); - } catch (PatternSyntaxException exception) { - ChatEx.getInstance().getLogger().warning("Failed to compile regex pattern " + stringPattern); - } - continue; - } - blockers.add(new StringBlocker(word)); - } - } - - public boolean isBlocked(String string) { - return blockers.stream().anyMatch(b -> b.test(string)); - } -} diff --git a/src/main/java/de/jeter/chatex/utils/blockedWords/Blocker.java b/src/main/java/de/jeter/chatex/utils/blockedWords/Blocker.java deleted file mode 100644 index 114a5b4..0000000 --- a/src/main/java/de/jeter/chatex/utils/blockedWords/Blocker.java +++ /dev/null @@ -1,6 +0,0 @@ -package de.jeter.chatex.utils.blockedWords; - -import java.util.function.Predicate; - -public interface Blocker extends Predicate { -} diff --git a/src/main/java/de/jeter/chatex/utils/blockedWords/RegexBlocker.java b/src/main/java/de/jeter/chatex/utils/blockedWords/RegexBlocker.java deleted file mode 100644 index ea7fe31..0000000 --- a/src/main/java/de/jeter/chatex/utils/blockedWords/RegexBlocker.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.jeter.chatex.utils.blockedWords; - -import java.util.regex.Pattern; - -public class RegexBlocker implements Blocker { - private final Pattern pattern; - - public RegexBlocker(Pattern pattern) { - this.pattern = pattern; - } - - @Override - public boolean test(String s) { - return pattern.matcher(s).find(); - } -} diff --git a/src/main/java/de/jeter/chatex/utils/blockedWords/StringBlocker.java b/src/main/java/de/jeter/chatex/utils/blockedWords/StringBlocker.java deleted file mode 100644 index bd8d404..0000000 --- a/src/main/java/de/jeter/chatex/utils/blockedWords/StringBlocker.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.jeter.chatex.utils.blockedWords; - -public class StringBlocker implements Blocker { - - private final String blocking; - - public StringBlocker(String blocking) { - this.blocking = blocking.toLowerCase(); - } - - @Override - public boolean test(String s) { - return s.toLowerCase().contains(blocking); - } -}