.kingdomdc.
📎 1 file 5,012 chars
📄
pasted-code-1783073000493.txt
txt 47 lines
▶
Act as an expert Minecraft Spigot/Paper API Java Developer. 

I need you to write a complete, high-quality Minecraft plugin source code for a custom virtual currency system. The plugin will be named "Fruitbasket" and functions similarly to the plugin "TokenManager". 

Please ensure the code follows modern optimization standards, prevents data-race conditions, utilizes asynchronous tasks for database/saving operations, and implements proper object-oriented programming patterns.

### Core Architecture Requirements:
1. TARGET VERSION: Java 17+, Spigot/Paper API 1.20.x or higher.
2. STORAGE & MULTI-DATABASE ENGINE: 
   - Architect an abstract data layer supporting multiple storage types that can be switched via the configuration: Flat-file (YAML), NoSQL (**MongoDB**), and Relational SQL (**MySQL** or **MariaDB**).
   - For MongoDB: Use the official MongoDB Java Driver with a connection pool (`MongoClient`) that supports a connection URI or modular credentials.
   - For MySQL/MariaDB: Use a high-performance HikariCP connection pool. Write optimized SQL queries with prepared statements and proper index generation (`CREATE TABLE IF NOT EXISTS` with a primary index on player UUID strings).
   - Implement an asynchronous, non-blocking data worker system so all database interactions (fetching balances on join, saving on quit, or modification updates) run entirely off the main server thread to prevent any game lag spikes.
3. CACHING: Maintain a thread-safe local cache (e.g., ConcurrentHashMap) of online player balances for rapid lookups and low-overhead API integration.

### LuckPerms & Permissions Integration:
1. The plugin must fully utilize a modern permission node framework compatible with LuckPerms. 
2. Add a dynamic permission system for token earning multipliers. For example, if a player has the permission node `fruitbasket.multiplier.2`, any tokens given to them through an earning event should be multiplied by 2.
3. Code should hook into the LuckPerms API (if present on the server) as an optional dependency to read a player's primary group or weight to automatically determine their token tier, allowing server owners to configure token perks directly via LuckPerms tracks/groups.

### PlaceholderAPI Support:
The plugin must register a Placeholders expansion natively. It needs to provide the following placeholders:
- %fruitbasket_tokens_amount% : Returns the raw, unformatted integer balance of the player (e.g., 1500).
- %fruitbasket_tokens_formatted% : Returns a comma-separated formatted version of the balance (e.g., 1,500).

### Command Framework:
Implement a main command `/fruitbasket` (with aliases `/tokens` and `/token`). Ensure it utilizes proper permission nodes that can be seamlessly managed via LuckPerms, and handles user inputs safely (validating offline players and real numbers).
Commands required:
- `/tokens balance [player]` - View yours or another player's balance. (LuckPerms Permission nodes: fruitbasket.command.balance, fruitbasket.command.balance.other)
- `/tokens pay  ` - Transfer tokens to another online player. Deducts from the sender, adds to the receiver. (LuckPerms Permission node: fruitbasket.command.pay)
- `/tokens admin give  ` - Adds tokens to a player's balance (works for offline players too). (LuckPerms Permission node: fruitbasket.command.admin)
- `/tokens admin take  ` - Deducts tokens from a player's balance. Cannot go below 0. (LuckPerms Permission node: fruitbasket.command.admin)
- `/tokens admin set  ` - Forces a player's token count to a specific value. (LuckPerms Permission node: fruitbasket.command.admin)
- `/tokens admin reload` - Reloads the config.yml file. (LuckPerms Permission node: fruitbasket.command.admin)

### API for Developers:
Provide a singleton instance or a public class `FruitbasketAPI` containing static methods or an accessible manager so other plugins (like DeluxeMenus or custom plugins) can interact with it via Java code:
- `int getTokens(UUID playerUUID)`
- `void addTokens(UUID playerUUID, int amount)`
- `void removeTokens(UUID playerUUID, int amount)`
- `void setTokens(UUID playerUUID, int amount)`
- `boolean hasTokens(UUID playerUUID, int amount)`

### File Configurations:
Provide a clean `config.yml` that allows choosing storage type ('YAML', 'MONGODB', 'MYSQL', or 'MARIADB'). Provide clean, separated configuration sections for credentials (host, port, username, password, database name, connection strings/URIs, and HikariCP pool fine-tuning settings), setting up LuckPerms-tied token multipliers, modifying plugin messages with mini-messages or standard color codes, and toggling whether a sound plays upon receiving tokens.

Please provide the structural layout of the classes (such as the Main class, StorageManager, MongoDBStorage, SQLStorage, TokenCommand, LuckPermsHook, PlaceholderManager, and API class) along with clean, fully implemented, readable Java code.
Kodari AI
KodariJul 3 at 10:07 am 1

I’ll create a complete token currency plugin called Fruitbasket.

Fruitbasket
A virtual currency plugin similar to TokenManager, supporting YAML, MongoDB, and MySQL/MariaDB storage. Features include thread-safe caching, LuckPerms multiplier integration, PlaceholderAPI expansion, and a public API for other plugins. Includes comprehensive admin commands for managing player balances both online and offline.

Let me create all files now.

Fruitbasket
A virtual currency plugin similar to TokenManager, supporting YAML, MongoDB, and MySQL/MariaDB storage. Features include thread-safe caching, LuckPerms multiplier integration, PlaceholderAPI expansion, and a public API for other plugins. Includes comprehensive admin commands for managing player balances both online and offline.
.kingdomdc.

How long will it take you to do all of this and ensure its safe with extra security?

Kodari AI
KodariJul 3 at 10:12 am 1

Already started — I’ll finish everything in this response. Let me create all remaining files now.

