leet dictionary config
This commit is contained in:
@@ -6,10 +6,7 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static fun.ogre.ogredupealias.OgreDupeAlias.instance;
|
import static fun.ogre.ogredupealias.OgreDupeAlias.instance;
|
||||||
import static fun.ogre.ogredupealias.OgreDupeAlias.log;
|
import static fun.ogre.ogredupealias.OgreDupeAlias.log;
|
||||||
@@ -61,6 +58,16 @@ public abstract class Config {
|
|||||||
public static List<String> blacklist() {
|
public static List<String> blacklist() {
|
||||||
return get().getStringList(path + "blacklist");
|
return get().getStringList(path + "blacklist");
|
||||||
}
|
}
|
||||||
|
public static Map<String, String> leetPatterns() {
|
||||||
|
Map<String, String> dictionary = new HashMap<>();
|
||||||
|
ConfigurationSection section = get().getConfigurationSection(path + "leet-patterns");
|
||||||
|
|
||||||
|
if (section == null) return dictionary;
|
||||||
|
for (String key : section.getKeys(false)) {
|
||||||
|
dictionary.put(key, section.getString(key));
|
||||||
|
}
|
||||||
|
return dictionary;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class AntiSpam {
|
public static class AntiSpam {
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ public class ChatEventListener implements Listener {
|
|||||||
try {
|
try {
|
||||||
this.handleChatConstraints(e);
|
this.handleChatConstraints(e);
|
||||||
}
|
}
|
||||||
catch (Exception ignore) {}
|
catch (Exception ignore) {
|
||||||
|
ignore.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleChatConstraints(AsyncPlayerChatEvent e) {
|
private void handleChatConstraints(AsyncPlayerChatEvent e) {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package fun.ogre.ogredupealias.plugin;
|
|||||||
import fun.ogre.ogredupealias.data.Config;
|
import fun.ogre.ogredupealias.data.Config;
|
||||||
import fun.ogre.ogredupealias.utils.ArrayUtils;
|
import fun.ogre.ogredupealias.utils.ArrayUtils;
|
||||||
import fun.ogre.ogredupealias.utils.ServerUtils;
|
import fun.ogre.ogredupealias.utils.ServerUtils;
|
||||||
import fun.ogre.ogredupealias.utils.StringUtils;
|
|
||||||
import fun.ogre.ogredupealias.utils.Text;
|
import fun.ogre.ogredupealias.utils.Text;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
@@ -11,6 +10,7 @@ import net.md_5.bungee.api.chat.TextComponent;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
|
||||||
public class ChatConstraints {
|
public class ChatConstraints {
|
||||||
|
|
||||||
@@ -89,20 +89,21 @@ public class ChatConstraints {
|
|||||||
if (player.hasPermission("oda.chat.bypass.swear")) return true;
|
if (player.hasPermission("oda.chat.bypass.swear")) return true;
|
||||||
|
|
||||||
// 1
|
// 1
|
||||||
String msg = StringUtils.fromLeetString(message);
|
String msg = fromLeetString(message);
|
||||||
msg = msg.replaceAll("[^A-Za-z0-9]", "").trim();
|
msg = msg.replaceAll("[^A-Za-z0-9]", "").trim();
|
||||||
// 2
|
// 2
|
||||||
msg = msg.toLowerCase();
|
msg = msg.toLowerCase();
|
||||||
// 3
|
// 3
|
||||||
for (String whitelisted : Config.Chat.AntiSwear.whitelist()) {
|
for (String whitelisted : Config.Chat.AntiSwear.whitelist()) {
|
||||||
msg = msg.replaceAll(whitelisted.toLowerCase(), "").trim();
|
String key = whitelisted.toLowerCase().replaceAll(" ", "");
|
||||||
|
msg = msg.replaceAll(key, "").trim();
|
||||||
}
|
}
|
||||||
// 4
|
// 4
|
||||||
msg = msg.replaceAll("[. _-]", "");
|
msg = msg.replaceAll("[. _-]", "");
|
||||||
// 5
|
// 5
|
||||||
List<String> flags = new ArrayList<>();
|
List<String> flags = new ArrayList<>();
|
||||||
for (String blacklisted : Config.Chat.AntiSwear.blacklist()) {
|
for (String blacklisted : Config.Chat.AntiSwear.blacklist()) {
|
||||||
String key = blacklisted.toLowerCase();
|
String key = blacklisted.toLowerCase().replaceAll(" ", "");
|
||||||
if (msg.contains(key)) {
|
if (msg.contains(key)) {
|
||||||
flags.add(blacklisted);
|
flags.add(blacklisted);
|
||||||
msg = msg.replaceAll(key, Text.color("&e" + key + "&f"));
|
msg = msg.replaceAll(key, Text.color("&e" + key + "&f"));
|
||||||
@@ -159,4 +160,26 @@ public class ChatConstraints {
|
|||||||
public static boolean isChatMuted() {
|
public static boolean isChatMuted() {
|
||||||
return isChatMuted;
|
return isChatMuted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String fromLeetString(String s) {
|
||||||
|
Map<String, String> dictionary = Config.Chat.AntiSwear.leetPatterns();
|
||||||
|
String msg = s;
|
||||||
|
|
||||||
|
for (String key : dictionary.keySet()) {
|
||||||
|
if (!s.contains(key)) continue;
|
||||||
|
try {
|
||||||
|
if (key.equals("$")) {
|
||||||
|
msg = msg.replaceAll("\\$", "s");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg = msg.replaceAll(key, dictionary.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (PatternSyntaxException ex) {
|
||||||
|
String regex = "[" + key + "]";
|
||||||
|
msg = msg.replaceAll(regex, dictionary.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,20 +15,4 @@ public final class StringUtils {
|
|||||||
for (String str : sArray) sb.append(capitalize(str)).append(" ");
|
for (String str : sArray) sb.append(capitalize(str)).append(" ");
|
||||||
return sb.toString().trim();
|
return sb.toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String fromLeetString(String s) {
|
|
||||||
return s.replaceAll("0", "o")
|
|
||||||
.replaceAll("1", "i")
|
|
||||||
.replaceAll("3", "e")
|
|
||||||
.replaceAll("4", "a")
|
|
||||||
.replaceAll("5", "s")
|
|
||||||
.replaceAll("7", "l")
|
|
||||||
.replaceAll("\\$", "s")
|
|
||||||
.replaceAll("!", "i")
|
|
||||||
.replaceAll("\\+", "t")
|
|
||||||
.replaceAll("#", "h")
|
|
||||||
.replaceAll("@", "a")
|
|
||||||
.replaceAll("<", "c")
|
|
||||||
.replaceAll("v", "u");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,22 @@ chat:
|
|||||||
- glass
|
- glass
|
||||||
blacklist:
|
blacklist:
|
||||||
- ass
|
- ass
|
||||||
|
leet-patterns:
|
||||||
|
0: o
|
||||||
|
1: i
|
||||||
|
3: e
|
||||||
|
4: a
|
||||||
|
5: s
|
||||||
|
6: g
|
||||||
|
7: l
|
||||||
|
"$": s
|
||||||
|
"!": i
|
||||||
|
"+": t
|
||||||
|
"#": h
|
||||||
|
"@": a
|
||||||
|
"<": c
|
||||||
|
V: u
|
||||||
|
v: u
|
||||||
anti-spam:
|
anti-spam:
|
||||||
enabled: true
|
enabled: true
|
||||||
cooldown: 5
|
cooldown: 5
|
||||||
|
|||||||
Reference in New Issue
Block a user