Add blocked-words filter

This commit is contained in:
Draycia committed 2020-07-30 23:21:08 -07:00
1 parent 70ca812c59
commit 88af664e61
2 files changed
+14

No files matched your search

@@ -10,6 +10,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
public class FilterHandler implements Listener { public class FilterHandler implements Listener {
@@ -39,6 +40,13 @@ public class FilterHandler implements Listener {
event.setMessage(event.getMessage().replaceAll(word, replacement)); 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) { private boolean channelUsesFilter(ChatChannel chatChannel) {
@@ -6,12 +6,18 @@ caps-protection:
filters: filters:
enabled: true 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: filters:
# In this example, any instance of "lag" or "laggggg" will be replaced with "****"
"****": "****":
- "lag" - "lag"
- "la[g]+" - "la[g]+"
"": "":
- "broccoli sucks" - "broccoli sucks"
# Anything in blocked-words will prevent the message from being sent at all.
blocked-words:
- "pineapple doesn't belong on pizza"
channels: channels:
- '*' # Use '*' to mean all channels - '*' # Use '*' to mean all channels