apex.ly
๐Ÿ“Ž 1 file 1,741 chars
๐Ÿ“„
pasted-code-1790340734287.txt
txt 39 lines
โ–ถ
Plugin Name: PositiveChat & AutoMute
Minecraft Version: 1.21.1 (Paper / Spigot / Purpur)

Objective:
Create a Minecraft chat management plugin that replaces toxic words/phrases with positive language and automatically mutes players for 10 minutes if they repeatedly attempt to post toxic words.

Key Features & Logic:

1. Chat Word Replacement:
- Intercept player chat before it is broadcasted.
- Replace toxicity and toxic slang with clean/wholesome words.
- Examples:
  * "ez" / "ezz" -> "gg"
  * "fuck" -> "love"
  * "fucking" -> "loving"
  * "bc" / "bhenchod" -> "pyare bhai"
  * "mc" / "madarchod" -> "dost"
  * "chutiya" -> "accha banda"
  * "bhosdike" -> "bhai"
  * "gand" -> "dil"
- Word matching should be case-insensitive and handle word variations.

2. Violation Counter & Auto-Mute:
- Track each player's specific toxic word violations using their UUID in-memory.
- If a player uses the exact same toxic word 3 times:
  - Cancel the chat message.
  - Temporarily mute the player for 10 minutes (600,000 milliseconds).
  - Broadcast a public server message: "[PlayerName] has been muted for 10 minutes for using bad language."
  - Send a private alert to the player notifying them of the 10-minute mute.
  - Reset their violation count for that word.

3. Mute Enforcement:
- While muted, block all chat attempts from the player.
- Display a live countdown message when they try to chat (e.g., "You are muted for abusing! Time remaining: 9m 45s").
- Automatically unmute the player once the 10 minutes elapse without needing a server restart.

4. Performance & Compatibility:
- Ensure chat handling runs asynchronously where appropriate to prevent main thread lag.
- Support standard Paper/Spigot 1.21.1 API (AsyncPlayerChatEvent).
Kodari AI
KodariSep 25 at 12:54 pm 1
PositiveChatAutoMute
PositiveChatAutoMute is a Minecraft chat management plugin that intercepts player messages before broadcast, replacing toxic words with positive alternatives. It tracks repeated violations per player using UUIDs, automatically muting offenders for 10 minutes after three identical infractions. While muted, chat attempts are blocked with a live countdown display. The plugin broadcasts public mute announcements, sends private alerts, and automatically unmutes players after the duration expires. It handles case-insensitive word matching, supports asynchronous chat processing for performance, and is compatible with Paper/Spigot 1.21.1.
  1. Create the Gradle project and plugin metadata for Paper/Spigot 1.21.1.

  2. Add async chat filtering, per-word violation tracking, and timed mute enforcement.

Created the PositiveChat & AutoMute plugin for Paper/Spigot 1.21.1.

