Skip to content

Commit

Permalink
Simple regular expression support
Browse files Browse the repository at this point in the history
  • Loading branch information
hank9999 committed May 4, 2020
1 parent 9566cc7 commit 69a345e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ChatEvent implements Listener {

Expand All @@ -31,7 +33,8 @@ public void onChat(AsyncPlayerChatEvent event) {
String key_text_a_no = text_low.replaceAll("&[0-9]|&[a-z]", "").replaceAll("\\\\[a-z]|\\\\[A-Z]|/[A-Z]|/[a-z]", "");
String key_text_c_no = key_text_a_no.replaceAll("%[0-9]|%[a-z]", "");
String key_text_replaceall_no = key_text_c_no.replaceAll("[^a-zA-Z0-9\\u4E00-\\u9FA5]", "");
String all = text_low_source + " "
String all = text + " "
+ text_low_source + " "
+ text_low + " "
+ key_text_a + " "
+ text_low.replaceAll("%[0-9]|%[a-z]", "") + " "
Expand All @@ -50,12 +53,16 @@ public void onChat(AsyncPlayerChatEvent event) {
+ key_text_c.replaceAll("[\\p{P}+~$`^=./|<>?~`$^+。、?·|()()<>¥×{}&#%@!!…*丶—【】,;‘:”“’]", "") + " "
+ key_text_c_no.replaceAll("[\\p{P}+~$`^=./|<>?~`$^+。、?·|()()<>¥×{}&#%@!!…*丶—【】,;‘:”“’]", "");

for (String keyword : KeywordBlock.plugin.getConfig().getStringList("words")) {
keyword = keyword.toLowerCase();
if (keyword.equalsIgnoreCase("")) {
for (String keyword1 : KeywordBlock.plugin.getConfig().getStringList("words")) {
String keyword2 = keyword1.toLowerCase();
if (keyword1.equalsIgnoreCase("")) {
continue;
}
if (all.contains(keyword)) {
Pattern p1 = Pattern.compile(keyword1);
Matcher m1 = p1.matcher(all);
Pattern p2 = Pattern.compile(keyword2);
Matcher m2 = p2.matcher(all);
if (m1.lookingAt() || m2.lookingAt()) {
event.setCancelled(true);
for (String warn_message : KeywordBlock.plugin.getConfig().getStringList("message.warn.player")) {
player.sendMessage(Lib.color_translate(warn_message.replaceAll("%player_name%", username).replaceAll("%player_message%", text)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommandPreprocessEvent implements Listener {

Expand Down Expand Up @@ -38,7 +40,8 @@ public void onCommands(PlayerCommandPreprocessEvent e) {
String key_text_a_no = text_low.replaceAll("&[0-9]|&[a-z]", "").replaceAll("\\\\[a-z]|\\\\[A-Z]|/[A-Z]|/[a-z]", "");
String key_text_c_no = key_text_a_no.replaceAll("%[0-9]|%[a-z]", "");
String key_text_replaceall_no = key_text_c_no.replaceAll("[^a-zA-Z0-9\\u4E00-\\u9FA5]", "");
String all = text_low_source + " "
String all = text + " "
+ text_low_source + " "
+ text_low + " "
+ key_text_a + " "
+ text_low.replaceAll("%[0-9]|%[a-z]", "") + " "
Expand All @@ -57,12 +60,16 @@ public void onCommands(PlayerCommandPreprocessEvent e) {
+ key_text_c.replaceAll("[\\p{P}+~$`^=./|<>?~`$^+。、?·|()()<>¥×{}&#%@!!…*丶—【】,;‘:”“’]", "") + " "
+ key_text_c_no.replaceAll("[\\p{P}+~$`^=./|<>?~`$^+。、?·|()()<>¥×{}&#%@!!…*丶—【】,;‘:”“’]", "");

for (String keyword : KeywordBlock.plugin.getConfig().getStringList("words")) {
keyword = keyword.toLowerCase();
if (keyword.equalsIgnoreCase("")) {
for (String keyword1 : KeywordBlock.plugin.getConfig().getStringList("words")) {
String keyword2 = keyword1.toLowerCase();
if (keyword1.equalsIgnoreCase("")) {
continue;
}
if (all.contains(keyword)) {
Pattern p01 = Pattern.compile(keyword1);
Matcher m01 = p01.matcher(all);
Pattern p02 = Pattern.compile(keyword2);
Matcher m02 = p02.matcher(all);
if (m01.lookingAt() || m02.lookingAt()) {
e.setCancelled(true);
for (String warn_message : KeywordBlock.plugin.getConfig().getStringList("message.warn.player")) {
player.sendMessage(Lib.color_translate(warn_message.replaceAll("%player_name%", username).replaceAll("%player_message%", text)));
Expand Down

0 comments on commit 69a345e

Please sign in to comment.