N
📎 1 file 1,911 chars
📄
pasted-code-1772278384143.txt
txt 37 lines
▶
Generate a Discord plugin named "FastVeloCord" that reads Minecraft Bungee/Velocity server player counts and updates a Discord channel and embeds.   
  
Requirements:  
  
1. Configuration file: FastVeloCord/config.yml  
  
Content of config.yml should include:  
  
#------- Placeholder---------  
# {ProxyPlayerCount} - Bungee/Velocity server's total player count  
# {PlayerCount} - Replace  with your backend server name from velocity.toml/config.yml  
  
BotToken: "Your-BotToken"  
  
playercount-channel-id: "00000000"   # replace 00000000 with your Discord channel ID  
playercount-channel-name: "🎮•Playing: {ProxyPlayerCount}"  
  
playercount-channel-update-interval: "480"   # in seconds (minimum 480 = 8 minutes)  
  
PlayerlistEmbedFooter: "powered by FastVeloCord"  
  
2. Features of the plugin:  
  
- Every configured interval (e.g., 480 seconds), update the Discord channel name with total player count using {ProxyPlayerCount}.  
- Generate a Discord embed message showing:  
  - Title: "🎮 Total Players: {ProxyPlayerCount}"  
  - Description: For each backend server (from velocity.toml), show:  
    - "** ({ServerPlayerCount}):** `Player1`, `Player2`, `Player3`"  
  - If a backend server has 0 players, skip that line.  
  - If no players online at all, description should be: "**There are no players online.**"  
- Footer: Configurable via PlayerlistEmbedFooter.  
- Should work for any Bungee/Velocity server with proper player counts from the server.  
- Embed style and player list layout should follow the current format exactly, with player names separated by commas.  
- All functionality must use the configuration placeholders provided.  
- Provide a ready-to-use Discord bot integration inside the plugin that reads from config.yml for token, channel ID, and update interval.  
  
and discription er Backend ServerPlayerCount jeno work kore
Kodari AI
KodariFeb 28 at 11:34 am 9,483 (v2)
FastVeloCord
A Velocity proxy plugin that integrates with Discord via JDA to display real-time Minecraft server player counts. Automatically updates a Discord channel name with total proxy player count and posts/edits an embed showing per-backend-server player lists. Configurable update interval, channel ID, bot token, and embed footer. Supports {ProxyPlayerCount} and {ServerName}PlayerCount placeholders across all backend servers defined in velocity.toml.

I’ll create a Velocity proxy plugin with JDA integration. Here’s my plan:

  • Velocity main plugin class with @Plugin + @Inject

  • ConfigManager to read config.yml

  • DiscordManager to handle JDA login, channel name updates, and embed posting/editing

  • PlayerCountTask as the scheduled repeating task

  • Data file to persist the last embed message ID for editing

  • manifest.kod for JDA, build.gradle, velocity-plugin.json, and config.yml


Here’s a summary of everything created:

Files Created:

File
Purpose
manifest.kod
Declares JDA as a runtime dependency
build.gradle
Velocity build config
velocity-plugin.json
Velocity plugin metadata
config.yml
Bot token, channel ID, interval, footer
FastVeloCord.java
Main plugin class, initializes everything and schedules the task
ConfigManager.java
Reads and parses
config.yml
using SnakeYAML
DataStorage.java
Persists the embed message ID so it edits the same message every time instead of spamming new ones
DiscordManager.java
JDA connection, channel name updates, and embed send/edit logic
PlayerCountTask.java
The repeating task — builds embed description per backend server and triggers Discord updates

How It Works:

  1. On startup, config is loaded and JDA connects with the bot token

  2. Every N seconds (min 480), the task fires:

    • Channel name is updated to playercount-channel-name with {ProxyPlayerCount} replaced

    • Embed is built — each backend server with players gets a line like **Survival (3):** \Player1, Player2, Player3``

    • If all servers are empty → **There are no players online.**

    • The embed is edited in-place (not a new message each time) — the message ID is saved in data.properties

  3. On shutdown, JDA disconnects cleanly

Setup Steps:

  1. Put the jar in your Velocity plugins/ folder

  2. Start once to generate plugins/FastVeloCord/config.yml

  3. Fill in BotToken, playercount-channel-id, and your desired channel name template

  4. Restart Velocity — the bot will connect and begin updating

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

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.entities.Message;
import org.slf4j.Logger;

import java.awt.Color;
import java.time.Instant;

public class DiscordManager {

    private final FastVeloCord plugin;
    private final Logger logger;
    private JDA jda;

    public DiscordManager(FastVeloCord plugin, Logger logger) {
        this.plugin = plugin;
        this.logger = logger;
    }

    public boolean connect() {
        try {
            String token = plugin.getConfigManager().getBotToken();
            jda = JDABuilder.createDefault(token)
                    .enableIntents(GatewayIntent.GUILD_MEMBERS)
                    .build();
            jda.awaitReady();
            logger.info("Connected to Discord as: " + jda.getSelfUser().getAsTag());
            return true;
        } catch (Exception e) {
            logger.error("Failed to connect to Discord: " + e.getMessage());
            return false;
        }
    }

    public void shutdown() {
        if (jda != null) {
            jda.shutdown();
        }
    }

    public void updateChannelName(String channelId, String newName) {
        if (jda == null) return;
        try {
            GuildChannel channel = jda.getGuildChannelById(channelId);
            if (channel == null) {
                logger.warn("Could not find channel with ID: " + channelId);
                return;
            }
            channel.getManager().setName(newName).queue(
                    success -> logger.info("Updated channel name to: " + newName),
                    error -> logger.warn("Failed to update channel name: " + error.getMessage())
            );
        } catch (Exception e) {
            logger.warn("Error updating channel name: " + e.getMessage());
        }
    }

    public void updateOrPostEmbed(String channelId, MessageEmbed embed) {
        if (jda == null) return;
        try {
            TextChannel channel = jda.getTextChannelById(channelId);
            if (channel == null) {
                logger.warn("Could not find text channel with ID: " + channelId + ". Make sure the playercount channel is a text channel for embed support.");
                return;
            }

            String savedMessageId = plugin.getDataStorage().getEmbedMessageId();

            if (savedMessageId != null) {
                channel.retrieveMessageById(savedMessageId).queue(
                        message -> {
                            message.editMessageEmbeds(embed).queue(
                                    success -> logger.info("Edited existing embed message."),
                                    error -> sendNewEmbed(channel, embed)
                            );
                        },
                        error -> sendNewEmbed(channel, embed)
                );
            } else {
                sendNewEmbed(channel, embed);
            }
        } catch (Exception e) {
            logger.warn("Error updating embed: " + e.getMessage());
        }
    }

    private void sendNewEmbed(TextChannel channel, MessageEmbed embed) {
        channel.sendMessageEmbeds(embed).queue(
                message -> {
                    plugin.getDataStorage().setEmbedMessageId(message.getId());
                    logger.info("Sent new embed message with ID: " + message.getId());
                },
                error -> logger.warn("Failed to send embed: " + error.getMessage())
        );
    }

    public MessageEmbed buildPlayerListEmbed(String title, String description, String footer, Color color) {
        EmbedBuilder builder = new EmbedBuilder();
        builder.setTitle(title);
        builder.setDescription(description);
        builder.setFooter(footer);
        builder.setColor(color);
        builder.setTimestamp(Instant.now());
        return builder.build();
    }
}