Skip to content

Commit

Permalink
overwrite detection
Browse files Browse the repository at this point in the history
  • Loading branch information
hank9999 committed May 2, 2020
1 parent b8a80dd commit 084366f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 51 deletions.
99 changes: 55 additions & 44 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.hank9999</groupId>
<artifactId>KeywordBlock</artifactId>
<version>1.4.5</version>
<version>1.5.0</version>
<packaging>jar</packaging>

<name>KeywordBlock</name>
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/com/github/hank9999/keywordblock/ChatListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,29 @@ public void onChat(AsyncPlayerChatEvent event) {
String username = player.getName();
String text = ChatColor.stripColor(event.getMessage());
String text_low = text.toLowerCase().replace(" ", "");
String key_text = text_low.replaceAll("&[0-9]|&[a-z]", "");
String key_text2 = key_text.replaceAll("[^a-zA-Z0-9\\\\u4E00-\\\\u9FA5]", "").replaceAll("[\\s*|\t|\r|\n]", "");
String key_text3 = key_text2.replaceAll("[^\\\\u4E00-\\\\u9FA5]", "");
String key_text4 = key_text.replaceAll("%[0-9]|%[a-z]", "");
String key_text5 = key_text4.replaceAll("[^a-zA-Z0-9\\\\u4E00-\\\\u9FA5]", "").replaceAll("[\\s*|\t|\r|\n]", "");
String key_text_a = text_low.replaceAll("&[0-9]|&[a-z]", "");
String key_text_b = text_low.replaceAll("%[0-9]|%[a-z]", "");
String key_text_c = key_text_a.replaceAll("%[0-9]|%[a-z]", "");
String key_text_replaceall = key_text_c.replaceAll("[^a-zA-Z0-9\\u4E00-\\u9FA5]", "");
String key_text_only_en = key_text_replaceall.replace("[^a-zA-Z]", "");
String key_text_only_en_123 = key_text_replaceall.replace("[^a-zA-Z0-9]", "");
String key_text_only_cn = key_text_replaceall.replace("[^\\u4E00-\\u9FA5]", "");
String key_text_a_no = text_low.replaceAll("&[0-9]|&[a-z]", "").replaceAll("[\\s*|\t|\r|\n]", "").replaceAll("\\\\[a-z]|\\\\[A-Z]|/[A-Z]|/[a-z]","");
String key_text_b_no = text_low.replaceAll("%[0-9]|%[a-z]", "").replaceAll("[\\s*|\t|\r|\n]", "").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 key_text_only_en_no = key_text_replaceall_no.replace("[^a-zA-Z]", "");
String key_text_only_en_123_no = key_text_replaceall_no.replace("[^a-zA-Z0-9]", "");
String key_text_only_cn_no = key_text_replaceall_no.replace("[^\\u4E00-\\u9FA5]", "");

String all = text_low + " " + key_text_a + " " + key_text_b + " " + key_text_c + " " + key_text_replaceall + " " + key_text_only_en + " " + key_text_only_en_123 + " " + key_text_only_cn + " " + key_text_a_no + " " + key_text_b_no + " " + key_text_c_no + " " + key_text_replaceall_no + " " + key_text_only_en_no + " " + key_text_only_en_123_no + " " + key_text_only_cn_no;

for (String keyword : KeywordBlock.plugin.getConfig().getStringList("words")) {
keyword = keyword.toLowerCase();
if (keyword.equalsIgnoreCase("")) {
continue;
}
if (text_low.contains(keyword) || key_text.contains(keyword) || key_text2.contains(keyword) || key_text3.contains(keyword) || key_text4.contains(keyword) || key_text5.contains(keyword)) {
if (all.contains(keyword)) {
event.setCancelled(true);
for (String warn_message : KeywordBlock.plugin.getConfig().getStringList("message.warn.player")) {
player.sendMessage(Lib.color_translate(warn_message.replace("%player_name%", username).replace("%player_message%", text)));
Expand Down

0 comments on commit 084366f

Please sign in to comment.