racism bad

This commit is contained in:
Chayapak 2023-08-16 18:04:24 +07:00
parent e61407fa22
commit 5ec6250570

View file

@ -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);