It replaces the requested toxic terms and repeated-letter variants, tracks violations per player and matched word, and cancels chat and applies a 10-minute mute on the third occurrence. Muted players receive a remaining-time message when they try to chat; notices and broadcasts are scheduled on the server thread.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
3 191
src/main/java/com/example/positivechat/PositiveChatPlugin.java
package com.example.positivechat;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class PositiveChatPlugin extends JavaPlugin implements Listener {
    private static final long MUTE_DURATION_MILLIS = 600_000L;
    private static final List<WordRule> WORD_RULES = List.of(
            new WordRule(Pattern.compile("(?<![\\p{L}\\p{N}_])e+z+(?![\\p{L}\\p{N}_])", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE), "gg", false),
            new WordRule(Pattern.compile("(?<![\\p{L}\\p{N}_])f+u+c+k+(?:i+n+g+)?(?![\\p{L}\\p{N}_])", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE), "love", true),
            new WordRule(Pattern.compile("(?<![\\p{L}\\p{N}_])(?:b+c+|b+h+e+n+c+h+o+d+)(?![\\p{L}\\p{N}_])", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE), "pyare bhai", false),
            new WordRule(Pattern.compile("(?<![\\p{L}\\p{N}_])(?:m+c+|m+a+d+a+r+c+h+o+d+)(?![\\p{L}\\p{N}_])", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE), "dost", false),
            new WordRule(Pattern.compile("(?<![\\p{L}\\p{N}_])ch+u+t+i+y+a+(?![\\p{L}\\p{N}_])", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE), "accha banda", false),
            new WordRule(Pattern.compile("(?<![\\p{L}\\p{N}_])bh+o+s+d+i+k+e+(?![\\p{L}\\p{N}_])", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE), "bhai", false),
            new WordRule(Pattern.compile("(?<![\\p{L}\\p{N}_])g+a+n+d+(?![\\p{L}\\p{N}_])", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE), "dil", false)
    );

    private final Map<UUID, PlayerState> playerStates = new ConcurrentHashMap<>();

    @Override
    public void onEnable() {
        Bukkit.getPluginManager().registerEvents(this, this);
    }

    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
    public void onPlayerChat(AsyncPlayerChatEvent event) {
        Player player = event.getPlayer();
        PlayerState state = playerStates.computeIfAbsent(player.getUniqueId(), ignored -> new PlayerState());
        long now = System.currentTimeMillis();
        long remaining = state.remainingMuteMillis(now);
        if (remaining > 0L) {
            event.setCancelled(true);
            sendMuteCountdown(player, remaining);
            return;
        }

        String message = event.getMessage();
        for (WordRule rule : WORD_RULES) {
            Matcher matcher = rule.pattern().matcher(message);
            StringBuffer replaced = new StringBuffer();
            while (matcher.find()) {
                int result = state.recordViolation(matcher.group().toLowerCase(Locale.ROOT), now);
                if (result == PlayerState.MUTED) {
                    event.setCancelled(true);
                    sendMuteCountdown(player, state.remainingMuteMillis(System.currentTimeMillis()));
                    return;
                }
                if (result == PlayerState.NEW_MUTE) {
                    event.setCancelled(true);
                    scheduleMuteNotice(player);
                    return;
                }

                String replacement = rule.fuckingVariant() && matcher.group().toLowerCase(Locale.ROOT).contains("i")
                        ? "loving"
                        : rule.replacement();
                matcher.appendReplacement(replaced, Matcher.quoteReplacement(replacement));
            }
            matcher.appendTail(replaced);
            message = replaced.toString();
        }
        event.setMessage(message);
    }

    private void sendMuteCountdown(Player player, long remainingMillis) {
        long safeRemaining = Math.max(0L, remainingMillis);
        long totalSeconds = (safeRemaining + 999L) / 1_000L;
        long minutes = totalSeconds / 60L;
        long seconds = totalSeconds % 60L;
        String message = "You are muted for abusing! Time remaining: " + minutes + "m " + seconds + "s";
        Bukkit.getScheduler().runTask(this, () -> {
            if (player.isOnline()) {
                player.sendMessage(message);
            }
        });
    }

    private void scheduleMuteNotice(Player player) {
        Bukkit.getScheduler().runTask(this, () -> {
            Bukkit.broadcastMessage(player.getName() + " has been muted for 10 minutes for using bad language.");
            if (player.isOnline()) {
                player.sendMessage("You have been muted for 10 minutes for using bad language.");
            }
        });
    }

    private static final class WordRule {
        private final Pattern pattern;
        private final String replacement;
        private final boolean fuckingVariant;

        private WordRule(Pattern pattern, String replacement, boolean fuckingVariant) {
            this.pattern = pattern;
            this.replacement = replacement;
            this.fuckingVariant = fuckingVariant;
        }

        private Pattern pattern() {
            return pattern;
        }

        private String replacement() {
            return replacement;
        }

        private boolean fuckingVariant() {
            return fuckingVariant;
        }
    }

    private static final class PlayerState {
        private static final int MUTED = -1;
        private static final int BELOW_THRESHOLD = 0;
        private static final int NEW_MUTE = 1;

        private final Map<String, Integer> violations = new ConcurrentHashMap<>();
        private long muteUntilMillis;

        private synchronized long remainingMuteMillis(long now) {
            if (muteUntilMillis <= now) {
                muteUntilMillis = 0L;
                return 0L;
            }
            return muteUntilMillis - now;
        }

        private synchronized int recordViolation(String word, long now) {
            if (muteUntilMillis > now) {
                return MUTED;
            }
            if (muteUntilMillis != 0L) {
                muteUntilMillis = 0L;
            }

            int count = violations.getOrDefault(word, 0) + 1;
            if (count >= 3) {
                violations.remove(word);
                muteUntilMillis = now + MUTE_DURATION_MILLIS;
                return NEW_MUTE;
            }
            violations.put(word, count);
            return BELOW_THRESHOLD;
        }
    }
}