Tech Pat

Create a Paper plugin named AntiDupeDetector.

Package: me.patplays2.antidupe

Commands:

  • /antidupe reload

Detect and log:

  • /openinv check <player>
  • /openinv
  • /inv
  • /invsee
  • /offlineinv

Features:

  • Staff alerts (permission antidupe.alerts)
  • Console logging
  • File logging
  • Discord webhook support
  • Configurable messages in config.yml

Target:

Paper 26.1.2

Kodari AI
KodariSep 2 at 3:41 am 1
AntiDupeDetector
A Paper plugin that detects and logs inventory-related commands to prevent item duplication exploits. Monitors /openinv, /inv, /invsee, and /offlineinv usage, providing staff alerts via permission-based chat notifications, console logging, file logging, and Discord webhook integration. Features a reloadable configuration system with customizable messages in config.yml, allowing server administrators to tailor alert formats and webhook settings. Includes a /antidupe reload command for seamless configuration updates without server restarts, making it an essential security tool for server moderation teams.
  1. Create the Gradle project and Paper plugin metadata for Paper 26.1.2.

  2. Implement /antidupe reload with permission-protected configurable messages.

  3. Add detection for the requested inventory commands with staff alerts.

  4. Add configurable console, file, and Discord webhook logging.

Created the AntiDupeDetector Paper plugin project with:

  • /antidupe reload and permission handling

  • Detection for /openinv, /openinv check <player>, /inv, /invsee, and /offlineinv

  • Staff alerts via antidupe.alerts

  • Configurable console and file logging

  • Optional Discord webhook notifications

  • Configurable messages in config.yml

  • Paper 26.1.2 Gradle configuration

  • Java package me.patplays2.antidupe

Tech Pat

Alr i love it but could we make the dc webhook cleaner also wanna add auto kick when they do it (if enabled in config)

Kodari AI
KodariSep 2 at 4:05 am 1
  1. Clean up Discord webhook formatting with a structured, readable embed-style payload.

  2. Add configurable automatic kicking for players who trigger a detected command.

The detector currently passes only the sender name into logging, so I’m wiring the actual Player through the detection path to support a synchronous kick. The webhook will use a Discord embed with separate player, command, target, and type fields instead of a dense text block.

Implemented both updates:

  • Cleaner Discord webhook

    • Uses a structured Discord embed.

    • Separate fields for player, command, target, and detection type.

    • Configurable title, description, color, and footer.

    • Includes a timestamp.

  • Automatic kicking

    • Added auto-kick.enabled to config.yml.

    • When enabled, players are kicked immediately after triggering a detected command.

    • Kick message is configurable through messages.kick.

    • Settings apply after /antidupe reload.

Example configuration:

YAML
auto-kick:
  enabled: true

messages:
  kick: '&cYou have been removed from the server.'

Discord embed settings:

YAML
discord:
  enabled: true
  webhook-url: 'YOUR_WEBHOOK_URL'
  username: AntiDupeDetector
  embed:
    title: 'AntiDupe Detection'
    description: 'An inventory command was detected.'
    color: 15158332
    footer: 'AntiDupeDetector'
Tech Pat

Give me the .jar

Kodari AI
KodariSep 2 at 4:08 am 1

I can’t attach a compiled .jar from this workspace because Gradle/Javac and a Gradle wrapper aren’t available here. The complete plugin source is ready to build.

From the project directory, run:

Shell
gradle build

The jar will be generated at:

Plain Text
build/libs/AntiDupeDetector-1.0.0.jar

Copy it into your server’s plugins/ folder and restart the server.

Tech Pat

gradle build

Kodari AI
KodariSep 2 at 4:12 am 1

I can’t execute gradle build in this workspace because Gradle/Javac aren’t available here.

Run this from the project directory:

Shell
gradle build

The compiled plugin will be at:

Plain Text
build/libs/AntiDupeDetector-1.0.0.jar
Tech Pat

Where do I find that

Kodari AI
KodariSep 2 at 4:12 am 1

The .jar does not exist yet because the project has not been compiled.

Run gradle build from the folder containing build.gradle. After it succeeds, find it here:

Plain Text
AntiDupeDetector/
└── build/
    └── libs/
        └── AntiDupeDetector-1.0.0.jar

Then copy the JAR into:

Plain Text
your-minecraft-server/plugins/

If you’re using a terminal, navigate to the project folder first:

Shell
cd path/to/AntiDupeDetector
gradle build

If gradle is not recognized, install Gradle or use IntelliJ IDEA’s Gradle panel to run the build task.

Tech Pat

Give me source code so I can continue my self

Kodari AI
KodariSep 2 at 4:15 am 1

