venom2064
📎 1 file 2,887 chars
📄
pasted-code-1783100241990.txt
txt 108 lines
▶
Prompt
Create a Minecraft Paper plugin (latest Paper API, Java 21, Maven project) that logs commands executed by operators (OPs) and the server console to a Discord channel using a Discord Webhook URL.
Requirements
Compatible with the latest Paper version.
Use Maven for dependency management.
Plugin name: OperatorCommandLogger
Main package: com.example.operatorcommandlogger
Functionality
Listen for commands executed by players and the server console.
Log commands executed by players with operator status (player.isOp()).
Also log commands executed directly through the Minecraft server console.
Do not log commands executed by command blocks, command block minecarts, plugins, or any other sender types.
Send each logged command to a Discord channel using a configurable Discord webhook URL.
Discord Message Format
For player commands:
Player: Notch
Command:
/gamemode creative

Time:
2026-07-03 18:24:12
For console commands:
Player: Console
Command:
/stop

Time:
2026-07-03 18:25:01
Use Discord embeds if possible.
Configuration
Generate a config.yml with:
webhook-url: ""
ignored-commands:
  - msg
  - tell
  - w
  - whisper
  - r
  - reply
  - me
  - teammsg
  - tm
  - minecraft:msg
  - minecraft:tell
The webhook URL should be loaded from the config.
Ignored Commands
Commands in ignored-commands should never be sent to Discord.
The comparison should:

Ignore the leading /
Be case-insensitive
Ignore namespaces (minecraft:msg and msg should both match)
Only compare the base command, not arguments.
Examples that should NOT be logged:
/msg Steve hi
/tell Steve hi
/w Steve hi
/whisper Steve hi
/r hello
/reply hello
/me waves
/teammsg hello
/tm hello
Examples that should be logged:
/gamemode creative
/give Steve diamond 64
/op Steve
/deop Steve
/ban Steve
/kick Steve
/stop
/reload
/execute ...
Webhook Requirements
Use Java's HTTP client (or OkHttp).
Send webhook requests asynchronously.
Do not block the server thread.
Handle failures gracefully.
Log webhook errors to the server console.
Additional Features
Include:
Plugin reload command:
/operatorcommandlogger reload
which reloads config.yml.
Permission:
operatorcommandlogger.reload
Code Quality
Use clean, object-oriented design.
Separate classes for:
Main plugin
Event listener
Webhook sender
Configuration manager
Include comments explaining important logic.
Prevent duplicate webhook sends.
Properly escape Discord JSON.
Follow Paper API best practices.
Deliverables
Provide:
Complete Maven project structure.
Full Java source code.
plugin.yml
config.yml
pom.xml
Instructions for building with Maven.
Ensure the project compiles without errors.
The final plugin should be production-ready, efficient enough to run on large Paper servers without affecting performance, and should correctly distinguish between operator player commands and commands executed directly from the server console in the Discord logs.
Kodari AI
KodariJul 3 at 5:38 pm 1

I’ll create the OperatorCommandLogger plugin — a Paper plugin that logs OP and console commands to Discord via webhook.

OperatorCommandLogger
Logs commands executed by operators and the server console to a Discord channel via webhook. Features configurable ignored commands, Discord embed formatting, asynchronous non-blocking webhook requests, a reload command, and proper deduplication. Supports namespace-ignored command matching with case-insensitive comparisons.

Project structure:

Plain Text
OperatorCommandLogger/
├── pom.xml
├── src/main/resources/
│   ├── plugin.yml
│   └── config.yml
└── src/main/java/com/example/operatorcommandlogger/
    ├── OperatorCommandLogger.java
    ├── command/
    │   └── ReloadCommand.java
    ├── config/
    │   └── ConfigManager.java
    ├── listener/
    │   └── CommandListener.java
    └── webhook/
        └── WebhookSender.java

Key design decisions:

  • Event filtering — PlayerCommandPreprocessEvent with player.isOp() check for players; ServerCommandEvent with ConsoleCommandSender instanceof check for the console. Command blocks, RCON, and plugins are excluded.

  • Command normalization — strips /, arguments, namespace (minecraft:), and lowercases before comparing against the ignored list. /msg Steve hi → msg matches the config entry.

  • Async webhook — java.net.http.HttpClient.sendAsync() never blocks the server thread. Failures log to console without throwing.

  • Dedup — ConcurrentHashMap with 2-second window prevents duplicate sends from rapid event firings.

  • Discord embeds — proper JSON structure with title, color, fields (Player inline, Command, Time), and footer.

  • Reload — /operatorcommandlogger reload with operatorcommandlogger.reload permission, reloads config.yml.

Build: mvn clean package produces target/OperatorCommandLogger-1.0.0.jar. Place in plugins/, set webhook-url in config.yml, restart or /reload confirm.

Kodari can make mistakes. Review important code before using.
Files
src
pom.xml
Code
8 429
src/main/java/com/example/operatorcommandlogger/OperatorCommandLogger.java
package com.example.operatorcommandlogger;

import com.example.operatorcommandlogger.command.ReloadCommand;
import com.example.operatorcommandlogger.config.ConfigManager;
import com.example.operatorcommandlogger.listener.CommandListener;
import com.example.operatorcommandlogger.webhook.WebhookSender;
import org.bukkit.plugin.java.JavaPlugin;

public class OperatorCommandLogger extends JavaPlugin {

    private ConfigManager configManager;
    private WebhookSender webhookSender;

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

        this.configManager = new ConfigManager(this);
        this.webhookSender = new WebhookSender(this);

        getServer().getPluginManager().registerEvents(new CommandListener(this), this);

        getCommand("operatorcommandlogger").setExecutor(new ReloadCommand(this));

        getLogger().info("OperatorCommandLogger enabled.");
    }

    @Override
    public void onDisable() {
        if (webhookSender != null) {
            webhookSender.shutdown();
        }
        getLogger().info("OperatorCommandLogger disabled.");
    }

    public ConfigManager getConfigManager() {
        return configManager;
    }

    public WebhookSender getWebhookSender() {
        return webhookSender;
    }

    public void reload() {
        reloadConfig();
        configManager.reload();
        getLogger().info("Configuration reloaded.");
    }
}