diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java index 2018f25..fa8ce1e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CustomChat.java @@ -11,12 +11,18 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.text.Text; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class CustomChat { private final MinecraftClient client; public static final CustomChat INSTANCE = new CustomChat(MinecraftClient.getInstance()); + public static final Pattern RACIST_PATTERN = Pattern.compile("nigga|nigger|i hate black", Pattern.CASE_INSENSITIVE); + public boolean enabled = true; public String format; @@ -36,6 +42,14 @@ public class CustomChat { public void chat (String message) { final ClientPlayerEntity player = client.player; + + final Matcher racistMatcher = RACIST_PATTERN.matcher(message); + if (racistMatcher.find()) { + player.sendMessage(Text.literal("racism bad")); + + return; + } + if (!enabled || !player.hasPermissionLevel(2) || !player.isCreative()) { final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); networkHandler.sendChatMessage(message);