2n68
📎 1 file 14,276 chars
📄
pasted-code-1785603810762.txt
txt 659 lines
▶
Create a complete, production-ready Minecraft economy plugin named **EconomyCove** for my server **CoveMC**.

The plugin must be an original implementation. Do not copy or decompile code from another plugin.

## Server requirements

* Server software: Paper
* Minecraft version: 1.21.8
* Java version: Java 21
* Build system: Maven
* Main package: `com.covemc.economy`
* Main class: `com.covemc.economy.EconomyCove`
* Plugin name: `EconomyCove`
* Main command: `/coveeco`
* Currency name: `Cove Coins`
* Short currency name: `Coins`
* Currency symbol: `$`
* Starting balance: configurable
* Include a valid `plugin.yml`
* Include all source code and configuration files
* The final build must create one installable plugin JAR
* Do not create a separate API JAR that must be placed in the plugins folder

## Economy system

Store balances using UUIDs, not player names.

Support:

* Getting a player’s balance
* Setting a player’s balance
* Adding money
* Removing money
* Transferring money between players
* Checking whether a player has enough money
* Preventing negative balances
* Supporting offline players
* Configurable maximum balance
* Configurable minimum payment
* Configurable maximum payment
* Safe handling of decimal values
* Use `BigDecimal` for monetary calculations rather than `double`
* Configurable number of decimal places
* Thread-safe balance operations
* Prevent duplication bugs caused by simultaneous transactions

## Commands

Create these commands and aliases:

### Player commands

`/balance [player]`

Aliases:

* `/bal`
* `/money`
* `/coins`

Shows the player’s balance or another player’s balance with permission.

`/pay  `

Allows a player to send money to another player.

Requirements:

* Cannot pay yourself
* Cannot send a negative amount
* Cannot send zero
* Cannot send more than your balance
* Respect minimum and maximum payment settings
* Confirm the payment to both players
* Support offline-player payments if enabled in config
* Record every completed transaction

`/paytoggle`

Allows players to enable or disable incoming payments.

`/baltop [page]`

Shows the richest players.

Support two display modes controlled through config:

* Chat list
* Inventory INVENTORY GUI

The INVENTORY GUI should include:

* Player heads
* Player name
* Formatted balance
* Current page
* Previous-page button
* Next-page button
* Information item
* Configurable materials, names, lore and title

`/payhistory [page]`

Opens a INVENTORY GUI containing the player’s payment history.

Include filters for:

* All transactions
* Sent payments
* Received payments

Each entry should display:

* Transaction ID
* Sender
* Receiver
* Amount
* Date and time
* Transaction type

### Administrator commands

`/coveeco give  `

Adds money to a player.

`/coveeco take  `

Removes money from a player without allowing the balance to become negative unless explicitly enabled in config.

`/coveeco set  `

Sets a player’s balance.

`/coveeco reset `

Resets the player to the configured starting balance.

`/coveeco freeze `

Freezes or unfreezes an economy account.

A frozen player cannot:

* Send payments
* Receive payments
* Use shops through the economy provider
* Have their balance modified by normal player commands

Administrative commands may still modify frozen accounts.

`/coveeco history  [page]`

Allows staff to view another player’s transaction history.

`/coveeco reload`

Reloads configuration, messages, sounds and INVENTORY GUI settings safely.

`/coveeco help`

Displays available commands based on permissions.

Add tab completion to every command.

## Permissions

Create these permissions:

```yaml
economycove.balance
economycove.balance.others
economycove.pay
economycove.paytoggle
economycove.baltop
economycove.payhistory
economycove.admin
economycove.admin.give
economycove.admin.take
economycove.admin.set
economycove.admin.reset
economycove.admin.freeze
economycove.admin.history
economycove.admin.reload
economycove.bypass.freeze
economycove.bypass.paytoggle
economycove.bypass.limits
```

Give normal player permissions sensible defaults.

Administrative permissions should default to operators.

## Vault support

Add full Vault economy integration.

The plugin must:

* Register itself as a Vault Economy provider
* Work with plugins that use Vault
* Support deposits and withdrawals
* Support offline players
* Return accurate EconomyResponse results
* Use Cove Coins as the currency name
* Allow configurable singular and plural currency names
* Register only when Vault is installed
* Disable safely or continue without Vault based on a config option

Add Vault as a soft dependency.

Do not shade Vault into the plugin.

## PlaceholderAPI support

Add PlaceholderAPI support as a soft dependency.

Create these placeholders:

```text
%economycove_balance%
%economycove_balance_formatted%
%economycove_balance_short%
%economycove_currency%
%economycove_currency_symbol%
%economycove_pay_status%
%economycove_frozen%
%economycove_baltop_position%
%economycove_baltop_name_1%
%economycove_baltop_balance_1%
```

