Build the requested Minecraft server plugin in this new project. Requirement: if a player places TNT so that a face-connected cluster of TNT blocks reaches 20 or more blocks, kick that player and delete the TNT in that connected cluster immediately, without drops or explosions. Detect clusters using six face-adjacent neighbors (up/down/north/south/east/west), not diagonal-only connections. Count the newly placed TNT as part of the cluster. Use a Bukkit/Paper block placement listener; cancel the triggering placement as needed, and make sure all TNT in the offending connected cluster is removed. Use a configurable threshold in the plugin config with default 20, and provide a clear kick message. Add the needed plugin metadata and default config consistent with this project. Do not add tests. Implement the complete feature only.

Kodari AI
KodariOct 30 at 11:37 pm 1
TNTClusterKicker
A Minecraft Bukkit/Paper plugin that detects when a player places TNT forming a face-connected cluster of 20 or more blocks. On detection, the plugin kicks the offending player with a configurable message and immediately removes all TNT in the connected cluster without drops or explosions. Uses six-directional adjacency (up/down/north/south/east/west) for cluster detection via flood-fill algorithm. Includes configurable threshold (default 20) in config.yml and full plugin metadata in plugin.yml.
  1. Create the Paper plugin entry point and six-direction TNT-cluster detection.

  2. Add the default threshold/kick message, plugin metadata, and build configuration.

Implemented TNTClusterGuard. It counts TNT connected through the six face-adjacent blocks; at the configurable threshold (default 20), it cancels the placement, removes the entire connected cluster without drops or physics, and kicks the placer with the configured message.

