antiswear leet string checks

This commit is contained in:
ImproperIssues
2023-05-27 14:28:07 -07:00
parent 92a1170b5f
commit 7e30dd7b93
2 changed files with 20 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ package fun.ogre.ogredupealias.plugin;
import fun.ogre.ogredupealias.data.Config;
import fun.ogre.ogredupealias.utils.ArrayUtils;
import fun.ogre.ogredupealias.utils.ServerUtils;
import fun.ogre.ogredupealias.utils.StringUtils;
import fun.ogre.ogredupealias.utils.Text;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
@@ -88,7 +89,8 @@ public class ChatConstraints {
if (player.hasPermission("oda.chat.bypass.swear")) return true;
// 1
String msg = message.replaceAll("[^A-Za-z0-9]", "").trim();
String msg = StringUtils.fromLeetString(message);
msg = msg.replaceAll("[^A-Za-z0-9]", "").trim();
// 2
msg = msg.toLowerCase();
// 3
@@ -110,7 +112,7 @@ public class ChatConstraints {
if (!flags.isEmpty()) {
player.sendMessage(Text.ofAll("&cPlease do not swear in chat! Attempting to bypass this filter would result in a mute!"));
// 7
String hover = Text.color("&bMessage: &f" + msg + "\n&bFlags: &f" + ArrayUtils.list2string(flags) + "\n&7&o(click to copy)");
String hover = Text.color("&bOriginal: &f" + this.message + "\n&bMessage: &f" + msg + "\n&bFlags: &f" + ArrayUtils.list2string(flags) + "\n&7&o(click to copy)");
TextComponent text = new TextComponent();
text.setText(Text.ofAll("&f&n" + player.getName() + "&e has triggered the anti-swear!"));
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hover)));

View File

@@ -15,4 +15,20 @@ public final class StringUtils {
for (String str : sArray) sb.append(capitalize(str)).append(" ");
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");
}
}