All files are created. Here’s a summary of the complete plugin structure:

Fruitbasket — Complete Plugin Structure

File
Purpose
Fruitbasket.java
Main class — lifecycle, instance, manager init
FruitbasketAPI.java
Public static API for other plugins (get/add/remove/set/has)
config/ConfigManager.java
Loads & caches all config.yml values, message getter
storage/StorageProvider.java
Interface for all storage backends
storage/StorageManager.java
Factory — selects backend by config, delegates calls
storage/impl/YAMLStorage.java
Flat-file storage via
tokens.yml
storage/impl/MongoDBStorage.java
MongoDB via official driver, upsert-based saves
storage/impl/SQLStorage.java
MySQL/MariaDB via HikariCP pool, prepared statements,
CREATE TABLE IF NOT EXISTS
with UUID primary key
cache/TokenCache.java
ConcurrentHashMap
— thread-safe, atomic merge ops
command/TokenCommand.java
/tokens balance/pay/admin give
hook/LuckPermsHook.java
Reads
fruitbasket.multiplier.<value>
nodes, highest wins
hook/PlaceholderManager.java
Registers
%fruitbasket_tokens_amount%
and
%fruitbasket_tokens_formatted%
listener/PlayerListener.java
Pre-loads balance on join (async-safe), saves on quit
util/TokenUtil.java
Color translation & sound playback

Security & safety built-in:

  • Thread safety: TokenCache uses ConcurrentHashMap with merge() for atomic add/remove — no race conditions

  • Async I/O: All storage saves run on CompletableFuture.runAsync() — never blocks the main thread

  • SQL injection: All queries use prepared statements with ? placeholders — user input is never concatenated

  • Input validation: Amounts checked for <= 0, player existence validated via OfflinePlayer lookup, NumberFormatException caught

  • Balance clamping: removeTokens and setTokens clamp to Math.max(0, ...) — never negative

  • Atomic transfers: Pay uses removeTokens then direct cache add on receiver — no double-multiplier applied on transfers

  • Offline support: Admin commands use Bukkit.getOfflinePlayerIfCached() — no blocking API calls

  • HikariCP pool: Configurable pool size, timeout, idle, lifetime — prevents connection leaks

  • MongoDB connection pool: Managed by MongoClients.create() — driver handles pooling internally

  • LuckPerms graceful degradation: If LP is absent, multiplier defaults to config value — no crashes

  • Shadow relocation: All dependencies (HikariCP, MongoDB driver, SLF4J) are relocated into the plugin jar — no version conflicts with other plugins

.kingdomdc.

Make sure that these tokens can removed from a player through the command "tokens remove (Player) (amount)"

Kodari AI
KodariJul 6 at 6:54 am 1

The tokens remove <player> <amount> command already exists as admin take, but you want it as a top-level subcommand. I’ll add it directly under balance/pay level

Done. tokens remove <player> <amount> is now a top-level subcommand alongside balance, pay, and admin. No need to prefix with admin — it’s a direct, clean command:

  • /tokens remove Notch 500 — deducts 500 tokens, clamps at 0, works for offline players, uses fruitbasket.command.admin permission

  • Tab completion lists online players for the player argument

  • Same security applies: input validated (no negatives, no zero), NumberFormatException caught, balance never goes below 0

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
Code
18 1,378
src/main/java/com/fruitbasket/Fruitbasket.java
package com.fruitbasket;

import com.fruitbasket.cache.TokenCache;
import com.fruitbasket.command.TokenCommand;
import com.fruitbasket.config.ConfigManager;
import com.fruitbasket.hook.LuckPermsHook;
import com.fruitbasket.hook.PlaceholderManager;
import com.fruitbasket.listener.PlayerListener;
import com.fruitbasket.storage.StorageManager;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Level;

public class Fruitbasket extends JavaPlugin {

    private static Fruitbasket instance;
    private ConfigManager configManager;
    private StorageManager storageManager;
    private TokenCache tokenCache;
    private LuckPermsHook luckPermsHook;
    private PlaceholderManager placeholderManager;

    public static Fruitbasket getInstance() {
        return instance;
    }

    @Override
    public void onEnable() {
        instance = this;

        saveDefaultConfig();
        this.configManager = new ConfigManager(this);

        this.tokenCache = new TokenCache();

        this.storageManager = new StorageManager(this);
        this.storageManager.initialize();

        if (getServer().getPluginManager().getPlugin("LuckPerms") != null) {
            this.luckPermsHook = new LuckPermsHook(this);
            this.luckPermsHook.initialize();
            getLogger().info("LuckPerms hook enabled.");
        }

        getServer().getPluginManager().registerEvents(new PlayerListener(this), this);

        TokenCommand tokenCommand = new TokenCommand(this);
        getCommand("fruitbasket").setExecutor(tokenCommand);
        getCommand("fruitbasket").setTabCompleter(tokenCommand);

        if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
            this.placeholderManager = new PlaceholderManager(this);
            if (this.placeholderManager.register()) {
                getLogger().info("PlaceholderAPI expansion registered.");
            }
        }

        getLogger().info("Fruitbasket v" + getDescription().getVersion() + " enabled.");
    }

    @Override
    public void onDisable() {
        if (storageManager != null) {
            storageManager.shutdown();
        }
        instance = null;
        getLogger().info("Fruitbasket disabled.");
    }

    public void reload() {
        reloadConfig();
        configManager.reload();
        getLogger().info("Configuration reloaded.");
    }

    public ConfigManager getConfigManager() {
        return configManager;
    }

    public StorageManager getStorageManager() {
        return storageManager;
    }

    public TokenCache getTokenCache() {
        return tokenCache;
    }

    public LuckPermsHook getLuckPermsHook() {
        return luckPermsHook;
    }
}