YT Tech
📎 1 file 10,065 chars
📄
pasted-code-1790404214515.txt
txt 660 lines
▶
Create a production-ready Minecraft Paper plugin that allows authorized Discord staff members to execute specific Minecraft moderation commands from a designated Discord channel.

## Core Concept

Discord staff:

/mcban Steve Griefing

```
    ↓
```

Discord Bot

```
    ↓
```

Permission + command validation

```
    ↓
```

Minecraft server

```
    ↓
```

Execute ban command

The system must NOT allow arbitrary Discord users to execute Minecraft commands.

---

# Supported Discord Commands

Implement these commands:

### Ban

```text
/mcban  
```

Example:

```text
/mcban Steve Griefing
```

Execute the configured Minecraft ban action.

---

### Temporary Timeout

```text
/mctimeout   
```

Example:

```text
/mctimeout Steve 10m Spamming
```

Support durations such as:

```text
30s
5m
1h
1d
```

The plugin should validate the duration before executing the action.

If the server has a compatible punishment plugin, allow the command used for timeout to be configured.

---

### Kick

```text
/mckick  
```

Example:

```text
/mckick Steve Spamming
```

Kick the player from the Minecraft server with the specified reason.

---

# Discord Channel Restriction

Commands must work ONLY inside the configured Discord channel.

Example:

```yml
discord:
  channel-id: "YOUR_CHANNEL_ID"
```

If somebody attempts:

```text
/mcban Steve
```

in another channel:

Do not execute the command.

Optionally reply:

```text
❌ This command can only be used in the Minecraft staff channel.
```

---

# Discord Staff Authorization

Create a whitelist of authorized Discord user IDs.

Example:

```yml
staff:
  allowed-user-ids:
    - "123456789012345678"
    - "987654321098765432"
```

Only these Discord users can execute Minecraft moderation commands.

Unauthorized users must receive:

```text
❌ You do not have permission to use Minecraft moderation commands.
```

Do NOT execute anything in Minecraft.

Use Discord user IDs rather than usernames because usernames can change.

---

# Discord Roles

Also support optional role-based authorization.

Example:

```yml
staff:
  allowed-role-ids:
    - "123456789012345678"
```

Configuration option:

```yml
staff:
  authorization-mode: "USER_OR_ROLE"
```

Supported modes:

```text
USER
ROLE
USER_OR_ROLE
```

---

# Security

This is extremely important.

The plugin must NEVER allow arbitrary Discord users to execute:

```text
/mcban ...
/mctimeout ...
/mckick ...
```

Do NOT create a generic Discord command such as:

```text
/mcexec 
```

Do NOT allow Discord users to execute arbitrary Minecraft console commands.

Only the explicitly implemented commands should be available.

Validate:

* Discord channel
* Discord user
* Discord role
* Minecraft player
* Duration
* Reason

---

# Minecraft Execution

Minecraft commands must be executed safely on the Minecraft main server thread.

Discord network handling must remain asynchronous.

When a Discord command is received:

1. Validate Discord channel.
2. Validate Discord user/role.
3. Parse arguments.
4. Validate target player.
5. Validate duration if required.
6. Schedule the Minecraft action on the server thread.
7. Return the result to Discord.

Never block the Minecraft main thread while waiting for Discord.

---

# Player Handling

Support both online and offline players where appropriate.

For example:

```text
/mcban Steve Griefing
```

should be able to ban an offline player if the configured punishment system supports offline bans.

For kick:

```text
/mckick Steve Spamming
```

the target must be online.

If the player doesn't exist:

```text
❌ Player `Steve` could not be found.
```

---

# Discord Response

After successful execution, send a clean Discord Embed.

Example:

## 🔨 PLAYER BANNED

**Player**
`Steve`

**Moderator**
`DiscordStaff`

**Reason**
`Griefing`

**Time**
`26 September 2026 • 12:05 PM`

**Source**
`Discord`

Footer:

```text
MALABAR SMP • Moderation
```

---

For kick:

## 👢 PLAYER KICKED

**Player**
`Steve`

**Moderator**
`DiscordStaff`

**Reason**
`Spamming`

---

For timeout:

## ⏳ PLAYER TIMED OUT

**Player**
`Steve`

**Duration**
`10 minutes`

**Reason**
`Spamming`

**Moderator**
`DiscordStaff`

---

# Confirmation

For dangerous moderation actions, support optional confirmation.

Configuration:

```yml
confirmation:
  enabled: true
  timeout-seconds: 15
```

Example:

```text
/mcban Steve Griefing
```

Bot responds:

```text
⚠️ Confirm ban of Steve?

[Confirm] [Cancel]
```

Only the Discord user who created the command should be able to confirm it.

---

# Logging

Create a separate configurable Discord log channel.

```yml
logs:
  enabled: true
  channel-id: "LOG_CHANNEL_ID"
```

Every successful moderation action should be logged.

Example:

```text
🔨 BAN LOG

Player: Steve
Moderator: DiscordStaff
Reason: Griefing
Source: Discord
Time: 12:05 PM
```

This should be separate from the command channel if configured.

---

# Minecraft Console Logging

Also log actions to the Minecraft console:

```text
[DiscordControl] DiscordStaff banned Steve
[DiscordControl] Reason: Griefing
```

Never print the Discord bot token.

---

# Configuration

Create a clean configuration:

```yml
discord:
  enabled: true
  bot-token: "YOUR_BOT_TOKEN"
  command-channel-id: "YOUR_CHANNEL_ID"

staff:
  authorization-mode: "USER_OR_ROLE"

  allowed-user-ids:
    - "DISCORD_USER_ID"

  allowed-role-ids:
    - "DISCORD_ROLE_ID"

logs:
  enabled: true
  channel-id: "LOG_CHANNEL_ID"

commands:
  ban:
    enabled: true
    minecraft-command: "ban {player} {reason}"

  timeout:
    enabled: true
    minecraft-command: "timeout {player} {duration} {reason}"

  kick:
    enabled: true
    minecraft-command: "kick {player} {reason}"

confirmation:
  enabled: true
  timeout-seconds: 15

timezone: "Asia/Kolkata"
```

IMPORTANT:

Do not blindly execute the configured command strings.

Only allow the three supported actions:

```text
ban
timeout
kick
```

Validate their arguments and prevent command injection.

---

# Discord Bot

Use JDA or another reliable Discord library.

The bot must:

* Connect automatically.
* Reconnect after temporary Discord connection problems.
* Handle invalid token gracefully.
* Handle missing channel gracefully.
* Handle missing permissions gracefully.
* Never crash the Minecraft server.
* Shut down cleanly when the plugin disables.
* Never expose the bot token.

Required Discord permissions should be kept minimal.

---

# Discord Slash Commands

Register proper Discord slash commands:

```text
/mcban
/mctimeout
/mckick
```

Do NOT rely only on parsing ordinary Discord chat messages.

Use Discord's slash-command system so users get proper argument fields.

Example:

```text
/mcban
    player: Steve
    reason: Griefing
```

For timeout:

```text
/mctimeout
    player: Steve
    duration: 10m
    reason: Spamming
```

For kick:

```text
/mckick
    player: Steve
    reason: Spamming
```

---

# Permissions

Minecraft permissions:

```text
discordcontrol.reload
discordcontrol.status
```

Discord authorization must remain independent from Minecraft permissions.

---

# Commands

Minecraft:

```text
/discordcontrol reload
/discordcontrol status
```

`reload` reloads configuration safely.

`status` displays:

```text
Discord: Connected
Command Channel: Connected
Log Channel: Connected
Authorized Staff: 4
```

---

# Anti-Abuse Protection

Implement:

* Rate limiting.
* Duplicate command protection.
* Confirmation timeout.
* Discord authorization.
* Channel restriction.
* Input validation.
* Player-name validation.
* Duration validation.
* Reason length limit.

Example:

```yml
security:
  max-reason-length: 200
  rate-limit:
    enabled: true
    commands-per-minute: 20
```

---

# Audit Information

Every action must record:

```text
Discord User ID
Discord Username
Minecraft Player
Action
Reason
Timestamp
```

Use:

```text
Asia/Kolkata
```

for timestamps by default, but make timezone configurable.

---

# Performance

The plugin must:

* Never block the Minecraft main thread with Discord API calls.
* Never repeatedly poll Discord unnecessarily.
* Use asynchronous Discord operations.
* Use the Minecraft scheduler only for Minecraft API operations.
* Clean up all tasks/listeners on shutdown.
* Avoid memory leaks.
* Support multiple Discord staff members using commands simultaneously.

---

# Compatibility

Target:

* Paper
* Minecraft 1.21.x
* Java 21

Avoid unnecessary NMS.