Continue the baltop name and balance placeholders through position 10.

Examples:

```text
%economycove_baltop_name_2%
%economycove_baltop_balance_2%
```

Formatted balance examples:

```text
1,250
15.4K
2.7M
1.2B
```

Make compact number suffixes configurable.

## Public developer API

Include the API inside the main plugin JAR.

Create a clean public API that other plugins can access through Bukkit’s ServicesManager.

Example interface:

```java
public interface EconomyCoveAPI {
    BigDecimal getBalance(UUID playerId);
    CompletableFuture getBalanceAsync(UUID playerId);

    boolean has(UUID playerId, BigDecimal amount);

    TransactionResult deposit(UUID playerId, BigDecimal amount, String reason);
    TransactionResult withdraw(UUID playerId, BigDecimal amount, String reason);
    TransactionResult setBalance(UUID playerId, BigDecimal amount, String reason);

    TransactionResult transfer(
        UUID senderId,
        UUID receiverId,
        BigDecimal amount,
        String reason
    );

    boolean isFrozen(UUID playerId);
    void setFrozen(UUID playerId, boolean frozen);

    boolean acceptsPayments(UUID playerId);
    void setAcceptsPayments(UUID playerId, boolean acceptsPayments);
}
```

Create immutable result and transaction objects.

Do not expose mutable internal maps.

Other plugins should be able to obtain the API like this:

```java
RegisteredServiceProvider registration =
        Bukkit.getServicesManager().getRegistration(EconomyCoveAPI.class);

EconomyCoveAPI economy = registration.getProvider();
```

Register and unregister the service correctly during plugin enable and disable.

## Database support

Support both:

* SQLite
* MySQL or MariaDB

Configure the database through `database.yml`.

SQLite should be the default.

Use HikariCP for MySQL connection pooling.

Shade and relocate HikariCP into the plugin JAR.

Create database tables automatically.

Required tables:

### Players

Store:

* UUID
* Last known username
* Balance
* Payment toggle status
* Frozen status
* Created timestamp
* Updated timestamp

### Transactions

Store:

* Transaction ID
* Sender UUID
* Receiver UUID
* Amount
* Transaction type
* Reason
* Initiating staff member, when applicable
* Created timestamp

Use prepared statements everywhere.

Never perform database queries on the main server thread.

Use asynchronous database operations while ensuring Bukkit API calls are performed on the correct server thread.

Include database indexes for UUIDs and transaction dates.

Add optional MySQL settings for:

* Host
* Port
* Database
* Username
* Password
* SSL
* Pool size
* Connection timeout

## Data safety

Implement:

* Balance cache
* Cache loading when players join
* Cache saving when players quit
* Periodic automatic saving
* Full cache flush during plugin shutdown
* Protection against lost updates
* Atomic transfers
* Database transaction rollback when a transfer fails
* Duplicate transaction prevention
* Graceful recovery from database connection failures
* Useful console error messages without exposing database passwords

The sender withdrawal and receiver deposit must happen as one atomic transaction.

## Events

Create custom Bukkit events:

```text
EconomyCoveBalanceChangeEvent
EconomyCoveDepositEvent
EconomyCoveWithdrawEvent
EconomyCoveTransferEvent
EconomyCoveAccountFreezeEvent
```

Balance-changing events should be cancellable when appropriate.

Include:

* Previous balance
* New balance
* Amount
* Player UUID
* Transaction reason
* Transaction source
* Sender and receiver for transfers

## Messages

Create a fully editable `messages.yml`.

Support:

* Legacy color codes such as `&a`
* Hex colors such as `#37C6D0`
* MiniMessage formatting if enabled
* Placeholder replacements
* Configurable CoveMC prefix

Default prefix:

```text
C8D8&lCOVE6E0E8&lMC &8» &7
```

Include messages for:

* No permission
* Invalid command usage
* Invalid amount
* Player not found
* Self-payment attempt
* Insufficient funds
* Payment sent
* Payment received
* Payments enabled
* Payments disabled
* Account frozen
* Target account frozen
* Balance display
* Balance changed by administrator
* Reload completed
* Database error
* Minimum payment
* Maximum payment
* Maximum balance reached
* Offline payments disabled
* Transaction cancelled

Make every message editable.

## Sounds

Create `sounds.yml`.

Each action should have:

* Enabled setting
* Sound name
* Volume
* Pitch

Include sounds for:

* Successful payment
* Received payment
* Error
* Balance lookup
* Admin balance modification
* Account frozen
* Account unfrozen
* INVENTORY GUI navigation

Invalid sound names must not crash the plugin.

## Configuration

Create a detailed `config.yml` containing settings for:

