Marjan Khan
📎 1 file 4,963 chars
📄
pasted-code-1793539007947.txt
txt 79 lines
▶
Build a Paper 1.21.11 plugin called EclipseBridge in Java that connects the Minecraft server to a Discord channel. Use Maven, Java 21, and JDA (Java Discord API) for the Discord connection. Deliver the complete source code, a pom.xml, a plugin.yml, a config.yml, and install instructions.

GOAL
Players and Discord members should see each other's messages, and join, leave, and death events should appear in Discord automatically.

REQUIRED FEATURES

1. Minecraft chat → Discord
- Send every player chat message to a configured Discord channel.
- Show the player's name and rank in the Discord embed (author name, e.g. "[Owner] Fizz4r").
- Use a clean embed: player avatar (https://mc-heads.net/avatar//64 or similar), message text, and a footer with the server name.
- Strip Minecraft color codes and disable Discord mention pings in the message (sanitize @everyone, @here, and role mentions).

2. Discord → Minecraft chat
- Forward messages from the configured Discord chat channel to all online players.
- Format: "[DISCORD]  : " using a configurable format string in config.yml.
- The Discord name should show the member's highest server role, if they have one, using the role name.
- Ignore messages from bots, including this bot.
- Ignore messages that start with a configurable command prefix (default "!") so commands don't leak into chat.
- Strip or escape Minecraft color codes (§ and &) typed by Discord users so they can't fake formatting.
- Truncate messages to a configurable max length (default 256).

3. Rank display
- Rank comes from a configurable source. Support at least these:
  a. "permission" mode: map each rank to a permission node. The plugin checks the player's permissions in order from highest to lowest and shows the first match.
  b. "static" mode: a rank list in config.yml keyed by player UUID, for servers without a permissions plugin.
- Rank prefixes, colors, and display names are all configurable in config.yml.
- Do not require LuckPerms. If LuckPerms is present, the plugin may read it as an optional source, but it must still work without it.

4. Join, leave, and death notifications
- Send join and leave messages to a configured Discord channel (can be the same as chat or separate).
- Send death messages with the death cause, using Paper's death message as the text.
- Show first-time joins in a different color or title, if enabled.
- Each event type can be turned on or off in config.yml.
- Send join/leave/death messages to Minecraft chat too, optionally, using the same format as Discord.

5. Loop prevention
- Never relay a message back to its origin. A Discord message forwarded to Minecraft must not be picked up again and sent back to Discord.
- Use a flag or a message tag so the bridge recognizes its own messages.

CONFIGURATION (config.yml)
- discord.token: bot token (empty by default; never log this value)
- discord.guild-id
- discord.chat-channel-id
- discord.events-channel-id (join, leave, death)
- discord.enabled (true/false for the whole bridge)
- formats for each message type
- toggles for each event type
- rank source mode and rank definitions
- command prefix to ignore, max message length
- minecraft-to-discord and discord-to-minecraft enable/disable flags

ARCHITECTURE
- Keep Bukkit API calls on the main server thread. Discord API calls must run asynchronously so they never block the server tick.
- Queue outgoing Discord messages and send them with a short batching delay (or sequentially) to respect Discord rate limits.
- Handle JDA disconnects with automatic reconnection and a logged warning.
- Shut down the bot cleanly when the plugin disables.
- Validate the config on startup. If the token or channel IDs are missing or invalid, log a clear error and disable the bridge without crashing the server.

SECURITY
- Never log the bot token.
- Do not allow Discord users to run Minecraft commands through the bridge.
- Sanitize all text in both directions, including the mention filter and color-code stripping.
- Use the Message Content intent only for the chat channel, and explain in the install notes how to enable it in the Discord Developer Portal.

COMMANDS
- /eclipsebridge reload (op only): reload config and reconnect the bot
- /eclipsebridge status (op only): show connection state and channel IDs
- Permission: eclipsebridge.admin, default op

TESTING
- Include a test checklist in the README: chat both ways, join, leave, death, first-time join, rank display, mention filtering, color-code stripping, bot restart, and reconnect after a network drop.

DELIVERABLES
- Full source tree with all Java files
- pom.xml, plugin.xml/plugin.yml, config.yml
- README with setup steps, Discord bot creation steps, required permissions and intents, and the test checklist

Do not leave placeholder methods or TODO comments. Every feature listed above must be implemented.
Kodari AI
KodariNov 1 at 1:31 pm 3
EclipseBridge
EclipseBridge is a Paper 1.21.11 Minecraft plugin that seamlessly connects server chat to a Discord channel using JDA. It relays Minecraft messages to Discord embeds with player avatars and ranks, forwards Discord messages to in-game chat with configurable formatting, and sends join, leave, and death notifications to both platforms. Features include rank display via permission or static configuration, bidirectional sanitization preventing mention pings and color-code injection, loop prevention through message tagging, asynchronous Discord operations with rate-limit batching, automatic reconnection handling, and admin commands for reload and status. Config validation ensures safe startup without crashing.
  1. Set up the Maven/Paper 1.21.11 project, configuration, plugin metadata, and setup/test README.

  2. Implement the Discord bridge, safe message formatting, rank lookup, event relays, and admin commands.

  3. Wire startup validation, async Discord handling, reload/reconnect, and clean shutdown.

Implemented EclipseBridge as a Java 21 Maven plugin for Paper 1.21.11. The project includes the source files, pom.xml, plugin.yml, config.yml, manifest.kod, and a README with setup and test instructions.

The bridge relays chat in both directions, displays Minecraft ranks and Discord roles, handles join/leave/death and first-join messages, and includes sanitization, message limits, loop prevention, queued Discord sends, configuration validation, reconnect warnings, and /eclipsebridge reload|status. Configure the Discord token and IDs in config.yml before starting the server.

Marjan Khan

The compilation failed with this error:

code
Compilation failed with 2 error(s):

ERROR in src/main/java/com/kodari/eclipsebridge/DiscordBridge.java at line 43: cannot find symbol
                    .enableIntents(GatewayIntent.GUILDS, GatewayIntent.GUILD_MESSAGES, GatewayIntent.MESSAGE_CONTENT)
                                                ^
  symbol: variable GUILDS
  location: class GatewayIntent

ERROR in src/main/java/com/kodari/eclipsebridge/DiscordBridge.java at line 238: onEvent(GenericEvent) in DiscordBridge.BridgeEvents cannot override onEvent(GenericEvent) in ListenerAdapter
        public void onEvent(GenericEvent event) {
                    ^


=== COMPILATION ERROR ANALYSIS ===

FILES TO INVESTIGATE:
  - src/main/java/com/kodari/eclipsebridge/DiscordBridge.java

Please fix this error by creating a new artifact with the corrected code.

Kodari AI
KodariNov 1 at 1:33 pm 1

Fixed DiscordBridge.java: removed the unsupported GatewayIntent.GUILDS constant and replaced the invalid onEvent(GenericEvent) override with JDA’s onStatusChange(StatusChangeEvent) callback. Also made the sanitized message effectively final for use in async callbacks.

Marjan Khan
📎 1 file 11,073 chars
📄
pasted-code-1793543455252.txt
txt 193 lines
▶
Build a complete upgrade to EclipseBridge, a Paper 1.21.11 plugin in Java 21 that bridges Minecraft and Discord with JDA. It also adds a built-in /team system, a preset team color palette, and rank display on the tab list, chat, and nametags. This is a full rewrite of the presentation and team layers. Keep the working bot connection and the way the token and channel IDs are read, and keep the existing config keys working.

ENVIRONMENT
- Paper 1.21.11, Java 21, Maven, JDA (Discord API), SQLite for storage.
- Plugin name: EclipseBridge. Main class: com.kodari.eclipsebridge.EclipseBridgePlugin.
- The server is "Eclipse SMP". Discord guild ID 1496778033661607936, chat and events channel ID 1533067902729851001. Keep these in config.yml, not hard-coded.
- The bot token is read only from config.yml and is never logged, printed, or sent in any message.

============================================================
PART 1: CONNECTION AND SAFETY
============================================================
- Connect to Discord on enable, reconnect automatically after drops, and shut down cleanly on disable.
- If the token or IDs are missing or invalid, log one clear error and disable the Discord side without crashing the server. Keep Minecraft-only features (teams, ranks, nametags) working.
- Use the Message Content Intent for chat only. Explain in the README how to turn it on in the Developer Portal.
- Run Discord calls off the main thread. Make all Bukkit and scoreboard changes on the main thread.
- Rate-limit outgoing Discord messages with a small queue.
- Prevent message loops: messages the bot sends are never relayed back.
- Discord users cannot run Minecraft commands through the bridge.

============================================================
PART 2: DISCORD → MINECRAFT CHAT
============================================================
Each Discord message gets a tag based on the sender, checked in this order:
1. Guild owner → [OWNER]. Read the owner ID from the guild, not from config.
2. Has any role in discord-roles.senior-admin (list of role IDs in config) → [SR ADMIN]
3. Has any role in discord-roles.admin → [ADMIN]
4. Has any role in discord-roles.moderator → [MOD]
5. Everyone else → [DISCORD]

Read roles from the message's member object so it works without the member cache. Ignore bot messages, messages starting with the command prefix (default "!"), and empty messages.

In-game format, like normal Minecraft chat, one line:
    » 
- The tag uses its configured color. The name is bold white. The message is plain white.
- Strip § and & color codes typed by Discord users. Truncate to max-message-length (default 256).
- Keep the colors, tags, and separator in config.yml so they can change without a rebuild.

============================================================
PART 3: MINECRAFT → DISCORD
============================================================
- Send player chat to the chat channel as an embed:
  - Author line: "[Team] [Rank] Name" (team and rank parts shown only when they apply), with the player's avatar from server.avatar-url, where {player} is replaced by the name.
  - Accent bar in the rank color (or the team's nearest color if on a team).
  - Description: the message text, with color codes stripped.
  - Footer: server name (server.name) and a timestamp.
- Prefix the message with [MINECRAFT] in the Discord author line for clarity when needed, for example "[MINECRAFT] Fizz4r".
- Sanitize @everyone, @here, and role mentions so they can't ping.
- Join, leave, and death use their own small embeds, not chat-style embeds:
  - Join: green accent, "Fizz4r joined the server".
  - First join: gold accent, "Fizz4r joined for the first time".
  - Leave: gray accent, "Fizz4r left the server".
  - Death: red accent, Paper's death message text.
- Each event type can be turned on or off in config.yml.

============================================================
PART 4: IN-GAME EVENTS
============================================================
- Join: "+ Name joined" in green.
- Leave: "- Name left" in gray.
- Death: Paper's death message in red.
- Show these in chat only if the event toggles in config.yml are on.

============================================================
PART 5: RANKS
============================================================
Five ranks, checked highest first, first permission match wins:
  owner (eclipsebridge.rank.owner)
  senior-admin (eclipsebridge.rank.senior-admin)
  admin (eclipsebridge.rank.admin)
  moderator (eclipsebridge.rank.moderator)
  member (eclipsebridge.rank.member)

Defaults in config.yml, all editable without a rebuild:
- owner: prefix "[Owner] ", color &4 (dark red)
- senior-admin: prefix "[Sr Admin] ", color &5 (purple)
- admin: prefix "[Admin] ", color &c (red)
- moderator: prefix "[Mod] ", color &a (green)
- member: prefix "[Member] ", color &7 (gray)

Support a static rank mode too, keyed by player UUID, for servers without a permissions plugin. Do not require LuckPerms.

============================================================
PART 6: TEAMS (/team)
============================================================
Command: /team with these subcommands only. Do not add any gameplay changes such as friendly fire, team chat, teleports, or shared inventory.
- /team create  — creates a team. The creator becomes leader. Team names are 1–16 characters, letters, numbers, and spaces.
- /team delete — leader only. Removes the team and all members.
- /team invite  — leader only. Sends a clickable invite that expires after 60 seconds (configurable).
- /team accept — accepts the pending invite.
- /team kick  — leader only. Removes a member.
- /team leave — removes yourself. A leader must delete the team or transfer leadership first.
- /team info [team] — shows the team name, color name and hex, leader, and members. With no name, shows your own team.
- /team color  — leader only. Sets a preset color. Tab-complete the names. Reject unknown names and list the valid ones.
- Admin override: /team admin delete  and /team admin kick , requiring eclipsebridge.team.admin (default op).

Limits in config.yml: max team name length 16, max members 8, invite timeout 60 seconds.

Storage: SQLite at plugins/EclipseBridge/teams.db. Save on every change, load on start, and handle players who go offline and come back.

Permissions: eclipsebridge.team (default true), eclipsebridge.team.admin (default op).

============================================================
PART 7: TEAM COLOR PALETTE
============================================================
Store these 20 presets in config.yml under team-colors as name and hex pairs. Validate on load: skip malformed hex entries and log one warning.

1. Crimson #DC143C
2. Scarlet #FF2400
3. Orange #FF8C00
4. Amber #FFBF00
5. Gold #FFD700
6. Lime #A3E635
7. Green #22C55E
8. Emerald #10B981
9. Teal #14B8A6
10. Aqua #22D3EE
11. Sky #38BDF8
12. Blue #3B82F6
13. Royal Blue #1D4ED8
14. Indigo #6366F1
15. Violet #8B5CF6
16. Purple #A855F7
17. Magenta #D946EF
18. Pink #EC4899
19. Rose #F43F5E
20. White #F8FAFC

When a team is created, give it a random unused preset. If all 20 are in use, reuse the first one.

============================================================
PART 8: TAB LIST, NAMETAGS, AND CHAT ORDER
============================================================
Tab list:
- Use setPlayerListName with an Adventure component, so the team's exact hex color shows.
- Format: "[Team] [Rank] Name", with the team in its exact hex color and the rank in its rank color. Show only the parts that apply.
- Update when a player joins, leaves, changes rank, or changes team.

Nametags:
- Use a scoreboard team per player (under 16 characters, unique, for example "rk_owner" or "tm_"), with the color set to the nearest vanilla color.
- Team color has priority over rank color. A player on a team uses the team's nearest vanilla color. A player with no team uses the rank color.
- Store the vanilla mapping in config.yml:
  - Crimson, Scarlet → dark_red
  - Orange, Amber, Gold → gold
  - Lime, Green → green
  - Emerald, Teal → dark_aqua
  - Aqua, Sky → aqua
  - Blue, Royal Blue, Indigo → blue
  - Violet, Purple, Magenta → light_purple
  - Pink, Rose → red
  - White → white
  - Ranks: owner → dark_red, senior-admin → dark_purple, admin → red, moderator → green, member → gray
- Remove players from the old scoreboard team when their rank or team changes, and clear all of them on disable.
- If another plugin already controls a player's scoreboard, log one warning and skip that player.

In-game chat order: [Team] [Rank] Name » message, with the team in its exact hex color and the rank in its rank color.

Discord embed author line: "[Team] [Rank] Name".

============================================================
PART 9: CONFIG (config.yml)
============================================================
Include all keys from above with comments:
- discord: token, guild-id, chat-channel-id, events-channel-id, enabled, command-prefix, max-message-length, minecraft-to-discord, discord-to-minecraft
- discord-roles: senior-admin, admin, moderator (lists of role IDs, empty by default)
- server: name, avatar-url
- formats: discord-to-minecraft, minecraft-to-discord, and the team and rank formats
- events: each toggle and format, including first-join, leave, death
- ranks: source (permission or static), permission-order, definitions, static-players
- teams: max-name-length, max-members, invite-timeout-seconds
- team-colors: the 20 presets
- nametag-vanilla-map: the vanilla color mapping above

Missing keys fall back to defaults with one warning, never an error.

============================================================
PART 10: DELIVERABLES
============================================================
- Complete Java source for every class, with no placeholders or TODO comments.
- pom.xml, plugin.yml (including /team), config.yml with comments.
- README with: Discord bot creation, Developer Portal steps (Message Content Intent), how to get role IDs, how to change colors and formats, and the team commands.
- A test checklist covering:
  - Discord → Minecraft for owner, senior-admin, admin, moderator, and member
  - Minecraft → Discord embed, including [MINECRAFT] in the author line
  - Join, first join, leave, and death in both places
  - Ranks on tab, chat, and nametags, including a player with no rank and no team
  - Team create, invite, accept, kick, leave, delete, info, and color
  - All 20 team colors on tab and chat
  - Team color overriding rank color on nametags
  - Scoreboard teams cleaned up on leave and disable
  - Bot disconnect and reconnect
  - Invalid token: clean error, no crash

Every feature must be fully implemented and checked by reading the full code path end to end.
Kodari AI
KodariNov 1 at 2:57 pm 6
  1. Inspect the existing bridge/config and project setup to preserve the working Discord connection and existing keys.

  2. Implement the team system with SQLite persistence, commands, invites, and color presets.

  3. Add rank/chat/tab/nametag presentation, events, documentation, and verify the integrated code paths.Task 1: the project already has the Maven/JDA lifecycle and Discord relay; I’ll preserve those connection and config paths while extending the plugin. Next I’m implementing the team storage and command layer.

Task 2: the /team commands, SQLite persistence, expiring clickable invites, admin overrides, configurable limits, and 20-color palette are in place. I’m now integrating ranks and teams into chat, tab names, nametags, Discord embeds, and event notices.

Task 3: integrated the priority rank lookup, team/rank chat and tab formatting, scoreboard nametags, Discord chat embeds, and distinct event embeds. I’m finishing the permission metadata and setup/test documentation next.

Implemented the EclipseBridge upgrade with persistent SQLite-backed teams, clickable invites, admin overrides, configurable color presets, and team/rank presentation in chat, the tab list, and nametags. The Discord bridge now uses the requested role-tag priority, embeds, event notifications, sanitization, and connection/config failure handling.

Updated the Maven dependencies, plugin.yml, and config.yml; the README includes Discord setup, permissions, team commands, and the requested test checklist.

Kodari can make mistakes. Review important code before using.
Files
src
manifest.kod
pom.xml
README.md
Code
12 2,069
src/main/java/com/kodari/eclipsebridge/EclipseBridgePlugin.java
package com.kodari.eclipsebridge;

import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scoreboard.Scoreboard;

import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;

public final class EclipseBridgePlugin extends JavaPlugin implements Listener {
    private static final LegacyComponentSerializer LEGACY = LegacyComponentSerializer.legacyAmpersand();
    private static final List<String> CONFIG_KEYS = List.of(
            "discord.enabled", "discord.token", "discord.guild-id", "discord.chat-channel-id", "discord.events-channel-id",
            "discord.minecraft-to-discord", "discord.discord-to-minecraft", "discord.command-prefix", "discord.max-message-length",
            "discord-roles.senior-admin", "discord-roles.admin", "discord-roles.moderator",
            "discord-tags.owner.text", "discord-tags.owner.color", "discord-tags.senior-admin.text", "discord-tags.senior-admin.color",
            "discord-tags.admin.text", "discord-tags.admin.color", "discord-tags.moderator.text", "discord-tags.moderator.color",
            "discord-tags.member.text", "discord-tags.member.color",
            "server.name", "server.avatar-url", "formats.discord-to-minecraft", "formats.minecraft-to-discord",
            "formats.team-prefix", "formats.rank-prefix", "formats.chat-separator", "events.joins-enabled", "events.leaves-enabled",
            "events.deaths-enabled", "events.first-join-enabled", "events.minecraft-chat-enabled", "ranks.source",
            "events.join-format", "events.first-join-format", "events.leave-format", "events.death-format", "events.minecraft-format",
            "events.minecraft-join-format", "events.minecraft-first-join-format", "events.minecraft-leave-format",
            "events.minecraft-death-format", "events.embed-colors.join", "events.embed-colors.first-join",
            "events.embed-colors.leave", "events.embed-colors.death",
            "ranks.permission-order", "ranks.static-players", "teams.max-name-length", "teams.max-members",
            "ranks.definitions.owner.permission", "ranks.definitions.owner.prefix", "ranks.definitions.owner.color",
            "ranks.definitions.senior-admin.permission", "ranks.definitions.senior-admin.prefix", "ranks.definitions.senior-admin.color",
            "ranks.definitions.admin.permission", "ranks.definitions.admin.prefix", "ranks.definitions.admin.color",
            "ranks.definitions.moderator.permission", "ranks.definitions.moderator.prefix", "ranks.definitions.moderator.color",
            "ranks.definitions.member.permission", "ranks.definitions.member.prefix", "ranks.definitions.member.color",
            "ranks.definitions.owner.display-name", "ranks.definitions.senior-admin.display-name",
            "ranks.definitions.admin.display-name", "ranks.definitions.moderator.display-name", "ranks.definitions.member.display-name",
            "teams.invite-timeout-seconds", "team-colors.Crimson", "team-colors.Scarlet", "team-colors.Orange",
            "team-colors.Amber", "team-colors.Gold", "team-colors.Lime", "team-colors.Green", "team-colors.Emerald",
            "team-colors.Teal", "team-colors.Aqua", "team-colors.Sky", "team-colors.Blue", "team-colors.Royal Blue",
            "team-colors.Indigo", "team-colors.Violet", "team-colors.Purple", "team-colors.Magenta", "team-colors.Pink",
            "team-colors.Rose", "team-colors.White",
            "nametag-vanilla-map.team.Crimson", "nametag-vanilla-map.team.Scarlet", "nametag-vanilla-map.team.Orange",
            "nametag-vanilla-map.team.Amber", "nametag-vanilla-map.team.Gold", "nametag-vanilla-map.team.Lime",
            "nametag-vanilla-map.team.Green", "nametag-vanilla-map.team.Emerald", "nametag-vanilla-map.team.Teal",
            "nametag-vanilla-map.team.Aqua", "nametag-vanilla-map.team.Sky", "nametag-vanilla-map.team.Blue",
            "nametag-vanilla-map.team.Royal Blue", "nametag-vanilla-map.team.Indigo", "nametag-vanilla-map.team.Violet",
            "nametag-vanilla-map.team.Purple", "nametag-vanilla-map.team.Magenta", "nametag-vanilla-map.team.Pink",
            "nametag-vanilla-map.team.Rose", "nametag-vanilla-map.team.White",
            "nametag-vanilla-map.ranks.owner", "nametag-vanilla-map.ranks.senior-admin", "nametag-vanilla-map.ranks.admin",
            "nametag-vanilla-map.ranks.moderator", "nametag-vanilla-map.ranks.member");

    private volatile BridgeSettings settings;
    private RankManager rankManager;
    private DiscordBridge discordBridge;
    private TeamManager teamManager;
    private BukkitTask presentationTask;
    private final Map<UUID, String> nametagTeams = new HashMap<>();
    private boolean nametagWarningLogged;
    private boolean missingConfigWarningLogged;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        rankManager = new RankManager(this);
        discordBridge = new DiscordBridge(this);
        teamManager = new TeamManager(this);
        teamManager.load();
        getServer().getPluginManager().registerEvents(this, this);
        if (getCommand("eclipsebridge") != null) {
            getCommand("eclipsebridge").setExecutor(new BridgeCommand(this));
        }
        if (getCommand("team") != null) {
            TeamCommand teamCommand = new TeamCommand(this, teamManager);
            getCommand("team").setExecutor(teamCommand);
            getCommand("team").setTabCompleter(teamCommand);
        }
        presentationTask = Bukkit.getScheduler().runTaskTimer(this, this::refreshPresentations, 20L, 40L);
        reloadBridge();
    }

    @Override
    public void onDisable() {
        if (presentationTask != null) {
            presentationTask.cancel();
        }
        clearAllNametagTeams();
        if (discordBridge != null) {
            discordBridge.stop();
        }
        if (teamManager != null) {
            teamManager.close();
        }
    }

    public void reloadBridge() {
        reloadConfig();
        warnMissingConfigDefaults();
        if (teamManager != null) {
            teamManager.reloadColors();
        }
        settings = BridgeSettings.load(this);
        discordBridge.stop();
        refreshPresentations();

        if (!settings.enabled()) {
            getLogger().info("Discord bridge is disabled in config.yml.");
            return;
        }

        List<String> errors = settings.validate();
        if (!errors.isEmpty()) {
            getLogger().severe("Discord bridge disabled because its connection configuration is invalid: "
                    + String.join(" ", errors) + " The bot token was not logged.");
            return;
        }

        discordBridge.start(settings);
    }

    private void warnMissingConfigDefaults() {
        if (missingConfigWarningLogged) {
            return;
        }
        List<String> missing = CONFIG_KEYS.stream().filter(key -> !getConfig().contains(key)).toList();
        if (!missing.isEmpty()) {
            missingConfigWarningLogged = true;
            getLogger().warning("Missing config.yml keys are using built-in defaults: " + String.join(", ", missing));
        }
    }

    public String getBridgeStatus() {
        return discordBridge.getStatus();
    }

    public BridgeSettings getSettings() {
        return settings;
    }

    public TeamManager getTeamManager() {
        return teamManager;
    }

    public RankManager getRankManager() {
        return rankManager;
    }

    public void refreshPresentations() {
        if (!Bukkit.isPrimaryThread()) {
            Bukkit.getScheduler().runTask(this, this::refreshPresentations);
            return;
        }
        for (Player player : Bukkit.getOnlinePlayers()) {
            updatePresentation(player);
        }
    }

    private void updatePresentation(Player player) {
        player.playerListName(buildIdentity(player));
        updateNametag(player);
    }

    private Component buildIdentity(Player player) {
        Component identity = Component.empty();
        TeamManager.Team team = teamManager.getTeam(player.getUniqueId());
        if (team != null) {
            String prefix = getConfig().getString("formats.team-prefix", "[{team}] ").replace("{team}", team.name());
            TextColor color = TextColor.fromHexString(team.colorHex());
            identity = identity.append(LEGACY.deserialize(prefix).color(color == null ? NamedTextColor.WHITE : color));
        }

        RankManager.Rank rank = rankManager.getRank(player);
        if (rank != null) {
            String prefixFormat = getConfig().getString("formats.rank-prefix", "{prefix}");
            String prefix = prefixFormat.replace("{prefix}", rank.prefix());
            identity = identity.append(LEGACY.deserialize(rank.color() + prefix));
        }
        return identity.append(Component.text(player.getName(), NamedTextColor.WHITE).decorate(TextDecoration.BOLD));
    }

    private Component buildChatLine(Player player, String message) {
        String separator = getConfig().getString("formats.chat-separator", "&7 » ");
        return buildIdentity(player)
                .append(LEGACY.deserialize(separator))