Extend the existing TNTClusterGuard Paper plugin to alert the new Python Discord bot when a player triggers a TNT cluster violation. Current entry point is src/main/java/com/kodari/tntclusterguard/TNTClusterGuardPlugin.java; it detects and removes the offending face-connected TNT cluster and kicks the player at configured tnt-cluster-threshold (default 20). Add an optional configurable HTTP alert section in src/main/resources/config.yml, for example discord-alert.enabled (default false), discord-alert.endpoint (placeholder https://<bot-project-suffix>.kodaribots.com/alert), and discord-alert.shared-secret (empty/default placeholder). When a violation occurs, submit POST JSON to the configured endpoint with fields player, world, x, y, z, count, threshold and Authorization: Bearer <shared-secret>. Capture values on the server thread, perform network I/O asynchronously (never block the Bukkit main thread), set a short timeout, and log failures without exposing the secret or disrupting kick/removal behavior. Use Java APIs compatible with the existing Java 21 build. Keep the existing removal/kick behavior and threshold behavior intact. Update plugin config/documentation if any exists to explain filling the endpoint and matching the shared secret with the bot. Do not add tests. Implement the complete feature only.

Kodari AI
KodariOct 30 at 11:52 pm 1
  1. Inspect the current plugin, config, and build setup.

  2. Add optional async HTTP POST alerts and document endpoint/secret configuration without changing violation handling.

Added optional Discord bot alerts. When enabled, a violation sends an asynchronous JSON POST with the player, world, coordinates, cluster count, and threshold, using a Bearer shared secret and short timeouts. Invalid configuration and request failures are logged without exposing the secret or interrupting the existing removal and kick behavior.

Configure discord-alert.endpoint and discord-alert.shared-secret in src/main/resources/config.yml to match the bot; alerts are disabled by default.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 244
src/main/java/com/kodari/tntclusterguard/TNTClusterGuardPlugin.java
package com.kodari.tntclusterguard;

import com.cryptomorin.xseries.XMaterial;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class TNTClusterGuardPlugin extends JavaPlugin implements Listener {
    private final HttpClient alertHttpClient = HttpClient.newBuilder()
        .connectTimeout(Duration.ofSeconds(3))
        .build();

    private static final BlockFace[] ADJACENT_FACES = {
        BlockFace.UP,
        BlockFace.DOWN,
        BlockFace.NORTH,
        BlockFace.SOUTH,
        BlockFace.EAST,
        BlockFace.WEST
    };

    private Material tntMaterial;
    private Material airMaterial;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        tntMaterial = XMaterial.matchXMaterial("TNT").map(XMaterial::parseMaterial).orElse(null);
        airMaterial = XMaterial.matchXMaterial("AIR").map(XMaterial::parseMaterial).orElse(null);
        if (tntMaterial == null || airMaterial == null) {
            throw new IllegalStateException("TNT or AIR is unavailable on this server.");
        }
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onTntPlace(BlockPlaceEvent event) {
        Block placedBlock = event.getBlockPlaced();
        if (placedBlock.getType() != tntMaterial) {
            return;
        }

        List<Block> cluster = collectConnectedTnt(placedBlock);
        int threshold = Math.max(1, getConfig().getInt("tnt-cluster-threshold", 20));
        if (cluster.size() < threshold) {
            return;
        }

        event.setCancelled(true);
        for (Block block : cluster) {
            if (block.getType() == tntMaterial) {
                block.setType(airMaterial, false);
            }
        }

        Player player = event.getPlayer();
        sendViolationAlert(
            player.getName(),
            placedBlock.getWorld().getName(),
            placedBlock.getX(),
            placedBlock.getY(),
            placedBlock.getZ(),
            cluster.size(),
            threshold
        );
        String message = getConfig().getString(
            "kick-message",
            "&cYou were kicked for placing too large a connected TNT cluster."
        );
        player.kickPlayer(ChatColor.translateAlternateColorCodes('&', message));

        Bukkit.getScheduler().runTask(this, () -> {
            for (Block block : cluster) {
                if (block.getType() == tntMaterial) {
                    block.setType(airMaterial, false);
                }
            }
        });
    }

    private void sendViolationAlert(String player, String world, int x, int y, int z, int count, int threshold) {
        if (!getConfig().getBoolean("discord-alert.enabled", false)) {
            return;
        }

        String endpoint = getConfig().getString("discord-alert.endpoint", "");
        String sharedSecret = getConfig().getString("discord-alert.shared-secret", "");
        if (endpoint == null || endpoint.isBlank()) {
            getLogger().warning("Discord alerts are enabled but discord-alert.endpoint is empty; skipping alert.");
            return;
        }
        if (sharedSecret == null || sharedSecret.isBlank()) {
            getLogger().warning("Discord alerts are enabled but discord-alert.shared-secret is empty; skipping alert.");
            return;
        }

        String payload = "{\"player\":\"" + escapeJson(player)
            + "\",\"world\":\"" + escapeJson(world)
            + "\",\"x\":" + x
            + ",\"y\":" + y
            + ",\"z\":" + z
            + ",\"count\":" + count
            + ",\"threshold\":" + threshold + "}";

        try {
            HttpRequest request = HttpRequest.newBuilder(URI.create(endpoint))
                .timeout(Duration.ofSeconds(5))
                .header("Authorization", "Bearer " + sharedSecret)
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(payload, StandardCharsets.UTF_8))
                .build();
            alertHttpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding())
                .whenComplete((response, failure) -> {
                    if (failure != null) {
                        getLogger().warning("Failed to send Discord alert: " + failure.getClass().getSimpleName());
                    } else if (response.statusCode() < 200 || response.statusCode() >= 300) {
                        getLogger().warning("Discord alert endpoint returned HTTP " + response.statusCode() + ".");
                    }
                });
        } catch (IllegalArgumentException exception) {
            getLogger().warning("Invalid Discord alert endpoint configuration; unable to send alert.");
        }
    }

    private String escapeJson(String value) {
        StringBuilder escaped = new StringBuilder(value.length());
        for (int index = 0; index < value.length(); index++) {
            char character = value.charAt(index);
            switch (character) {
                case '"' -> escaped.append("\\\"");
                case '\\' -> escaped.append("\\\\");
                case '\b' -> escaped.append("\\b");
                case '\f' -> escaped.append("\\f");
                case '\n' -> escaped.append("\\n");
                case '\r' -> escaped.append("\\r");
                case '\t' -> escaped.append("\\t");
                default -> {
                    if (character < 0x20) {
                        escaped.append("\\u");
                        String hex = Integer.toHexString(character);
                        escaped.append("0".repeat(4 - hex.length())).append(hex);
                    } else {
                        escaped.append(character);
                    }
                }
            }
        }
        return escaped.toString();
    }

    private List<Block> collectConnectedTnt(Block startingBlock) {
        List<Block> cluster = new ArrayList<>();
        Queue<Block> pending = new ArrayDeque<>();
        Set<BlockPosition> visited = new HashSet<>();

        pending.add(startingBlock);
        visited.add(positionOf(startingBlock));

        while (!pending.isEmpty()) {
            Block current = pending.remove();
            if (current.getType() != tntMaterial) {
                continue;
            }
            cluster.add(current);

            for (BlockFace face : ADJACENT_FACES) {
                Block neighbor = current.getRelative(face);
                if (neighbor.getType() != tntMaterial) {
                    continue;
                }
                if (visited.add(positionOf(neighbor))) {
                    pending.add(neighbor);
                }
            }
        }

        return cluster;
    }

    private BlockPosition positionOf(Block block) {