kuma077114
📎 1 file 2,087 chars
📄
pasted-code-1777866736437.txt
txt 23 lines
▶
Role: You are a Senior Software Engineer specializing in Minecraft Plugin Development and Discord JDA integrations. Your goal is to write a bridge addon named BanAnnouncerButtonAddon, authored by Niloy.
​Objective: Create a bridge between BanAnnouncer (me.tini.announcer) and Spicord (org.spicord). The core functionality is to add Discord Button support to BanAnnouncer's existing JSON embed system. The addon must read custom button data directly from the .json files located in plugins/BanAnnouncer/embeds/.
​Technical Requirements:
​Plugin Identification:
​Plugin Name: BanAnnouncerButtonAddon
​Author: Niloy
​Spicord Addon ID: niloy.banbuttons
​Logic for Button Support in JSON:
​The addon must monitor or hook into BanAnnouncer's punishment pipeline.
​When a punishment occurs, locate the corresponding JSON file (e.g., ban.json, mute.json, warn.json) in the plugins/BanAnnouncer/embeds/ folder.
​Parse a root-level JSON array named "buttons" from that file.
​Button Data to Support: label, url, emoji (Unicode or ID), and style (default to LINK if not specified).
​Dynamic Placeholder Integration:
​All string data from the "buttons" array (especially labels and URLs) MUST be processed through announcer.processPlaceholder(info, string) to resolve placeholders like %player%, %reason%, and %staff%.
​Spicord & JDA Bridge:
​Use the Spicord API to access the active DiscordBot instance (specifically the bot named "default" from Spicord's config.toml).
​Convert BanAnnouncer's Embed object (via announcer.buildEmbed(info)) into a JDA MessageEmbed.
​Create JDA Button objects and wrap them in an ActionRow.
​Execution Flow:
​Retrieve the target channel ID from BanAnnouncer's config.yml (channel-to-announce).
​Use the Spicord bot instance to send the final message (Embed + Buttons) to that channel.
​Instructions for AI:
Please generate the complete Java source code. Focus on the AbstractExtension implementation for BanAnnouncer and the SimpleAddon implementation for Spicord. Include robust JSON parsing logic using GSON and ensure proper null-handling for the "buttons" field.
Kodari AI
KodariMay 4 at 3:58 am 14,915 (v2)

I’ll read the BanAnnouncer and Spicord documentation first before writing any code.

BanAnnouncerButtonAddon
A bridge addon between BanAnnouncer and Spicord that adds Discord Button support to BanAnnouncer's punishment announcements. Intercepts BanAnnouncer's punishment pipeline via a custom AbstractExtension, reads a "buttons" array from the corresponding embed JSON file (ban.json, mute.json, etc.), processes placeholders, and sends the embed alongside JDA ActionRow buttons to the configured Discord channel through the Spicord bot.

Plan:

  • BanAnnouncerButtonAddon — main JavaPlugin that wires BanAnnouncer extension + Spicord addon together

  • BanButtonExtension — AbstractExtension that intercepts punishment processing via processPlaceholder, deduplicates by punishment key, then fires the Discord send

  • BanButtonSpicordAddon — SimpleAddon that holds the live DiscordBot reference and exposes send(embed, buttons, channelId)

  • Button data (label, url, emoji, style) read from BanAnnouncer’s embed JSON files via Gson; all strings run through announcer.processPlaceholder

  • Channel ID read from BanAnnouncer’s own config.yml

How it works end-to-end:

  1. On enable, the plugin retrieves the BanAnnouncer API object via reflection on the BA plugin, registers BanButtonSpicordAddon with Spicord’s AddonManager, and registers BanButtonExtension with BanAnnouncer.

  2. When any punishment is announced by BanAnnouncer, it calls processPlaceholder on every registered extension for each token in the embed template. BanButtonExtension.processPlaceholder catches this, deduplicates by a punishment key (using id or a composite fallback), and schedules a 1-tick async task.

  3. The async task reads plugins/BanAnnouncer/config.yml for channel-to-announce, reads the matching embed JSON (e.g. ban.json) for the "buttons" array, runs each label/URL through announcer.processPlaceholder for placeholder resolution, calls announcer.buildEmbed(info).build() to get the MessageEmbed, and sends both to Discord via BanButtonSpicordAddon.send().

  4. The Spicord addon must be listed under the bot in Spicord’s config.toml:

    Toml
    [[bots]]
    name = "default"
    addons = ["niloy.banbuttons"]
    
  5. Example buttons block to add inside any plugins/BanAnnouncer/embeds/ban.json:

    JSON
    "buttons": [
      { "label": "Appeal %player%", "url": "https://example.com/appeal/%player%", "emoji": "⚖️", "style": "LINK" },
      { "label": "Rules", "url": "https://example.com/rules", "style": "LINK" }
    ]
    
kuma077114

add Readme.md

Kodari AI
KodariMay 4 at 4:02 am 7,394 (v2)

README.md created with full installation steps, Spicord config.toml snippet, button field reference, placeholder table, punishment-type-to-file mapping, build instructions, and an end-to-end flow diagram.

kuma077114

emon system o add daw je, button e jei user click korse tar samne akta message asbe jei message ta sudu sei dekhte pabe je button e click korse. Ei message e content, embed sob kisui dewa jabe.

Kodari AI
KodariMay 4 at 4:20 am 48,536 (v2)

Button interaction handling এর জন্য existing files পড়া দরকার।

বুঝলাম — বাটনে click করলে ephemeral reply আসবে (শুধু clicker দেখতে পাবে), JSON-এ response block এর মধ্যে content আর embed fields দেওয়া যাবে।

Plan:

  • BanButtonSpicordAddon-এ একটা Map<String, ButtonResponse> রাখব (customId → response data) এবং onReady()-এ JDA ButtonInteractionEvent listener register করব

  • Non-LINK buttons এর জন্য UUID-based customId generate করব; response data সেই map-এ store হবে

  • BanButtonExtension JSON থেকে response object parse করবে (content, embed_title, embed_description, embed_color, embed_footer, embed_thumbnail, embed_image) — সব string placeholder-processed

  • Click হলে listener ephemeral reply দেবে — LINK buttons Discord client-side handle করে, তাই interaction আসে না

Now update BanButtonExtension to parse the response block and register it:

এখন README-এ নতুন response block এর documentation যোগ করি:

Let me write the actual updated files properly:

Files already have the correct content from the updates. Now update the README with the new response system docs:

Also update the flow diagram in README to mention the interaction step:


কী কী change হলো:

BanButtonSpicordAddon

  • ButtonResponse record যোগ হলো — content (String) ও embed (MessageEmbed) নিয়ে

  • buildResponse(...) static helper যোগ হলো — embed fields থেকে MessageEmbed তৈরি করে

  • responseMap (ConcurrentHashMap<String, ButtonResponse>) যোগ হলো — customId → response

  • registerResponse(customId, response) method যোগ হলো

  • onReady() তে JDA ListenerAdapter register হলো → onButtonInteraction() এ event.deferReply(true) দিয়ে ephemeral reply পাঠায় (শুধু clicker দেখে)

BanButtonExtension

  • parseResponse() method যোগ হলো — button JSON এর response object parse করে, সব string placeholder-resolve করে

  • buildButton() এ non-LINK button এর জন্য UUID-based customId generate হয় এবং response map এ store হয়

  • LINK বাটনে response ignore হয় — কারণ Discord LINK click এ কোনো interaction event fire করে না

JSON format (button এর ভেতরে response block):

JSON
{
  "label": "How to Appeal",
  "style": "PRIMARY",
  "response": {
    "content": "Only you can see this! Ban reason: %reason%",
    "embed_title": "Appeal Info",
    "embed_description": "Submit a ticket mentioning **%player%**",
    "embed_color": "#5865F2",
    "embed_footer": "Banned by %staff%"
  }
}
kuma077114

BanAnnouncer plugin e ei file gula ase: # If the text is empty (nothing between the double quotes),

the message will not be sent (a.k.a. the message is "disabled"), for example:

#

kick: "" <-- this will disable the message

#

If you don't want to use embed messages you can use pure text, for ex.:

#

kick: "The player %player% was kicked by %staff%"

#

Variables are self-explained...

messages: kick: "{embed:kick}" note: "{embed:note}" jail: "{embed:jail}" ban: "{embed:ban}" tempban: "{embed:tempban}" mute: "{embed:mute}" tempmute: "{embed:tempmute}" banip: "{embed:banip}" tempbanip: "{embed:tempbanip}" warn: "{embed:warn}" tempwarn: "{embed:tempwarn}" unbanip: "{embed:unbanip}" unwarn: "{embed:unwarn}" unmute: "{embed:unmute}" unban: "{embed:unban}" unnote: "{embed:unnote}" unjail: "{embed:unjail}" .....

Eigula file er location: "{<folder>:<jsonfile>}.

Kodari AI
KodariMay 4 at 4:33 am 15,410 (v2)

বুঝলাম। BanAnnouncer এর message format {embed:ban} মানে folder = embed, file = ban.json — so path হবে plugins/BanAnnouncer/embed/ban.json। Current code দুটো সমস্যা আছে:

  1. Folder embeds হার্ডকোড করা — হওয়া উচিত embed

  2. mapTypeToFile() TEMPBAN, BANIP, TEMPMUTE ইত্যাদিকে ভুলভাবে group করছে — প্রতিটার আলাদা JSON ফাইল আছে

দুটো fix:

  • Folder path embeds → embed (BanAnnouncer এর actual folder নাম)

  • mapTypeToFile() সরলীকৃত — এখন সব type এর জন্য type.name().toLowerCase() + ".json" return করে, মানে TEMPBAN → tempban.json, BANIP → banip.json, TEMPMUTE → tempmute.json ইত্যাদি — BanAnnouncer এর messages config এর keys এর সাথে exactly match করে।

kuma077114

banannouncer er sob placeholder jeno work kore + placeholderapi plugin er sob placeholder jeno work kore. and readme.md file ta tikh korba

Kodari AI
KodariMay 4 at 4:36 am 23,840 (v2)

Plan:

  • build.gradle এ PlaceholderAPI compileOnly dep যোগ করব

  • plugin.yml এ softdepend: [PlaceholderAPI] যোগ করব

  • BanButtonExtension.resolve() এ PAPI setPlaceholders() call যোগ করব (offline player support সহ)

  • README ঠিক করব — folder path embeds/ → embed/, type-to-file mapping correct করব, PAPI placeholder section যোগ করব

Now update BanButtonExtension to apply PAPI placeholders in resolve():

Now rewrite the README with all corrections:

কী কী change হলো:

  1. build.gradle — PlaceholderAPI repo (extendedclip) ও compileOnly 'me.clip:placeholderapi:2.11.5' dep যোগ হলো

  2. plugin.yml — softdepend: [PlaceholderAPI] যোগ হলো

  3. BanButtonExtension.resolve() — BanAnnouncer placeholder resolve করার পরে, PlaceholderAPI installed থাকলে PlaceholderAPI.setPlaceholders(offlinePlayer, text) দিয়ে PAPI placeholders ও resolve হয় — সব label, url, response field এ কাজ করবে

  4. README.md — folder path embeds/ → embed/ fix, type-to-file mapping সব আলাদা আলাদা (যেমন tempban.json, banip.json), BanAnnouncer + PAPI placeholder table, {embed:type} syntax explanation যোগ হলো

kuma077114

ei plugin e jeno BanAnnouncer plugin er sob placeholder work kore and PlaceholderAPI er sob placeholder work kore jeno.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
README.md
Code
6 740
src/main/java/me/niloy/banaddon/BanAnnouncerButtonAddon.java
package me.niloy.banaddon;

import me.tini.announcer.BanAnnouncer;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.spicord.Spicord;
import org.spicord.plugin.PluginInterface;

import java.io.File;
import java.util.logging.Logger;

public class BanAnnouncerButtonAddon extends JavaPlugin implements PluginInterface {

    private BanAnnouncer announcer;
    private BanButtonSpicordAddon spicordAddon;

    @Override
    public void onEnable() {
        Plugin baPlugin = Bukkit.getPluginManager().getPlugin("BanAnnouncer");
        if (baPlugin == null) {
            getLogger().severe("BanAnnouncer not found — disabling.");
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }

        try {
            announcer = (BanAnnouncer) baPlugin.getClass().getMethod("getAnnouncer").invoke(baPlugin);
        } catch (Exception e) {
            getLogger().severe("Failed to retrieve BanAnnouncer API instance: " + e.getMessage());
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }

        if (!Spicord.isLoaded()) {
            getLogger().severe("Spicord not found — disabling.");
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }

        spicordAddon = new BanButtonSpicordAddon();
        Spicord.getInstance().getAddonManager().registerAddon(spicordAddon, this);

        BanButtonExtension extension = new BanButtonExtension(this, announcer, spicordAddon);
        announcer.registerExtension(
                "BanAnnouncerButtonAddon",
                "niloy.banaddon.extension",
                () -> extension,
                "me.tini.announcer.BanAnnouncer"
        );
        announcer.enableExtensions();

        getLogger().info("BanAnnouncerButtonAddon enabled successfully.");
    }

    @Override
    public void onDisable() {
        if (Spicord.isLoaded() && spicordAddon != null) {
            Spicord.getInstance().getAddonManager().unregisterAddon(spicordAddon);
        }
    }

    @Override
    public File getFile() {
        return super.getFile();
    }

    @Override
    public Logger getLogger() {
        return super.getLogger();
    }
}