Use Bukkit/Paper APIs wherever possible.

Structure the plugin so future Minecraft versions can be supported easily.

---

# Testing

Test all of the following:

1. Authorized Discord user uses `/mcban`.
2. Unauthorized Discord user uses `/mcban`.
3. Command in wrong channel.
4. Online player kick.
5. Offline player ban.
6. Invalid player.
7. Invalid duration.
8. Empty reason.
9. Very long reason.
10. Multiple staff members using commands simultaneously.
11. Discord disconnect.
12. Minecraft server restart.
13. Plugin reload.
14. Bot reconnect.
15. Confirmation timeout.
16. Cancelled confirmation.
17. Attempted command injection.
18. Verify bot token never appears in logs.

The final plugin must be production-ready, secure, lightweight, and designed specifically for server administration through Discord.

Do not implement a generic remote console. Only implement the explicitly defined moderation commands.
Kodari AI
KodariSep 26 at 6:32 am 2
DiscordModerationBridge
A secure Paper plugin bridging Discord and Minecraft for staff moderation. Authorized Discord users execute /mcban, /mctimeout, and /mckick slash commands in a designated channel. Features multi-layer authorization (user IDs, role IDs, configurable modes), channel restriction, input validation, rate limiting, optional confirmation flow, and comprehensive audit logging to a separate Discord log channel and Minecraft console. Uses JDA for async Discord handling, Bukkit scheduler for safe Minecraft execution, and supports offline bans. Includes /discordcontrol reload and status commands with configurable timezone and punishment command templates.

I’ll build the plugin around three fixed slash commands, immutable settings snapshots, and main-thread-only Minecraft actions.

  1. Create the Paper/JDA project metadata and secure default configuration.

  2. Add Discord startup, authorization, rate limiting, confirmations, and audit handling.

  3. Add the protected Minecraft admin command for reload and status.

Created DiscordControl, a Paper 1.21.4 / Java 21 plugin with JDA slash commands.

  • Implements /mcban, /mctimeout, and /mckick only—no generic remote console.

  • Enforces the configured channel and user/role authorization, with input validation, rate limiting, duplicate protection, and optional requester-only confirmations.

  • Runs Minecraft commands on the server thread. Ban and timeout can target cached offline players; kick requires an online player.

  • Adds timezone-aware Discord audit embeds and console logs, plus /discordcontrol reload and /discordcontrol status with separate permissions.

Configure the bot token, channel IDs, staff IDs/roles, and command templates in config.yml. Timeout templates are restricted to supported punishment-command roots. Grant the bot access to the command channel and View Channel, Send Messages, and Embed Links in the log channel.

Live Paper/Discord integration tests were not run in this environment.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
settings.gradle
Code
11 926
src/main/java/com/kodari/discordcontrol/DiscordControlPlugin.java
package com.kodari.discordcontrol;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

public final class DiscordControlPlugin extends JavaPlugin {
    private volatile PluginSettings settings;
    private volatile JDA jda;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        settings = PluginSettings.load(getConfig());

        PluginCommand command = getCommand("discordcontrol");
        if (command != null) {
            command.setExecutor(new DiscordControlCommand(this));
        }

        startDiscord();
    }

    @Override
    public void onDisable() {
        JDA current = jda;
        jda = null;
        if (current != null) {
            current.shutdown();
        }
    }

    PluginSettings settings() {
        return settings;
    }

    JDA jda() {
        return jda;
    }

    void reloadIntegration() {
        reloadConfig();
        settings = PluginSettings.load(getConfig());
        startDiscord();
    }

    private void startDiscord() {
        JDA previous = jda;
        jda = null;
        if (previous != null) {
            previous.shutdown();
        }

        PluginSettings currentSettings = settings;
        if (!currentSettings.discordEnabled()) {
            getLogger().info("Discord integration is disabled in the configuration.");
            return;
        }

        String token = currentSettings.botToken();
        if (token == null || token.isBlank() || token.equalsIgnoreCase("YOUR_BOT_TOKEN")) {
            getLogger().warning("Discord bot token is not configured; Discord integration was not started.");
            return;
        }

        try {
            jda = JDABuilder.createDefault(token)
                    .addEventListeners(new ModerationListener(this))
                    .build();
            getLogger().info("Connecting to Discord.");
        } catch (RuntimeException exception) {
            getLogger().severe("Discord could not be started. Check the bot token and JDA configuration.");
            jda = null;
        }
    }
}