reazxd.
๐Ÿ“Ž 1 file 3,915 chars
๐Ÿ“„
pasted-code-1795104341373.txt
txt 33 lines
โ–ถ
Act as an expert Minecraft Paper plugin developer specializing in Paper 1.21.11 (Java 21) and cracked/offline-mode servers (including Velocity + LimboAuth proxy setups). Create a complete, production-ready, zero-dependency anti-cheat and auto-ban plugin named "AntiHackAutoBan" that detects hacked clients (Wurst, Meteor, LiquidBounce, Impact, Aristois, Sigma) and automatically bans cheaters.

### Strict Technical & Version Requirements:
1. **Paper 1.21.11 & Java 21 Native:** Target `api-version: '1.21'` in `plugin.yml` and compile with Java 21 features. Ensure full compatibility with Paper 1.21.11 movement physics, attribute-based reach/speed, and modern event handling.
2. **Cracked Server & Velocity Proxy Support:**
   - Handle offline-mode UUIDs cleanly (`player.getUniqueId()` and lowercase player name tracking) so bans persist reliably on cracked servers (`ban ` and `ban-ip ` options).
   - Ensure `minecraft:brand` plugin channel listener works both on standalone Paper servers and behind a Velocity proxy (handling null/delayed brand packets gracefully).
   - Ignore movement/combat checks for unauthenticated players still in Limbo/login state or standing frozen at spawn coordinates.
3. **Zero External Dependencies:** Use ONLY standard Java 21 libraries and the official Paper 1.21.11 API (`org.bukkit.*`). Do NOT use ProtocolLib, PacketEvents, Maven, or Gradle so it compiles directly via `javac` on Android/Termux using the server's cached Paper API jar.

### Core Features to Implement:
1. **Client Brand Blocker (`PluginMessageListener`):**
   - Listen to `minecraft:brand` on player join. Decode the brand string safely (stripping any leading VarInt length byte) and match against `blocked-brands` in `config.yml`.
   - Execute immediate console ban if a hacked client brand is detected.
2. **Behavioral Anti-Cheat Checks (for clients spoofing Vanilla/Fabric brand):**
   - **Reach Check (`EntityDamageByEntityEvent`):** Account for Paper 1.21+ entity interaction range attributes and sprint latency; flag survival/adventure players hitting beyond `max-reach` (default `3.8` blocks).
   - **NoFall / Ground Spoof (`PlayerMoveEvent`):** Flag if `player.isOnGround()` is `true` while surrounded by air (`AIR`, `CAVE_AIR`, `VOID_AIR`) and falling (`from.getY() - to.getY() > 0.3`).
   - **Fly / Hover (`PlayerMoveEvent`):** Track air ticks when not flying, gliding, riding a vehicle, in Creative/Spectator, or affected by Levitation/Slow Falling; flag if air ticks exceed `25` with `to.getY() >= from.getY()`.
   - **Speed / Timer (`PlayerMoveEvent`):** Measure horizontal distance per tick while factoring in Speed potions, soul speed, ice, and knockback; flag abnormal horizontal speed bursts.
3. **Violation (VL) System & Cracked Auto-Ban:**
   - Track VL in `ConcurrentHashMap` with automatic 1 VL decay every 30 seconds to eliminate false positives from lag.
   - Live alerts for staff with `antihack.alerts` (`/antihack alerts` toggle).
   - At `max-violations` (default `10`), run configurable console ban commands (`ban %player% AutoBan: %reason%` and optional IP-ban), broadcast a custom ban message, and log to `plugins/AntiHackAutoBan/bans.log`.
   - Exempt staff with `antihack.bypass`.
4. **Commands & Permissions:**
   - `/antihack reload`, `/antihack alerts`, `/antihack check ` (shows current VL, client brand, and IP).

