kingbob16526
📎 1 file 3,572 chars
📄
pasted-code-1769058422256.txt
txt 97 lines
▶
You are an expert Minecraft plugin developer. Create a complete, production-ready Spigot/Paper plugin in Java that links a Minecraft server console to a Discord channel in real time.

## Goal

Build a plugin that:

1. Streams the Minecraft server console output to a specific Discord channel in real time.
2. Lets users type commands in that Discord channel, which are then executed on the Minecraft server as console commands.
3. Blocks dangerous or sensitive commands (e.g., /op) from being executed via Discord.
4. Uses a Discord bot (via token) to send and receive messages.
5. Is configurable via a config.yml file.
6. Is delivered as:
   - Full Java source code
   - plugin.yml
   - config.yml
   - Clear build instructions (Maven or Gradle)
   - Ready to compile into a JAR

## Technical Requirements

### Platform

- Target: Spigot/Paper Minecraft server
- Version: 1.20.4 (if you must pick one; keep it as version-agnostic as possible)
- Language: Java
- Build system: Maven (preferred) or Gradle

### Discord Integration

- Use JDA (Java Discord API) for Discord integration.
- The plugin must read the following from `config.yml`:
  - `discord-bot-token`: The bot token.
  - `console-channel-id`: The Discord channel ID where console logs and commands are handled.
  - `blocked-commands`: A list of blocked commands (strings) that must not be executed from Discord.
- The bot should:
  - Connect on plugin enable.
  - Disconnect cleanly on plugin disable.

### Console → Discord

- All console output (server logs) should be mirrored to the configured Discord channel in real time.
- Use a listener or appender that captures console output.
- Each console line should be sent as a message to the Discord channel.
- Implement basic rate limiting or batching if necessary to avoid hitting Discord rate limits (e.g., group multiple lines into a single message if they come in very fast).

### Discord → Console

- Messages sent in the configured Discord channel should be treated as console commands.
- For example, if a user types:
  - `say Hello from Discord`
  - The plugin should execute this as a console command on the Minecraft server.
- Commands must be executed as if they were run from the server console (not as a player).
- Before executing, the plugin must:
  - Check the command against the `blocked-commands` list.
  - If the command starts with or matches a blocked command (e.g., "op", "deop", "stop", "restart", "reload"), it must NOT be executed.
  - Instead, send a message back to the Discord channel saying the command is blocked.

### Blocked Commands

In `config.yml`, include a default list like:

- `op`
- `deop`
- `stop`
- `restart`
- `reload`
- `plugman`
- `plugman:*`

The plugin should treat these as prefixes: if a command starts with one of these entries, it is blocked.

### Messages and Formatting

- Console output to Discord:
  - Prefix messages with something like `[CONSOLE]` or similar.
- Commands from Discord:
  - Optionally log to console that a command was run from Discord, including the Discord username and discriminator.
- Do NOT spoof a "Console" user in Discord; the messages should clearly come from the bot account.

### Configuration

Create a `config.yml` with at least:

```yaml
discord-bot-token: "PUT_YOUR_TOKEN_HERE"
console-channel-id: "000000000000000000"
blocked-commands:
  - "op"
  - "deop"
  - "stop"
  - "restart"
  - "reload"
  - "plugman"
  - "plugman:*"
log-batch-size: 5
log-batch-interval-ticks: 20
Kodari AI
KodariJan 22 at 5:08 am 7,094 (v2)

I’ll create a complete Discord-Console bridge plugin for Minecraft.

ConsoleDiscordBridge
A comprehensive Minecraft-Discord integration plugin that provides real-time bidirectional console communication. Streams server console output to Discord channels and allows authorized Discord users to execute console commands remotely. Features advanced command filtering, rate limiting, message batching, and secure token-based authentication. Supports all Spigot/Paper versions 1.16.5+ with full JDA integration.

Creating complete project structure

Build Instructions

Prerequisites

  • Java 8 or higher

  • Gradle (or use ./gradlew wrapper)

Compilation Steps

Using Gradle Wrapper (Recommended):

Shell
./gradlew clean build

Using System Gradle:

Shell
gradle clean build

Output

The compiled JAR will be located at:

Plain Text
build/libs/ConsoleDiscordBridge-1.0.0.jar

Installation

  1. Place the JAR in your server’s plugins/ folder

  2. Start the server once to generate config.yml

  3. Stop the server

  4. Edit plugins/ConsoleDiscordBridge/config.yml:

    • Add your Discord bot token

    • Add your Discord channel ID

  5. Restart the server

Discord Bot Setup

  1. Create a new application

  2. Go to the “Bot” section and create a bot

  3. Enable “MESSAGE CONTENT INTENT” under Privileged Gateway Intents

  4. Copy the bot token

  5. Invite the bot to your server with permissions: Send Messages, Read Message History, Add Reactions

Configuration Example

YAML
discord-bot-token: "YOUR_ACTUAL_BOT_TOKEN_HERE"
console-channel-id: "1234567890123456789"
blocked-commands:
  - "op"
  - "deop"
  - "stop"
log-batch-size: 5
log-batch-interval-ticks: 20

✅ Complete plugin created with:

  • Real-time console → Discord streaming

  • Discord → Console command execution

  • Command filtering/blocking

  • Message batching for rate limiting

  • Log4j integration for console capture

  • Clean startup/shutdown

  • Full JDA integration

  • Production-ready error handling

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
Code
9 431
src/main/java/com/consolediscord/ConsoleDiscordBridge.java
package com.consolediscord;

import com.consolediscord.discord.DiscordManager;
import com.consolediscord.logging.ConsoleAppender;
import org.bukkit.plugin.java.JavaPlugin;

public class ConsoleDiscordBridge extends JavaPlugin {
    private DiscordManager discordManager;
    private ConsoleAppender consoleAppender;
    
    @Override
    public void onEnable() {
        saveDefaultConfig();
        
        String token = getConfig().getString("discord-bot-token");
        String channelId = getConfig().getString("console-channel-id");
        
        if (token == null || token.equals("PUT_YOUR_TOKEN_HERE")) {
            getLogger().severe("Discord bot token not configured! Please set it in config.yml");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        
        if (channelId == null || channelId.equals("000000000000000000")) {
            getLogger().severe("Console channel ID not configured! Please set it in config.yml");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        
        discordManager = new DiscordManager(this);
        if (!discordManager.connect(token, channelId)) {
            getLogger().severe("Failed to connect to Discord! Disabling plugin...");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        
        consoleAppender = new ConsoleAppender(this, discordManager);
        consoleAppender.register();
        
        getLogger().info("ConsoleDiscordBridge enabled successfully!");
    }
    
    @Override
    public void onDisable() {
        if (consoleAppender != null) {
            consoleAppender.unregister();
        }
        
        if (discordManager != null) {
            discordManager.disconnect();
        }
        
        getLogger().info("ConsoleDiscordBridge disabled.");
    }
    
    public DiscordManager getDiscordManager() {
        return discordManager;
    }
}