niloy309_
📎 1 file 3,938 chars
📄
pasted-code-1780473974432.txt
txt 75 lines
▶
I need a highly secure, production-ready Java license verification system for a new Minecraft Spigot/Paper plugin (supporting versions 1.16.5 to recent releases). The system must communicate with my Node.js API and enforce strict conditional loading and command execution rules.

​Here are the exact technical requirements and architectural flow:

​1. Target API URL & Identity Parameters

​Verification Endpoint: [https://plugin-license.niloy.qzz.io/verify](https://plugin-license.niloy.qzz.io/verify)

​HTTP Method: GET

​Query Parameters: ?key=&serverIdentity=:

​Identity Rules (No Bukkit IP/Port Methods for IP): 

​Do NOT use Bukkit.getServer().getIp() or Bukkit.getIp().

​The plugin must fetch the server's Numerical Public IP by making a web request to [https://checkip.amazonaws.com/](https://checkip.amazonaws.com/).

​If Amazon is down or fails, it must immediately fallback to [https://ifconfig.me/ip](https://ifconfig.me/ip).

​The port must be dynamically fetched using Bukkit.getServer().getPort().

​Combine them as : for the serverIdentity parameter.

​2. Initialization & Dynamic Loading Flow (On Startup)

​When the server boots up (onEnable()), the plugin must only create and load a specific configuration file named license.yml.

​Inside license.yml, there should be a single configurable option: license-key: "".

​Strict Conditional Rule: The plugin must NOT load config.yml, data.yml, or any other feature files on startup until the license key is successfully validated through the API.

​The API request must run asynchronously to avoid locking up the main server thread, but it must complete its check before changing the plugin's structural state.

​3. Authorization Outcomes

​If API returns {"authorized": true}: 

​Set a global status boolean isLicenseValid = true.

​Perform the initial load of config.yml and data.yml for the very first time.

​Enable all plugin events, tasks, and features.

​If API returns {"authorized": false} or connection fails: 

​Set isLicenseValid = false.

​Do NOT load config.yml or data.yml. Keep them completely out of memory.

​Print this exact warning message to the console: [AuLuckyBlockParty] Error: Invalid license or connection failure. Features disabled.

​The plugin must remain enabled (to prevent console errors or crashes from other dependent plugins) but all its internal mechanisms must be disabled.

​4. Verification-Only Command (/lvp:admin license-reload)

​Register a command named /lvp:admin license-reload with the permission node lvp.admin.license-reload. It must be executable from both the Console and by authorized In-game Players.

​Strict Command Logic (When License is Invalid): 

​If isLicenseValid is false, ALL other commands belonging to this plugin must be intercepted and completely blocked.

​If any unauthorized command is executed while the license is invalid, it must return this exact English message to the sender: Error: This plugin is disabled because the license key is invalid. Please update your license.yml and run /lvp:admin license-reload.

​Strict Reload Constraints (No File Reloading): 

​Running /lvp:admin license-reload must ONLY re-read the license.yml file, fetch the numerical public IP again, and hit the verification endpoint to re-verify the status.

​It must NOT act as a traditional plugin configuration reload. It must never reload data inside config.yml or data.yml if they are already active.

​If the status changes from Invalid to Valid, it triggers the initial load of config.yml and data.yml for the first time since boot. If it stays valid or invalid, no file modifications/reloads should happen.

​Please write the complete, clean, and object-oriented Java source code, including the LicenseManager class, the CommandExecutor, and an example of how they should be registered inside the main class's onEnable() method."

plugin name: AuLuckyBlockParty
Kodari AI
KodariJun 3 at 8:08 am 12

Here’s the complete license verification system. 5 files to create:

  1. LicenseManager — async IP fetch, API call, state

  2. LicenseCommand — /admin license-reload (namespaced as /auluckyblockparty:admin)

  3. LicensedCommandExecutor — wrapper that gates all feature commands behind license

  4. AuLuckyBlockParty — main class with conditional feature loading

  5. plugin.yml + license.yml

Note on /lvp:admin: Bukkit namespaces commands using the plugin name. With name: AuLuckyBlockParty, the full command is /auluckyblockparty:admin license-reload. To get exactly /lvp:admin, change name: in plugin.yml to lvp — everything else stays the same.


Here’s exactly how the system behaves at each stage:

Boot flow

Plain Text
onEnable()
  └─ saves license.yml only           (config.yml / data.yml NOT touched)
  └─ registers /admin license-reload  (always available, regardless of license)
  └─ async: fetchPublicIP → verify API
       ├─ authorized: true  → loadFeatures() → loads config.yml + data.yml, registers events/commands
       └─ authorized: false → logs "[AuLuckyBlockParty] Error: Invalid license..." plugin stays up

/admin license-reload flow

Plain Text
reloadAsync()
  └─ re-reads license.yml               (no other files touched)
  └─ fetches fresh public IP            (checkip.amazonaws.com → ifconfig.me fallback)
  └─ hits verify endpoint again
       ├─ invalid → valid  → calls loadFeatures() once, enables everything
       ├─ valid → valid    → confirms valid, does nothing else
       └─ → invalid        → reports failure, stays disabled

Command blocking

Wrap every feature command with registerLicensedCommand("mycommand", executor) inside loadFeatures(). Any call to a licensed command while invalid returns the exact message specified. The LicensedCommandExecutor class handles this transparently — your real executors never need to check licensing themselves.

niloy309_

license valid na jeno sudu ei plugin er command gulai use na korte pare.

Kodari AI
KodariJun 3 at 8:10 am 10

বর্তমান সিস্টেমে LicensedCommandExecutor দিয়ে command block হয়, কিন্তু এটা কাজ করে শুধু যদি developer manually প্রতিটা command wrap করে registerLicensedCommand() দিয়ে। কেউ যদি ভুলে একটা command register করতে ভুলে যায়, সেটা unlocked থেকে যাবে।

সমাধান: একটা central CommandFilter add করা যা Bukkit-এর PluginCommandYAMLParser hook ব্যবহার না করে বরং plugin-এর সব command-এর executor-এ startup-এ automatically license gate বসিয়ে দেবে। Plus onCommand intercept করার জন্য একটা PluginCommand override strategy।

সবচেয়ে bulletproof approach — onEnable-এ সব declared command গুলো automatically wrap করে দেওয়া, কোনো manual wrapping ছাড়াই:

এখন AuLuckyBlockParty.java এ একটা autoWrapAllCommands() method যোগ করব যেটা plugin.yml-এ declared সব commands (admin বাদে) automatically LicensedCommandExecutor দিয়ে wrap করবে — কোনো manual call ছাড়াই।

এখন registerLicensedCommand() ও update করতে হবে যেন এটা existing wrapper-এর ভেতরে delegate replace করে, double-wrap না করে:


কী পরিবর্তন হলো

আগে (দুর্বল): Developer যদি loadFeatures()-এ registerLicensedCommand("luckyblock", ...) call করতে ভুলে যেত, luckyblock command সরাসরি execute হয়ে যেত — license invalid হলেও।

এখন (bulletproof):

Plain Text
onEnable()
  └─ licenseManager তৈরি
  └─ /admin register (সবসময় চলবে)
  └─ autoGateAllCommands()  ← নতুন
       └─ plugin.yml-এর প্রতিটা command ("admin" বাদে)
          automatically LicensedCommandExecutor দিয়ে wrap হয়
          এমনকি real executor set হওয়ার আগেই
  └─ async verify...

Race window ও solved: Async check শেষ হওয়ার আগেই যদি কেউ command দেয়, সেটাও block হবে কারণ autoGateAllCommands() sync-এ, verifyAsync() শুরুর আগেই চলে।

Double-wrap নেই: registerLicensedCommand() সবসময় একটা fresh LicensedCommandExecutor তৈরি করে — wrapper-এর ভেতরে আরেকটা wrapper বসে না।

niloy309_

Emon koro jeno jodi license invalid hoi taile ei plugin er kono command work korbe nah (console eo nah player/admin o use korte parbe nah)

Kodari AI
KodariJun 3 at 8:11 am 12

দুটো জায়গা fix করতে হবে:

  1. LicensedCommandExecutor — এখন sender.sendMessage() দিয়ে block করে, কিন্তু console sender-এর জন্য §c color code raw text হিসেবে দেখায়। আরও গুরুত্বপূর্ণ: Console-এর জন্যও block যে হচ্ছে সেটা absolutely explicit করতে হবে।

  2. LicenseCommand — console-এর জন্য color strip করে clean log দিতে হবে।

এখন LicenseCommand-এও console-এর জন্য color code ছাড়া clean message দিতে হবে:


কী পরিবর্তন হলো

License invalid থাকলে block হবে:

Sender
আগে
এখন
Regular Player
✅ blocked (colored msg)
✅ blocked (colored msg)
OP / Admin (in-game)
✅ blocked
✅ blocked
Console
✅ blocked কিন্তু
§c
raw দেখাতো
✅ blocked + clean plain text log

Console-এ দেখাবে:

Plain Text
[AuLuckyBlockParty] Error: This plugin is disabled because the license key is invalid.
Please update your license.yml and run /lvp:admin license-reload.

Player-এ দেখাবে:

Plain Text
§c (লাল রঙে) Error: This plugin is disabled...

একমাত্র কাজ করবে: /auluckyblockparty:admin license-reload — কারণ এটা ছাড়া license fix করার কোনো উপায় থাকবে না।

niloy309_

ei plugin e kew jokhon rewards pai (jokhon event ti start hoi) tokhon sob online player er chat e blank message jai (empty messag). Fix koro

Kodari AI
KodariJun 3 at 8:15 am 11

সমস্যা পাওয়া গেছে। config.yml-এ stopDurability আর startVoteCount এর value empty string ""। তাই Bukkit.broadcastMessage("") call হচ্ছে — সব online player-এর chat-এ blank message যাচ্ছে।

stopDurability আর startVoteCount empty "" — তাই broadcastMessage("") blank line broadcast করছে। VoteManager-এ broadcast করার আগে null/empty check দিতে হবে।

৪টা জায়গায় fix হয়েছে:

Location
সমস্যা
Fix
addVotes()
formatStartVoteCount()
→
""
→ blank broadcast
empty check added
startEvent()
getEventStartMessage()
empty হলে blank broadcast
empty check added
stopEvent()
getEventStopMessage()
empty হলে blank broadcast
empty check added
decreaseHealth()
formatStopDurability()
→
""
→ blank broadcast
empty check added

Root cause: config.yml-এ stopDurability: "" আর startVoteCount: "" — এই দুটো empty string হওয়ার কারণে Bukkit.broadcastMessage("") call হচ্ছিল, যেটা সব online player-এর chat-এ একটা blank line পাঠাচ্ছিল।

এখন থেকে যেকোনো message empty বা null হলে broadcast হবেই না।

niloy309_

plugin er author change kore Niloy koro

Kodari AI
KodariJun 3 at 8:56 am 3

plugin.yml-এ author YourName থেকে Niloy-তে পরিবর্তন হয়েছে।

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
README.md
Code
26 2,245
src/main/java/com/auluckyblockparty/AuLuckyBlockParty.java
package com.auluckyblockparty;

import com.auluckyblockparty.license.LicenseCommand;
import com.auluckyblockparty.license.LicensedCommandExecutor;
import com.auluckyblockparty.license.LicenseManager;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

public class AuLuckyBlockParty extends JavaPlugin {

    private LicenseManager licenseManager;

    // Guards against loadFeatures() being called more than once.
    private boolean featuresLoaded = false;

    @Override
    public void onEnable() {
        // ── Step 1: Create the data folder and save license.yml only ──────────
        if (!getDataFolder().exists()) {
            getDataFolder().mkdirs();
        }
        saveLicenseConfig();

        // ── Step 2: Bootstrap the license subsystem ───────────────────────────
        licenseManager = new LicenseManager(this);

        // Register the license-reload command immediately — it must always work.
        PluginCommand adminCmd = getCommand("admin");
        if (adminCmd != null) {
            LicenseCommand licenseCommand = new LicenseCommand(this, licenseManager);
            adminCmd.setExecutor(licenseCommand);
            adminCmd.setTabCompleter(licenseCommand);
        }

        // ── Step 3: Async license check — no other files loaded until valid ───
        // Auto-gate all feature commands immediately, before the async check finishes.
        // This prevents a tiny race window where a command could fire before the
        // async verification returns its result.
        autoGateAllCommands();

        licenseManager.verifyAsync(
                /* onValid   */ this::loadFeatures,
                /* onInvalid */ this::disableFeatures
        );
    }

    @Override
    public void onDisable() {
        // Clean shutdown — cancel any tasks, close resources, etc.
        getLogger().info("AuLuckyBlockParty has been disabled.");
    }

    // ─────────────────────────────────────────────────────────────────────────
    // Feature gate
    // ─────────────────────────────────────────────────────────────────────────

    /**
     * Called exactly once when the license first becomes valid (either on startup
     * or after a successful /admin license-reload while previously invalid).
     * Loads config.yml and data.yml and registers all plugin internals.
     */
    public void loadFeatures() {
        if (featuresLoaded) return;
        featuresLoaded = true;

        getLogger().info("License validated. Loading plugin features...");

        // ── Load configuration files ──────────────────────────────────────────
        saveDefaultConfig();                         // config.yml
        saveResource("data.yml", false);             // data.yml (only if absent)

        // ── Register events ───────────────────────────────────────────────────
        // Example: getServer().getPluginManager().registerEvents(new YourListener(this), this);

        // ── Register feature commands ─────────────────────────────────────────
        // Assign the real executor; autoGateAllCommands() already wrapped every
        // command with LicensedCommandExecutor on startup, so we must set the
        // real executor THROUGH the existing wrapper rather than bypassing it.
        // Use registerLicensedCommand() which always produces a clean single wrap.
        //
        // Example:
        //   registerLicensedCommand("luckyblock", new LuckyBlockCommand(this));

        getLogger().info("AuLuckyBlockParty is fully enabled.");
    }

    private void disableFeatures() {
        getLogger().warning(
                "[AuLuckyBlockParty] Error: Invalid license or connection failure. Features disabled.");
        // Plugin stays enabled; only internal mechanisms are inactive.
    }

    // ─────────────────────────────────────────────────────────────────────────
    // Helpers
    // ─────────────────────────────────────────────────────────────────────────

    /**
     * Registers a command executor behind the license gate.
     * If the command was already auto-gated by autoGateAllCommands(), this replaces
     * the inner delegate instead of stacking a second wrapper on top.
     *
     * @param commandName name as declared in plugin.yml (without the slash)
     * @param executor    the real executor to delegate to when license is valid
     */
    public void registerLicensedCommand(String commandName, CommandExecutor executor) {
        PluginCommand cmd = getCommand(commandName);
        if (cmd == null) {
            getLogger().warning("Command '" + commandName + "' is not declared in plugin.yml.");
            return;
        }
        // Always create a fresh wrapper with the real executor — avoids double-wrapping.
        cmd.setExecutor(new LicensedCommandExecutor(licenseManager, executor));
    }

    /**
     * Automatically wraps ALL commands declared in plugin.yml (except "admin") with
     * LicensedCommandExecutor. This is called immediately in onEnable() so that even
     * commands whose real executors haven't been set yet are gated — they will block
     * with the license error message until loadFeatures() sets the real executor
     * (which itself is wrapped).
     *
     * This means developers NEVER need to remember to call registerLicensedCommand();
     * every new command added to plugin.yml is automatically protected.
     */
    private void autoGateAllCommands() {
        if (getDescription().getCommands() == null) return;
        for (String commandName : getDescription().getCommands().keySet()) {
            if (commandName.equalsIgnoreCase("admin")) continue; // license-reload must always work
            PluginCommand cmd = getCommand(commandName);
            if (cmd == null) continue;
            CommandExecutor current = cmd.getExecutor();
            // Only wrap if not already wrapped (prevents double-wrapping on re-registration)
            if (!(current instanceof LicensedCommandExecutor)) {
                cmd.setExecutor(new LicensedCommandExecutor(licenseManager, current));
            }
        }
    }

    public LicenseManager getLicenseManager() {
        return licenseManager;
    }

    // ─────────────────────────────────────────────────────────────────────────
    // license.yml bootstrap
    // ─────────────────────────────────────────────────────────────────────────

    private void saveLicenseConfig() {
        java.io.File licenseFile = new java.io.File(getDataFolder(), "license.yml");
        if (!licenseFile.exists()) {
            saveResource("license.yml", false);
        }
    }
}