diff --git a/CarbonChatModeration/src/main/java/net/draycia/carbonmoderation/listeners/FilterHandler.java b/CarbonChatModeration/src/main/java/net/draycia/carbonmoderation/listeners/FilterHandler.java index 257b095f..2a35783e 100644 --- a/CarbonChatModeration/src/main/java/net/draycia/carbonmoderation/listeners/FilterHandler.java +++ b/CarbonChatModeration/src/main/java/net/draycia/carbonmoderation/listeners/FilterHandler.java @@ -10,6 +10,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import java.util.List; +import java.util.regex.Pattern; public class FilterHandler implements Listener { @@ -39,6 +40,13 @@ public class FilterHandler implements Listener { event.setMessage(event.getMessage().replaceAll(word, replacement)); } } + + for (String blockedWord : config.getStringList("filters.blocked-words")) { + if (Pattern.compile(blockedWord).matcher(event.getMessage()).find()) { + event.setCancelled(true); + break; + } + } } private boolean channelUsesFilter(ChatChannel chatChannel) { diff --git a/CarbonChatModeration/src/main/resources/config.yml b/CarbonChatModeration/src/main/resources/config.yml index 91646512..855eebd6 100644 --- a/CarbonChatModeration/src/main/resources/config.yml +++ b/CarbonChatModeration/src/main/resources/config.yml @@ -6,12 +6,18 @@ caps-protection: filters: enabled: true + # The keys ("****" for example) are what the text is replaced with + # The strings in the lists ("lag" etc) are what's replaced filters: + # In this example, any instance of "lag" or "laggggg" will be replaced with "****" "****": - "lag" - "la[g]+" "": - "broccoli sucks" + # Anything in blocked-words will prevent the message from being sent at all. + blocked-words: + - "pineapple doesn't belong on pizza" channels: - '*' # Use '*' to mean all channels