From 7e30dd7b93954442789fd7195df5c75f9699264c Mon Sep 17 00:00:00 2001 From: ImproperIssues Date: Sat, 27 May 2023 14:28:07 -0700 Subject: [PATCH] antiswear leet string checks --- .../ogredupealias/plugin/ChatConstraints.java | 6 ++++-- .../ogre/ogredupealias/utils/StringUtils.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/fun/ogre/ogredupealias/plugin/ChatConstraints.java b/src/main/java/fun/ogre/ogredupealias/plugin/ChatConstraints.java index 02a6275..7e30a94 100644 --- a/src/main/java/fun/ogre/ogredupealias/plugin/ChatConstraints.java +++ b/src/main/java/fun/ogre/ogredupealias/plugin/ChatConstraints.java @@ -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))); diff --git a/src/main/java/fun/ogre/ogredupealias/utils/StringUtils.java b/src/main/java/fun/ogre/ogredupealias/utils/StringUtils.java index 354dc12..c198ef3 100644 --- a/src/main/java/fun/ogre/ogredupealias/utils/StringUtils.java +++ b/src/main/java/fun/ogre/ogredupealias/utils/StringUtils.java @@ -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"); + } }