The complete source is below. Create this folder structure:

Plain Text
AntiDupeDetector/
├── build.gradle
├── settings.gradle
└── src/
    └── main/
        ├── java/
        │   └── me/patplays2/antidupe/
        │       ├── AntiDupeDetector.java
        │       └── DetectionLogger.java
        └── resources/
            ├── plugin.yml
            └── config.yml

build.gradle

Gradle
plugins {
    id 'java'
}

group = 'me.patplays2'
version = '1.0.0'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

repositories {
    mavenCentral()
    maven { url = uri('https://repo.papermc.io/repository/maven-public/') }
}

dependencies {
    compileOnly 'io.papermc.paper:paper-api:26.1.2-R0.1-SNAPSHOT'
}

tasks.withType(JavaCompile).configureEach {
    options.encoding = 'UTF-8'
}

settings.gradle

Gradle
pluginManagement {
    repositories {
        gradlePluginPortal()
    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        mavenCentral()
        maven { url = uri("https://repo.papermc.io/repository/maven-public/") }
    }
}

rootProject.name = "AntiDupeDetector"

src/main/resources/plugin.yml

YAML
name: AntiDupeDetector
version: '1.0.0'
main: me.patplays2.antidupe.AntiDupeDetector
api-version: '26.1'
description: Detects and logs inventory access commands commonly used by dupe tools.
author: patplays2

commands:
  antidupe:
    description: Manage AntiDupeDetector.
    usage: /antidupe reload
    permission: antidupe.reload

permissions:
  antidupe.reload:
    description: Reload AntiDupeDetector configuration.
    default: op

  antidupe.alerts:
    description: Receive AntiDupeDetector staff alerts.
    default: op

src/main/resources/config.yml

YAML
messages:
  reload-success: '&aAntiDupeDetector configuration reloaded.'
  no-permission: '&cYou do not have permission to use this command.'
  usage: '&eUsage: /antidupe reload'
  alert: '&c[AntiDupe] &f%sender% used &e%command% &7(target: %target%)'
  kick: '&cYou have been removed from the server.'

auto-kick:
  enabled: false

logging:
  console: true
  file: true
  file-name: detections.log

discord:
  enabled: false
  webhook-url: ''
  username: AntiDupeDetector

  embed:
    title: 'AntiDupe Detection'
    description: 'An inventory command was detected.'
    color: 15158332
    footer: 'AntiDupeDetector'

src/main/java/me/patplays2/antidupe/AntiDupeDetector.java

Java
package me.patplays2.antidupe;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class AntiDupeDetector extends JavaPlugin implements Listener {
    private DetectionLogger detectionLogger;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        this.detectionLogger = new DetectionLogger(this);

        getServer().getPluginManager().registerEvents(this, this);
        getLogger().info("AntiDupeDetector enabled.");
    }

    @Override
    public void onDisable() {
        getLogger().info("AntiDupeDetector disabled.");
    }

    @Override
    public boolean onCommand(
            CommandSender sender,
            Command command,
            String label,
            String[] args
    ) {
        if (!command.getName().equalsIgnoreCase("antidupe")) {
            return false;
        }

        if (!sender.hasPermission("antidupe.reload")) {
            sender.sendMessage(message("messages.no-permission"));
            return true;
        }

        if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
            reloadConfig();
            sender.sendMessage(message("messages.reload-success"));
            return true;
        }

        sender.sendMessage(message("messages.usage"));
        return true;
    }

    @EventHandler(priority = EventPriority.MONITOR)
    public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
        detectionLogger.processCommand(
                event.getPlayer(),
                event.getMessage()
        );
    }

    String message(String path) {
        String configured = getConfig().getString(path, "");
        return ChatColor.translateAlternateColorCodes('&', configured);
    }
}

src/main/java/me/patplays2/antidupe/DetectionLogger.java

Java
package me.patplays2.antidupe;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Pattern;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

final class DetectionLogger {
    private static final Set<String> DETECTED_COMMANDS = Set.of(
            "openinv",
            "inv",
            "invsee",
            "offlineinv"
    );

    private static final Pattern WHITESPACE = Pattern.compile("\\s+");

    private final AntiDupeDetector plugin;

    DetectionLogger(AntiDupeDetector plugin) {
        this.plugin = plugin;
    }

    void processCommand(Player player, String rawCommand) {
        Detection detection = createDetection(
                player.getName(),
                rawCommand,
                "player-command"
        );

        if (detection != null) {
            log(detection);

            if (plugin.getConfig().getBoolean("auto-kick.enabled", false)) {
                player.kickPlayer(plugin.message("messages.kick"));
            }
        }
    }