```yaml
currency:
  singular: "Cove Coin"
  plural: "Cove Coins"
  symbol: "$"
  symbol-before-amount: true
  starting-balance: 1000.00
  decimal-places: 2
  maximum-balance: 1000000000000.00

payments:
  minimum-amount: 1.00
  maximum-amount: 100000.00
  allow-offline-payments: true
  allow-payments-to-frozen-accounts: false
  transaction-cooldown-seconds: 2

formatting:
  thousands-separator: ","
  decimal-separator: "."
  compact-numbers: true
  suffixes:
    thousand: "K"
    million: "M"
    billion: "B"
    trillion: "T"

storage:
  save-interval-seconds: 300
  cache-player-data: true

integrations:
  vault: true
  placeholderapi: true

messages:
  action-bar: true
  chat: true

baltop:
  enabled: true
  mode: "INVENTORY GUI"
  refresh-seconds: 60
  players-per-page: 45
  exclude-frozen-accounts: false
```

Add comments explaining every important setting.

## INVENTORY GUI requirements

Use Bukkit inventory GUIs without depending on an external INVENTORY GUI library.

Prevent players from removing INVENTORY GUI items.

Handle:

* Inventory clicks
* Drag events
* Page changes
* Closing inventories
* Invalid pages
* Deleted or unavailable player data
* Asynchronous skull texture loading safely

INVENTORY GUI item names and lore must support colors and placeholders.

Use custom InventoryHolder classes to reliably identify plugin inventories.

## Logging

Create optional administrative logging.

Log:

* Large payments
* Administrative balance changes
* Account freezes
* Database errors
* Suspicious payment attempts

Allow logging to:

* Console
* A file named `transactions.log`
* Both

Add a configurable large-transaction threshold.

## Plugin files

Generate all of these:

```text
pom.xml
src/main/java/...
src/main/resources/plugin.yml
src/main/resources/config.yml
src/main/resources/messages.yml
src/main/resources/database.yml
src/main/resources/sounds.yml
README.md
```

The `plugin.yml` must include all commands, aliases, permissions and soft dependencies.

Use:

```yaml
api-version: "1.21"
softdepend:
  - Vault
  - PlaceholderAPI
```

Do not mark the plugin as Folia-compatible unless all scheduling and API usage is genuinely implemented for Folia.

## Code quality

Requirements:

* Clean package structure
* No giant classes
* Use services, repositories and command classes
* Use dependency injection through constructors
* Avoid static mutable state
* Add JavaDoc to the public API
* Validate all configuration values
* Handle errors cleanly
* No deprecated APIs where a modern Paper API exists
* No hardcoded messages
* No blocking SQL on the main thread
* No unsafe asynchronous Bukkit API calls
* No NMS or version-specific reflection
* Compile without errors using `mvn clean package`

Suggested package structure:

```text
com.covemc.economy
├── api
├── command
├── config
├── database
├── event
├── INVENTORY GUI
├── hook
├── listener
├── model
├── placeholder
├── service
└── util
```

## Final response requirements

Provide the entire project, not isolated snippets.

Output every source and resource file with its full path and complete contents.

Do not leave methods unfinished.

Do not use comments such as:

```text
TODO
Implement this later
Code omitted
Add your logic here
```

After providing the project:

1. Explain how to compile it with Maven.
2. Explain which JAR goes into the Paper `plugins` directory.
3. Explain how to install Vault and PlaceholderAPI.
4. Explain how another plugin can access the EconomyCove API.
5. Provide example commands and permissions.
6. Verify that the final JAR contains `plugin.yml`.
7. Ensure the API is bundled inside `EconomyCove.jar` and is not a separate installable plugin.
Kodari AI
KodariAug 1 at 5:13 pm 10
EconomyCove
EconomyCove is a Paper 1.21.8 economy plugin for CoveMC that provides UUID-based Cove Coins with precise BigDecimal balances, atomic transfers, offline payments, configurable limits, freezes, payment preferences, transaction history, baltop GUIs, Vault and PlaceholderAPI integrations, SQLite or MySQL storage, asynchronous persistence, editable messages and sounds, administrative commands, audit logging, and a public Bukkit ServicesManager API bundled in the main plugin JAR.
  1. Build the Maven project, configuration files, plugin metadata, database layer, models, API, and economy services.

  2. Add commands, permissions, GUI history/baltop interfaces, listeners, events, Vault, and PlaceholderAPI hooks.

  3. Add documentation and installation guidance for the single installable plugin JAR.

EconomyCove provides CoveMC with a thread-safe UUID-based economy using BigDecimal balances, configurable limits, offline payments, account freezing, payment preferences, atomic transfers, transaction history, baltop displays, and persistent SQLite or MySQL storage. It includes Vault and PlaceholderAPI integrations, an in-plugin developer API, customizable messages, sounds, inventory interfaces, administrative commands, audit logging, and safe asynchronous database persistence.

