notkit690
๐Ÿ“Ž 1 file 4,622 chars
๐Ÿ“„
pasted-code-1783661794688.txt
txt 299 lines
โ–ถ
Create a production-ready Minecraft plugin called "DiscordBridge" for PaperMC 1.21.8 using Java 21, Gradle (Kotlin DSL), and the latest Paper API.

Objective:
The plugin should connect a Minecraft server with a Discord server so that Minecraft chat, server events, and Discord messages are synchronized in real time.

Requirements

General
- Java 21
- PaperMC 1.21.8
- Latest Paper API
- JDA (Java Discord API)
- Gradle Kotlin DSL
- Clean package structure
- Asynchronous networking
- No server lag
- Follow SOLID principles
- Fully documented code
- Production ready

Configuration

config.yml

discord:
  token: "BOT_TOKEN"
  guild-id: 123456789012345678
  chat-channel: 123456789012345678
  logs-channel: 123456789012345678
  status-channel: 123456789012345678

minecraft:
  server-name: "My Survival Server"
  chat-format: "&7[MC] &f%player% &8ยป &f%message%"
  discord-format: "&9[Discord] &b%user% &8ยป &f%message%"

features:
  relay-chat: true
  relay-joins: true
  relay-quits: true
  relay-deaths: true
  relay-advancements: true
  relay-console: false
  relay-server-start: true
  relay-server-stop: true
  relay-player-list: true
  webhook-mode: false

Chat Bridge

Minecraft โ†’ Discord

Whenever a player chats:
Steve: Hello everyone!

Discord receives:

๐ŸŸฉ Minecraft
Steve
Hello everyone!

with timestamp and avatar if possible.

Discord โ†’ Minecraft

When someone sends a message in the configured Discord channel:

[Discord] Username ยป Hello!

should appear in Minecraft.

Ignore bot messages.

Join/Quit

Player joined

๐ŸŸข Steve joined the server.

Player left

๐Ÿ”ด Steve left the server.

Death Messages

Relay every vanilla death message.

Example

โ˜  Steve was blown up by Creeper

Advancements

Relay advancements.

๐Ÿ† Steve has made the advancement
Monster Hunter

Server Start

When plugin loads

๐ŸŸข Minecraft Server Started

Server Stop

Before shutdown

๐Ÿ”ด Minecraft Server Stopped

Discord Slash Commands

/register commands

/playerlist

Shows

Online Players (4)

Steve
Alex
Notch
Herobrine

/ping

Shows

Server TPS
MSPT
Online players
Memory usage

/help

Displays commands.

Rich Discord Embeds

Use Discord embeds instead of plain text.

Chat embed:
- Player avatar
- Username
- Message
- Timestamp

Join embed:
Green

Quit embed:
Red

Death embed:
Dark Red

Advancement:
Gold

Console Logs

Optional.

Forward severe console errors to the logs channel.

Reconnect System

If Discord disconnects:
- Retry automatically.
- Exponential backoff.
- Never crash Minecraft.

PlaceholderAPI Support

Support placeholders including

%player%
%displayname%
%world%
%x%
%y%
%z%
%ping%

Permissions

discordbridge.reload
discordbridge.admin

Commands

/db reload

Reload config

/db reconnect

Reconnect Discord bot

/db status

Shows

Discord Connected
Latency
Guild
Channel

Message Formatting

Minecraft

[Discord] Username ยป Message

Discord

[MC]
Steve
Hello

Adventure API

Use MiniMessage and Adventure Components.

Performance

Never block the main thread.

Use async tasks for:
Discord API
HTTP requests
Avatar loading

Logging

Colored console logs.

Example

[DiscordBridge] Connected to Discord.
[DiscordBridge] Listening in #minecraft-chat

Error Handling

Missing token
Invalid channel
No permissions
Network errors
Reconnect failures

Project Structure