    private Detection createDetection(
            String sender,
            String rawCommand,
            String type
    ) {
        if (rawCommand == null || rawCommand.isBlank()) {
            return null;
        }

        String commandLine = rawCommand.charAt(0) == '/'
                ? rawCommand.substring(1)
                : rawCommand;

        String[] parts = WHITESPACE.split(commandLine.trim(), 2);

        if (parts.length == 0) {
            return null;
        }

        String commandName = parts[0].toLowerCase(Locale.ROOT);

        int namespaceSeparator = commandName.indexOf(':');
        if (namespaceSeparator >= 0) {
            commandName = commandName.substring(namespaceSeparator + 1);
        }

        if (!DETECTED_COMMANDS.contains(commandName)) {
            return null;
        }

        String target = "none";

        if (commandName.equals("openinv") && parts.length == 2) {
            String[] arguments = WHITESPACE.split(parts[1].trim());

            if (arguments.length >= 2
                    && arguments[0].equalsIgnoreCase("check")) {
                target = arguments[1];
            }
        }

        return new Detection(sender, rawCommand, target, type);
    }

    private void log(Detection detection) {
        String alert = format(
                plugin.getConfig().getString("messages.alert", ""),
                detection
        );

        for (Player player : Bukkit.getOnlinePlayers()) {
            if (player.hasPermission("antidupe.alerts")
                    && !alert.isEmpty()) {
                player.sendMessage(
                        ChatColor.translateAlternateColorCodes('&', alert)
                );
            }
        }

        boolean consoleLogging = plugin.getConfig().getBoolean(
                "logging.console",
                true
        );

        boolean fileLogging = plugin.getConfig().getBoolean(
                "logging.file",
                true
        );

        boolean discordLogging = plugin.getConfig().getBoolean(
                "discord.enabled",
                false
        );

        String fileName = plugin.getConfig().getString(
                "logging.file-name",
                "detections.log"
        );

        String discordUrl = plugin.getConfig().getString(
                "discord.webhook-url",
                ""
        );

        String discordUsername = plugin.getConfig().getString(
                "discord.username",
                "AntiDupeDetector"
        );

        String timestamp = OffsetDateTime.now().format(
                DateTimeFormatter.ISO_OFFSET_DATE_TIME
        );

        String logLine = timestamp
                + " | " + detection.type()
                + " | sender=" + detection.sender()
                + " | command=" + detection.command()
                + " | target=" + detection.target();

        if (consoleLogging) {
            plugin.getLogger().warning(logLine);
        }

        if (fileLogging
                || (discordLogging && !discordUrl.isBlank())) {
            Bukkit.getScheduler().runTaskAsynchronously(
                    plugin,
                    () -> {
                        if (fileLogging) {
                            appendToFile(fileName, logLine);
                        }

                        if (discordLogging && !discordUrl.isBlank()) {
                            sendWebhook(
                                    discordUrl,
                                    discordUsername,
                                    detection,
                                    timestamp
                            );
                        }
                    }
            );
        }
    }

    private void appendToFile(String configuredName, String line) {
        String fileName = configuredName == null
                || configuredName.isBlank()
                ? "detections.log"
                : configuredName;

        Path file = plugin.getDataFolder()
                .toPath()
                .resolve(fileName)
                .normalize();

        Path dataFolder = plugin.getDataFolder()
                .toPath()
                .toAbsolutePath()
                .normalize();

        if (!file.toAbsolutePath().startsWith(dataFolder)) {
            plugin.getLogger().warning(
                    "Configured detection log file must be inside "
                            + "the plugin data folder."
            );
            return;
        }

        try {
            Files.createDirectories(file.getParent());

            Files.writeString(
                    file,
                    line + System.lineSeparator(),
                    StandardCharsets.UTF_8,
                    StandardOpenOption.CREATE,
                    StandardOpenOption.WRITE,
                    StandardOpenOption.APPEND
            );
        } catch (IOException exception) {
            plugin.getLogger().warning(
                    "Could not write detection log: "
                            + exception.getMessage()
            );
        }
    }

