Arush Lad

Make an anti-cheat plugin

Kodari AI
KodariOct 5 at 11:19 am 1
AntiCheatGuard
AntiCheatGuard is a comprehensive Minecraft anti-cheat plugin designed to detect and prevent common cheating behaviors. It monitors player movement patterns to identify speed hacks, fly hacks, and teleportation abuse. The plugin also tracks player actions to catch rapid-fire attacks, impossible jump heights, and abnormal acceleration. It features a sophisticated detection system with configurable sensitivity levels, allowing server administrators to fine-tune thresholds. When violations are detected, the plugin logs detailed evidence including player coordinates, timestamps, and violation types. It implements an automated punishment system with configurable actions such as warnings, temporary bans, or kicks. The plugin includes a whitelist system for trusted players and a false-positive prevention mechanism that requires multiple consecutive violations before taking action. It provides real-time monitoring through console commands and an in-game admin panel, plus comprehensive statistics tracking for each player's violation history.

Created KodariAntiCheat, a Paper plugin with configurable speed and hovering checks, permission-based alerts and bypass, and /ac alerts and /ac reload commands. Checks report suspicious movement without automatically punishing players.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
6 249
src/main/java/com/kodari/anticheat/KodariAntiCheat.java
package com.kodari.anticheat;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public final class KodariAntiCheat extends JavaPlugin implements CommandExecutor, TabCompleter {
    private final Set<UUID> mutedAlerts = new HashSet<>();
    private final Map<UUID, Map<String, Long>> alertCooldowns = new HashMap<>();

    @Override
    public void onEnable() {
        saveDefaultConfig();
        getServer().getPluginManager().registerEvents(new MovementCheckListener(this), this);
        getCommand("ac").setExecutor(this);
        getCommand("ac").setTabCompleter(this);
        getLogger().info("KodariAntiCheat enabled.");
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length != 1) {
            sender.sendMessage("§cUsage: /ac <alerts|reload>");
            return true;
        }

        if (args[0].equalsIgnoreCase("alerts")) {
            if (!(sender instanceof Player player)) {
                sender.sendMessage("§cOnly players can toggle personal alerts.");
                return true;
            }
            if (!player.hasPermission("kodariac.admin")) {
                player.sendMessage("§cYou don't have permission to use this command.");
                return true;
            }
            if (mutedAlerts.remove(player.getUniqueId())) {
                player.sendMessage("§aAnti-cheat alerts enabled.");
            } else {
                mutedAlerts.add(player.getUniqueId());
                player.sendMessage("§eAnti-cheat alerts muted for you.");
            }
            return true;
        }

        if (args[0].equalsIgnoreCase("reload")) {
            if (!sender.hasPermission("kodariac.admin")) {
                sender.sendMessage("§cYou don't have permission to use this command.");
                return true;
            }
            reloadConfig();
            sender.sendMessage("§aAnti-cheat configuration reloaded.");
            return true;
        }

        sender.sendMessage("§cUsage: /ac <alerts|reload>");
        return true;
    }

    @Override
    public java.util.List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
        if (args.length == 1) {
            return java.util.Arrays.asList("alerts", "reload").stream()
                    .filter(option -> option.startsWith(args[0].toLowerCase()))
                    .toList();
        }
        return java.util.Collections.emptyList();
    }

    public void flag(Player player, String check, String detail) {
        long now = System.currentTimeMillis();
        long cooldown = getConfig().getLong("alerts.cooldown-seconds", 3) * 1000L;
        Map<String, Long> playerCooldowns = alertCooldowns.computeIfAbsent(player.getUniqueId(), key -> new HashMap<>());
        long lastAlert = playerCooldowns.getOrDefault(check, 0L);
        if (now - lastAlert < cooldown) {
            return;
        }
        playerCooldowns.put(check, now);

        String message = "§c[AntiCheat] §f" + player.getName() + " §7failed §e" + check + " §8(" + detail + ")";
        getLogger().warning(player.getName() + " failed " + check + " (" + detail + ")");
        for (Player recipient : getServer().getOnlinePlayers()) {
            if (recipient.hasPermission("kodariac.alerts")
                    && !mutedAlerts.contains(recipient.getUniqueId())) {
                recipient.sendMessage(message);
            }
        }
    }

    public void clearPlayer(Player player) {
        mutedAlerts.remove(player.getUniqueId());
        alertCooldowns.remove(player.getUniqueId());
    }
}