discordbridge/
โ”œโ”€โ”€ commands/
โ”œโ”€โ”€ config/
โ”œโ”€โ”€ discord/
โ”œโ”€โ”€ listeners/
โ”œโ”€โ”€ services/
โ”œโ”€โ”€ managers/
โ”œโ”€โ”€ utils/
โ”œโ”€โ”€ models/

Generate

- build.gradle.kts
- settings.gradle.kts
- plugin.yml
- config.yml
- README.md
- Complete source code
- Javadocs
- Comments

Bonus Features

- Webhook mode (Minecraft messages appear with player skin/avatar)
- Discord role synchronization
- Mention support (@player)
- Emoji support
- Markdown filtering
- Image attachment notifications
- Reply support
- Chat cooldown
- Discord message edit detection
- Discord delete detection
- Auto-update checker
- Metrics via bStats
- Config auto migration
- Optional MySQL logging
- Optional SQLite logging
- Optional LuckPerms group prefixes
- Optional Geyser/Floodgate Bedrock player support
- Optional Dynmap integration
- Optional DiscordSRV compatibility mode

Final Goal

The finished plugin should be a modern, optimized, production-ready Discord bridge comparable in quality to DiscordSRV, with clean architecture, excellent performance, and easy configuration.
Kodari AI
KodariJul 10 at 5:41 am 13
DiscordBridge
DiscordBridge synchronizes Minecraft and Discord in real time for Paper servers. It relays player chat, joins, quits, deaths, advancements, and server lifecycle events through rich Discord embeds while displaying Discord messages in Minecraft using Adventure components. The plugin includes asynchronous JDA networking, automatic reconnects with exponential backoff, slash commands for player lists and diagnostics, configurable channels and formats, permission-controlled administration commands, optional PlaceholderAPI support, and production-focused error handling.
  • Build the Paper 1.21.8 Java 21 Gradle project with JDA and external dependency metadata.

  • Add configurable Discord connectivity, asynchronous reconnect handling, rich embeds, and slash commands.

  • Add Minecraft event listeners, Adventure-based formatting, PlaceholderAPI compatibility, and /db administration commands.

  • Add plugin metadata, default configuration, and setup documentation.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle.kts
manifest.kod
README.md
settings.gradle.kts
Code
14 1,136
src/main/java/com/kodari/discordbridge/DiscordBridge.java
package com.kodari.discordbridge;

import com.kodari.discordbridge.commands.DiscordBridgeCommand;
import com.kodari.discordbridge.config.ConfigManager;
import com.kodari.discordbridge.discord.DiscordManager;
import com.kodari.discordbridge.listeners.MinecraftListener;
import com.kodari.discordbridge.services.MessageService;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

/**
 * Main plugin entry point for DiscordBridge.
 */
public final class DiscordBridge extends JavaPlugin {
    private ConfigManager configManager;
    private DiscordManager discordManager;
    private MessageService messageService;

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

        configManager = new ConfigManager(this);
        discordManager = new DiscordManager(this, configManager);
        messageService = new MessageService(this, configManager, discordManager);

        Bukkit.getPluginManager().registerEvents(new MinecraftListener(messageService), this);

        DiscordBridgeCommand command = new DiscordBridgeCommand(this);
        if (getCommand("db") != null) {
            getCommand("db").setExecutor(command);
            getCommand("db").setTabCompleter(command);
        }

        discordManager.start(messageService);

        if (configManager.relayServerStart()) {
            messageService.sendServerStart();
        }

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

    @Override
    public void onDisable() {
        if (messageService != null && configManager.relayServerStop()) {
            messageService.sendServerStop();
        }

        if (discordManager != null) {
            discordManager.shutdown();
        }

        getLogger().info("DiscordBridge disabled.");
    }

    /**
     * Reloads the plugin configuration.
     */
    public void reloadConfiguration() {
        reloadConfig();
    }

    public ConfigManager getConfigManager() {
        return configManager;
    }

    public DiscordManager getDiscordManager() {
        return discordManager;
    }

    public MessageService getMessageService() {
        return messageService;
    }
}