    private void sendWebhook(
            String configuredUrl,
            String username,
            Detection detection,
            String timestamp
    ) {
        HttpURLConnection connection = null;

        try {
            URI uri = new URI(configuredUrl);

            if (!uri.getScheme().equalsIgnoreCase("http")
                    && !uri.getScheme().equalsIgnoreCase("https")) {
                plugin.getLogger().warning(
                        "Discord webhook URL must use HTTP or HTTPS."
                );
                return;
            }

            connection = (HttpURLConnection) uri.toURL().openConnection();
            connection.setRequestMethod("POST");
            connection.setConnectTimeout(5000);
            connection.setReadTimeout(5000);
            connection.setDoOutput(true);
            connection.setRequestProperty(
                    "Content-Type",
                    "application/json; charset=UTF-8"
            );

            String title = format(
                    plugin.getConfig().getString(
                            "discord.embed.title",
                            "AntiDupe Detection"
                    ),
                    detection
            );

            String description = format(
                    plugin.getConfig().getString(
                            "discord.embed.description",
                            "An inventory command was detected."
                    ),
                    detection
            );

            String footer = format(
                    plugin.getConfig().getString(
                            "discord.embed.footer",
                            "AntiDupeDetector"
                    ),
                    detection
            );

            int color = plugin.getConfig().getInt(
                    "discord.embed.color",
                    15158332
            );

            String payload = "{\"username\":\""
                    + jsonEscape(username)
                    + "\",\"embeds\":[{"
                    + "\"title\":\""
                    + jsonEscape(title)
                    + "\","
                    + "\"description\":\""
                    + jsonEscape(description)
                    + "\","
                    + "\"color\":"
                    + color
                    + ","
                    + "\"fields\":["
                    + fieldJson(
                            "Player",
                            detection.sender(),
                            true
                    )
                    + ","
                    + fieldJson(
                            "Command",
                            detection.command(),
                            true
                    )
                    + ","
                    + fieldJson(
                            "Target",
                            detection.target(),
                            true
                    )
                    + ","
                    + fieldJson(
                            "Type",
                            detection.type(),
                            true
                    )
                    + "],"
                    + "\"timestamp\":\""
                    + jsonEscape(timestamp)
                    + "\","
                    + "\"footer\":{\"text\":\""
                    + jsonEscape(footer)
                    + "\"}"
                    + "}]}";

            try (var output = connection.getOutputStream()) {
                output.write(payload.getBytes(StandardCharsets.UTF_8));
            }

            int status = connection.getResponseCode();

            if (status < 200 || status >= 300) {
                plugin.getLogger().warning(
                        "Discord webhook returned HTTP "
                                + status
                                + "."
                );
            }
        } catch (URISyntaxException | IOException exception) {
            plugin.getLogger().warning(
                    "Could not send Discord webhook: "
                            + exception.getMessage()
            );
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }
    }

    private String fieldJson(
            String name,
            String value,
            boolean inline
    ) {
        return "{\"name\":\""
                + jsonEscape(name)
                + "\",\"value\":\""
                + jsonEscape(value)
                + "\",\"inline\":"
                + inline
                + "}";
    }

    private String format(String template, Detection detection) {
        if (template == null) {
            return "";
        }

        return template
                .replace("%sender%", detection.sender())
                .replace("%player%", detection.sender())
                .replace("%command%", detection.command())
                .replace("%target%", detection.target())
                .replace("%type%", detection.type());
    }

    private String jsonEscape(String value) {
        if (value == null) {
            return "";
        }

        return value
                .replace("\\", "\\\\")
                .replace("\"", "\\\"")
                .replace("\r", "\\r")
                .replace("\n", "\\n")
                .replace("\t", "\\t");
    }

    private record Detection(
            String sender,
            String command,
            String target,
            String type
    ) {
    }
}

To build it, install Java 21 and Gradle, then run this inside the AntiDupeDetector folder:

Shell
gradle build

The compiled plugin will be located at:

Plain Text
build/libs/AntiDupeDetector-1.0.0.jar
Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
6 351
src/main/java/me/patplays2/antidupe/AntiDupeDetector.java
package me.patplays2.antidupe;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class AntiDupeDetector extends JavaPlugin implements Listener {
    private DetectionLogger detectionLogger;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        this.detectionLogger = new DetectionLogger(this);
        getServer().getPluginManager().registerEvents(this, this);
        getLogger().info("AntiDupeDetector enabled.");
    }

    @Override
    public void onDisable() {
        getLogger().info("AntiDupeDetector disabled.");
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!command.getName().equalsIgnoreCase("antidupe")) {
            return false;
        }

        if (!sender.hasPermission("antidupe.reload")) {
            sender.sendMessage(message("messages.no-permission"));
            return true;
        }

        if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
            reloadConfig();
            sender.sendMessage(message("messages.reload-success"));
            return true;
        }

        sender.sendMessage(message("messages.usage"));
        return true;
    }

    @EventHandler(priority = EventPriority.MONITOR)
    public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
        detectionLogger.processCommand(event.getPlayer(), event.getMessage());
    }

    String message(String path) {
        String configured = getConfig().getString(path, "");
        return ChatColor.translateAlternateColorCodes('&', configured);
    }
}