Build the Paper server plugin half of a two-way Minecraft chat bridge, intended for Paper 26.2, using the Bukkit/Paper API (no NMS). Read existing files first (currently empty) and create all needed files. This pairs with a Python Discord bot WebSocket server at a configured URL. Add plugin config for ws URL (default ws://127.0.0.1:8765), shared BRIDGE_TOKEN, reconnect settings if needed. Authenticate as the FIRST WebSocket JSON text frame {"type":"auth","token":"<token>"}; wait for {"type":"auth_ok"} before sending chat or handling Discord frames. Protocol thereafter: plugin -> bot JSON frame {"type":"minecraft_chat","username":"<player name>","message":"<plain text>"}; bot -> plugin frame {"type":"discord_chat","username":"<Discord display name>","message":"<text>"}. On receiving Discord chat, broadcast to all online players exactly (<username>) > <message>, safely on the Bukkit main thread. Forward ONLY actual human player chat from Paper's player chat event (not console/system/plugin output); ignore cancelled events; serialize the message to plain text and send exactly one frame. Do not echo Discord-delivered chat back as Minecraft-originated chat. Implement async connection/reconnect without blocking server startup/main thread, reasonable validation, and stop/shutdown cleanup. Ensure compatibility with the project's Paper 26.2 build setup, add necessary external dependencies through the project's proper manifest/build mechanism, and provide config/setup documentation explaining that the bot host must be network reachable and both sides use the same secret. Done means a runnable Paper plugin with the stated behavior and matching JSON protocol.

Kodari AI
KodariSep 29 at 7:52 pm 1
ChatBridge
Paper plugin implementing a two-way Minecraft chat bridge to a Python Discord bot via WebSocket. Connects asynchronously to a configured WebSocket server, authenticates with a shared token, and relays player chat messages to Discord while broadcasting Discord messages to all online players. Handles reconnection, thread safety, and clean shutdown.
  1. Create a Gradle Paper 26.2 plugin scaffold and default WebSocket/token configuration.

  2. Implement authenticated async WebSocket connection, reconnect, and JSON frame handling.

  3. Forward player chat and safely broadcast Discord chat; add setup/network documentation.

Created the Paper 26.2 chat bridge with Gradle setup, default WebSocket/token configuration, authenticated JSON framing, asynchronous reconnects, and shutdown cleanup. Player messages are forwarded as plain text; authenticated Discord messages are broadcast on the Bukkit main thread as (<username>) > <message> without being echoed back.

Setup and protocol details are in README.md. Set websocket.bridge-token to the same secret as the bot’s BRIDGE_TOKEN, and ensure the bot host is reachable from the Paper server.

Small formatting correction to the completed Paper bridge: the user's requested output for Discord-originated messages in Minecraft is explicitly Discord (username) > message, while Minecraft-originated messages remain (username) > message in Discord. Currently ChatBridgePlugin.receiveDiscordChat formats only (username) > message. Change only the Discord-to-Minecraft display prefix to Discord ( + username + ) > + message. Keep the JSON protocol unchanged, preserve player-only chat forwarding/no echo, and update README wording/examples to match if needed. Read current relevant files first. Do not build; report the files changed.

Kodari AI
KodariSep 29 at 7:52 pm 1

Updated the Discord-to-Minecraft display prefix to Discord (<username>) > <message> and clarified the direction-specific formats in the README. JSON protocol and player-chat forwarding are unchanged.

Files changed: ChatBridgePlugin.java, README.md.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
README.md
settings.gradle
Code
7 462
src/main/java/com/kodari/chatbridge/ChatBridgePlugin.java
package com.kodari.chatbridge;

import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;

import java.net.URI;
import java.time.Duration;
import java.util.Locale;
import java.util.logging.Level;

public final class ChatBridgePlugin extends JavaPlugin implements Listener {
    private BridgeWebSocketClient bridgeClient;

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

        String configuredUrl = getConfig().getString("websocket.url", "ws://127.0.0.1:8765");
        String token = getConfig().getString("websocket.bridge-token", "");
        int reconnectSeconds = getConfig().getInt("websocket.reconnect-delay-seconds", 5);

        URI uri;
        try {
            uri = URI.create(configuredUrl == null ? "" : configuredUrl.trim());
            String scheme = uri.getScheme();
            if (scheme == null || !(scheme.toLowerCase(Locale.ROOT).equals("ws")
                    || scheme.toLowerCase(Locale.ROOT).equals("wss")) || uri.getHost() == null) {
                throw new IllegalArgumentException("URL must be a valid ws:// or wss:// URL");
            }
        } catch (IllegalArgumentException exception) {
            getLogger().log(Level.SEVERE, "Invalid websocket.url: " + exception.getMessage());
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        if (token == null || token.isBlank() || token.equals("CHANGE_ME")) {
            getLogger().severe("Set websocket.bridge-token to the same non-empty secret used by the Discord bot.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        reconnectSeconds = Math.max(1, Math.min(reconnectSeconds, 300));
        bridgeClient = new BridgeWebSocketClient(
                uri,
                token,
                Duration.ofSeconds(reconnectSeconds),
                this::receiveDiscordChat,
                getLogger()
        );
        getServer().getPluginManager().registerEvents(this, this);
        bridgeClient.start();
    }

    @EventHandler(ignoreCancelled = true)
    public void onPlayerChat(AsyncChatEvent event) {
        BridgeWebSocketClient client = bridgeClient;
        if (client == null) {
            return;
        }

        String plainMessage = PlainTextComponentSerializer.plainText().serialize(event.message());
        client.sendMinecraftChat(event.getPlayer().getName(), plainMessage);
    }

    private void receiveDiscordChat(String username, String message) {
        if (!isEnabled()) {
            return;
        }

        String line = "Discord (" + username + ") > " + message;
        try {
            getServer().getScheduler().runTask(this, () -> {
                if (!isEnabled()) {
                    return;
                }
                Component component = Component.text(line);
                for (Player player : Bukkit.getOnlinePlayers()) {
                    player.sendMessage(component);
                }
            });
        } catch (IllegalStateException ignored) {
            // The server is shutting down and no further broadcast can be scheduled.
        }
    }

    @Override
    public void onDisable() {
        if (bridgeClient != null) {
            bridgeClient.stop();
            bridgeClient = null;
        }
    }
}