### Required Deliverables:
1. Complete `AntiHackAutoBan.java` (clean, un-truncated, single or modular classes in `com.antihack`).
2. Complete `plugin.yml` (`api-version: '1.21'`).
3. Complete `config.yml` with comments, cracked server IP-ban toggle, thresholds, and custom messages.
4. A single copy-paste `build.sh` script for Termux that automatically finds the Paper 1.21.11 API jar inside `libraries/` or `cache/`, compiles with `javac --release 21`, packages `AntiHackAutoBan.jar`, and moves it into `plugins/`.
Kodari AI
KodariThu at 4:08 pm 3
AntiHackAutoBan
A zero-dependency Paper 1.21.11 anti-cheat plugin for cracked servers. Detects hacked clients via minecraft:brand plugin channel and behavioral checks (reach, nofall, fly, speed). Tracks violations with decay, alerts staff, auto-bans at threshold, supports Velocity proxy and LimboAuth unauthenticated players. Includes /antihack commands, configurable thresholds, and Termux build script.
  • Add brand and conservative movement/combat checks with violation decay and staff controls.

  • Configure console bans, optional IP bans, logging, and player inspection.

  • Provide the Paper plugin descriptor, defaults, and Termux build script.

Created AntiHackAutoBan with brand blocking, behavioral checks, violation decay, staff commands, configurable bans, and build.sh.

Important limitations: Client brands can be spoofed, and behavioral checks can produce false positives. The join grace period does not verify LimboAuth authentication; proxy forwarding must be configured correctly before enabling IP bans. Test the thresholds before using automatic bans in production.

