lefiraaya

Remove priority system and also remove kick system when player spamming in chat and add disconnect system when players spamming in chat

Kodari AI
KodariJul 27 at 4:43 pm 14

Plan:

  1. Priority system: merge the split LOWEST/MONITOR handlers in ChatListener into a single default-priority handler; drop the EventPriority usage and the config comment documenting it.

  2. Kick system: remove the 5: "kick {player}" violation threshold from config.yml.

  3. Disconnect system: add a configurable spam-disconnect section — after N chat-spam (repeat message) violations the player is disconnected directly.

All three changes landed:

  1. Priority system removed (ChatListener.java) — the split LOWEST/MONITOR handlers are merged into a single default-priority onChat handler; EventPriority import and the priority comment in config.yml are gone.

  2. Kick system removed (config.yml) — deleted the 5: "kick {player} Too many violations" violation threshold, so spam no longer triggers a kick via violation thresholds.

  3. Disconnect system added — new spam-disconnect config section:

    YAML
    spam-disconnect:
      enabled: true
      violations: 3
      message: "&cDisconnected for spamming chat!"
    

    When a player’s spam violations (repeat messages) reach the configured count, they’re disconnected directly via player.kickPlayer(...) (scheduled on the main thread since chat is async). Count, message, and on/off are all configurable.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
16 1,413
src/main/java/com/pmcchat/PMCChatManager.java
package com.pmcchat;

import com.pmcchat.command.ReloadCommand;
import com.pmcchat.listener.AnvilListener;
import com.pmcchat.listener.BookListener;
import com.pmcchat.listener.ChatListener;
import com.pmcchat.listener.CommandListener;
import com.pmcchat.listener.SignListener;
import com.pmcchat.manager.AlertManager;
import com.pmcchat.manager.ConfigManager;
import com.pmcchat.manager.CooldownManager;
import com.pmcchat.manager.FilterManager;
import com.pmcchat.manager.ViolationManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class PMCChatManager extends JavaPlugin {
    
    private ConfigManager configManager;
    private FilterManager filterManager;
    private ViolationManager violationManager;
    private CooldownManager cooldownManager;
    private AlertManager alertManager;
    
    @Override
    public void onEnable() {
        this.saveDefaultConfig();
        
        this.configManager = new ConfigManager(this);
        this.filterManager = new FilterManager(this);
        this.violationManager = new ViolationManager(this);
        this.cooldownManager = new CooldownManager(this);
        this.alertManager = new AlertManager(this);
        
        this.configManager.loadConfig();
        
        Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
        Bukkit.getPluginManager().registerEvents(new CommandListener(this), this);
        Bukkit.getPluginManager().registerEvents(new SignListener(this), this);
        Bukkit.getPluginManager().registerEvents(new BookListener(this), this);
        Bukkit.getPluginManager().registerEvents(new AnvilListener(this), this);
        
        this.getCommand("pmcchat").setExecutor(new ReloadCommand(this));
        
        this.getLogger().info("PMC-CHAT-MANAGER enabled successfully!");
    }
    
    @Override
    public void onDisable() {
        this.cooldownManager.clearAll();
        this.violationManager.clearAll();
        this.getLogger().info("PMC-CHAT-MANAGER disabled successfully!");
    }
}