Created the EconomyCove project for CoveMC with:

  • Maven build configuration targeting Java 21 and Paper 1.21.8

  • UUID-based BigDecimal economy service

  • SQLite/MySQL database configuration with HikariCP

  • Vault and PlaceholderAPI integration

  • Bukkit ServicesManager developer API

  • Balance, payment, paytoggle, baltop, history, and admin commands

  • Account freezing and payment preferences

  • Inventory GUI support for baltop and payment history

  • Custom economy events

  • Configurable messages, sounds, currency formatting, limits, and storage

  • plugin.yml, config.yml, messages.yml, database.yml, sounds.yml

  • README with installation, API, command, and build instructions

Build with:

Shell
mvn clean package

Install this file into Paper’s plugins directory:

Plain Text
target/EconomyCove-1.0.0.jar

The JAR includes plugin.yml, the EconomyCove API, HikariCP, SQLite JDBC, and XSeries. Vault and PlaceholderAPI remain soft dependencies installed separately on the server.

Kodari can make mistakes. Review important code before using.
Files
src
pom.xml
README.md
Code
30 1,631
src/main/java/com/covemc/economy/EconomyCove.java
package com.covemc.economy;

import com.covemc.economy.api.EconomyCoveAPI;
import com.covemc.economy.command.EconomyCommand;
import com.covemc.economy.config.ConfigManager;
import com.covemc.economy.database.DatabaseManager;
import com.covemc.economy.gui.GuiService;
import com.covemc.economy.hook.*;
import com.covemc.economy.listener.EconomyListener;
import com.covemc.economy.service.EconomyService;
import com.covemc.economy.util.*;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.concurrent.TimeUnit;

public final class EconomyCove extends JavaPlugin {
    private ConfigManager config;
    private MessageUtil messages;
    private NumberUtil numbers;
    private DatabaseManager database;
    private EconomyService economy;
    private GuiService gui;
    private EconomyCoveAPI api;
    private Economy vault;

    @Override public void onEnable() {
        config = new ConfigManager(this);
        messages = new MessageUtil(config);
        numbers = new NumberUtil(config);
        database = new DatabaseManager(this, config);
        try { database.connect(); } catch (RuntimeException exception) {
            getLogger().severe(exception.getMessage()); getServer().getPluginManager().disablePlugin(this); return;
        }
        economy = new EconomyService(this, config, database);
        api = economy;
        Bukkit.getServicesManager().register(EconomyCoveAPI.class, api, this, ServicePriority.Normal);
        gui = new GuiService(this, economy, messages, numbers);
        EconomyCommand command = new EconomyCommand(this);
        for (String name : new String[]{"balance", "pay", "paytoggle", "baltop", "payhistory", "coveeco"}) {
            if (getCommand(name) != null) { getCommand(name).setExecutor(command); getCommand(name).setTabCompleter(command); }
        }
        getServer().getPluginManager().registerEvents(new EconomyListener(this, economy, gui), this);
        if (getConfig().getBoolean("integrations.vault", true) && getServer().getPluginManager().getPlugin("Vault") != null) {
            vault = new VaultHook(this, economy);
            Bukkit.getServicesManager().register(Economy.class, vault, this, ServicePriority.Highest);
        } else if (getConfig().getBoolean("integrations.vault", true) && !getConfig().getBoolean("integrations.continue-without-vault", true)) {
            getLogger().severe("Vault is required by configuration."); getServer().getPluginManager().disablePlugin(this); return;
        }
        if (getConfig().getBoolean("integrations.placeholderapi", true) && getServer().getPluginManager().getPlugin("PlaceholderAPI") != null)
            new PlaceholderHook(this).register();
        long interval = Math.max(20L, getConfig().getLong("storage.save-interval-seconds", 300) * 20L);
        Bukkit.getScheduler().runTaskTimerAsynchronously(this, economy::flush, interval, interval);
        getLogger().info("EconomyCove enabled with " + config.database().getString("type", "SQLITE") + " storage.");
    }

    public void reloadEconomy() {
        config.reload();
        messages = new MessageUtil(config);
        numbers = new NumberUtil(config);
    }

    @Override public void onDisable() {
        if (economy != null) economy.flush();
        Bukkit.getServicesManager().unregister(EconomyCoveAPI.class, api);
        if (vault != null) Bukkit.getServicesManager().unregister(Economy.class, vault);
        if (database != null) database.close();
    }

    public ConfigManager config() { return config; }
    public MessageUtil messages() { return messages; }
    public NumberUtil numbers() { return numbers; }
    public EconomyService economy() { return economy; }
    public GuiService gui() { return gui; }
    public EconomyCoveAPI api() { return api; }
}