Kodari can make mistakes. Review important code before using.
Files
src
build.sh
Code
4 350
src/main/java/com/antihack/AntiHackAutoBan.java
package com.antihack;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.BoundingBox;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.time.Instant;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public final class AntiHackAutoBan extends JavaPlugin implements Listener, PluginMessageListener {
    private final ConcurrentHashMap<UUID, Integer> violations = new ConcurrentHashMap<>();
    private final Map<UUID, State> states = new HashMap<>();
    private final Set<UUID> alertsOff = new HashSet<>();
    private final Set<UUID> banning = new HashSet<>();

    private static final class State {
        String brand = "unknown";
        long exemptUntil;
        long lastMoveTick = -1;
        long lastFlagTick = -1;
        int airTicks;
        double horizontal;
    }

    @Override
    public void onEnable() {
        saveDefaultConfig();
        Bukkit.getPluginManager().registerEvents(this, this);
        getServer().getMessenger().registerIncomingPluginChannel(this, "minecraft:brand", this);
        for (Player player : Bukkit.getOnlinePlayers()) initialize(player);
        getServer().getScheduler().runTaskTimer(this, () -> violations.replaceAll((id, value) -> Math.max(0, value - 1)), 600L, 600L);
    }

    private void initialize(Player player) {
        State state = new State();
        state.exemptUntil = tick() + Math.max(0, getConfig().getLong("join-grace-ticks", 100));
        states.put(player.getUniqueId(), state);
    }

    private long tick() {
        return Bukkit.getCurrentTick();
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        initialize(event.getPlayer());
    }

    @EventHandler
    public void onQuit(PlayerQuitEvent event) {
        UUID id = event.getPlayer().getUniqueId();
        states.remove(id);
        alertsOff.remove(id);
        banning.remove(id);
    }

    @Override
    public void onPluginMessageReceived(String channel, Player player, byte[] message) {
        if (!channel.equals("minecraft:brand") || message.length == 0 || message.length > 32767) return;
        int length = 0, offset = 0, shift = 0;
        boolean complete = false;
        while (offset < message.length && shift < 35) {
            int b = message[offset++] & 255;
            length |= (b & 127) << shift;
            if ((b & 128) == 0) { complete = true; break; }
            shift += 7;
        }
        if (!complete || length < 0 || length != message.length - offset) return;
        String brand = new String(message, offset, length, StandardCharsets.UTF_8);
        State state = states.computeIfAbsent(player.getUniqueId(), id -> new State());
        state.brand = brand;
        if (player.hasPermission("antihack.bypass")) return;
        String normalized = brand.toLowerCase(Locale.ROOT);
        for (String blocked : getConfig().getStringList("blocked-brands")) {
            if (!blocked.isBlank() && normalized.contains(blocked.toLowerCase(Locale.ROOT))) {
                ban(player, "Blocked client brand: " + blocked);
                return;
            }
        }
    }

    private boolean exempt(Player player, State state) {
        return player.hasPermission("antihack.bypass") || tick() < state.exemptUntil
                || player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR
                || player.getAllowFlight() || player.isFlying() || player.isGliding() || player.isInsideVehicle()
                || player.isSwimming() || player.isRiptiding() || player.isDead();
    }

    private void grace(Player player, long ticks) {
        State state = states.get(player.getUniqueId());
        if (state != null) {
            state.exemptUntil = Math.max(state.exemptUntil, tick() + ticks);
            state.airTicks = 0;
            state.horizontal = 0;
        }
    }

    @EventHandler(ignoreCancelled = true)
    public void onTeleport(PlayerTeleportEvent event) { grace(event.getPlayer(), 60); }

    @EventHandler(ignoreCancelled = true)
    public void onVelocity(PlayerVelocityEvent event) { grace(event.getPlayer(), 60); }

    @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
    public void onDamage(EntityDamageEvent event) {
        if (event.getEntity() instanceof Player player) grace(player, 40);
    }

    @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
    public void onMove(PlayerMoveEvent event) {
        Player player = event.getPlayer();
        Location from = event.getFrom(), to = event.getTo();
        if (to == null || from.getWorld() != to.getWorld()) return;
        State state = states.computeIfAbsent(player.getUniqueId(), id -> new State());
        if (exempt(player, state)) { state.airTicks = 0; state.horizontal = 0; return; }
        double dx = to.getX() - from.getX(), dz = to.getZ() - from.getZ(), dy = to.getY() - from.getY();
        if (dx == 0 && dy == 0 && dz == 0) return;
        if (Math.abs(dy) > 2 || Math.hypot(dx, dz) > 3) { grace(player, 60); return; }
        long now = tick();
        boolean newTick = state.lastMoveTick != now;
        if (newTick) { state.horizontal = 0; state.lastMoveTick = now; }
        state.horizontal += Math.hypot(dx, dz);
        if (nearUncertainBlocks(player)) { state.airTicks = 0; return; }
        boolean supported = hasSupport(player);
        if (newTick) state.airTicks = supported ? 0 : state.airTicks + 1;
        if (!supported && player.isOnGround() && dy < -0.3) flag(player, state, "Ground spoof");
        if (!supported && state.airTicks > getConfig().getInt("hover-air-ticks", 25) && dy >= 0
                && !hasEffect(player, "LEVITATION") && !hasEffect(player, "SLOW_FALLING")) flag(player, state, "Hover");
        double limit = getConfig().getDouble("max-horizontal-per-tick", 0.8);
        PotionEffect speed = effect(player, "SPEED");
        if (speed != null) limit *= 1.0 + 0.2 * (speed.getAmplifier() + 1);
        if (state.horizontal > limit) flag(player, state, "Speed");
    }

    private PotionEffect effect(Player player, String name) {
        PotionEffectType type = PotionEffectType.getByName(name);
        return type == null ? null : player.getPotionEffect(type);
    }

    private boolean hasEffect(Player player, String name) { return effect(player, name) != null; }

    private boolean hasSupport(Player player) {
        BoundingBox box = player.getBoundingBox();
        int y = (int) Math.floor(box.getMinY() - 0.12);
        for (int x = (int) Math.floor(box.getMinX()); x <= (int) Math.floor(box.getMaxX()); x++) {
            for (int z = (int) Math.floor(box.getMinZ()); z <= (int) Math.floor(box.getMaxZ()); z++) {
                if (!player.getWorld().getBlockAt(x, y, z).isPassable()) return true;
            }
        }
        return false;
    }

    private boolean nearUncertainBlocks(Player player) {
        Location loc = player.getLocation();
        int bx = loc.getBlockX(), by = loc.getBlockY(), bz = loc.getBlockZ();
        for (int x = bx - 1; x <= bx + 1; x++) for (int y = by - 1; y <= by + 2; y++) for (int z = bz - 1; z <= bz + 1; z++) {
            Block block = player.getWorld().getBlockAt(x, y, z);
            String type = block.getType().name();
            if (block.isLiquid() || type.contains("ICE") || type.contains("SLIME") || type.contains("HONEY")
                    || type.contains("SOUL_SAND") || type.contains("SOUL_SOIL") || type.contains("WEB")
                    || type.contains("LADDER") || type.contains("VINE") || type.contains("SCAFFOLDING")
                    || type.contains("BUBBLE_COLUMN") || type.contains("POWDER_SNOW") || type.contains("PISTON")) return true;
        }
        return false;
    }