Danielius Galbuogis
📎 1 file 8,181 chars
📄
pasted-code-1789666129164.txt
txt 491 lines
▶
Build a complete custom economy system for my Minecraft Paper 1.21.11 server called SweetBlossomSMP (SBSMP).

IMPORTANT:

* Do NOT use EssentialsX economy, EssentialsX /bal, or Vault economy as the main economy.
* Use a custom SBSMP economy system.
* Store player balances safely and persistently.
* Use LuckPerms permissions.
* All commands and GUIs must work on Paper 1.21.11 and Java 21.
* Make the system configurable through config.yml.

========================

1. BALANCE SYSTEM
   ========================

Create a custom:

/bal
/balance
/bal 

The player's balance should be stored by UUID.

Example:

/bal

Shows:

Balance
$132.34

Use this number format:

* Dollar sign: $
* Thousands separator: ,
* Decimal separator: .
* Always show 2 decimal places.

Examples:
$0.00
$132.34
$1,250.50
$1,000,000.00

/bal  should show another player's balance.

Add permissions:

sbsmp.balance
sbsmp.balance.others

The balance should also be available as a PlaceholderAPI placeholder if possible:

%sbsmp_balance%

========================
2. PAY SYSTEM
=============

Create:

/pay  

Example:

/pay Steve 500

This transfers $500 from the sender to Steve.

Requirements:

* Sender must have enough money.
* Do not allow negative amounts.
* Do not allow 0 or invalid amounts.
* Do not allow paying yourself.
* Check that the target player exists.
* Remove the money from sender.
* Add the money to receiver.
* Save both balances.

Messages should clearly show the transaction.

Example sender:

You paid Steve $500.00.

Example receiver:

You received $500.00 from Danielius.

Add permission:

sbsmp.pay

Play a short configurable sound when a payment succeeds.

========================
3. ADMIN ECONOMY COMMANDS
=========================

Create console/admin commands:

/deposit  

/remove  

These should add/remove money without requiring the player to be online if possible.

Permissions:

sbsmp.admin.deposit
sbsmp.admin.remove

Only administrators should have these permissions.

Also make optional:

/setbal  

Permission:

sbsmp.admin.setbal

========================
4. SHOP SYSTEM
==============

Create:

/shop

Open a custom GUI shop.

The shop should be a configurable inventory GUI.

Use categories such as:

Blocks
Ores
Farming
Nether
End
Combat
Miscellaneous

Players click an item to open its purchase menu.

Each item needs configurable:

* Material
* Display name
* Description/lore
* Buy price
* Maximum purchase amount
* GUI slot
* Category
* Permission if needed

Example:

Obsidian
Buy price: $700 per item

Kelp
Buy price: $40 per item

Bonemeal
Buy price: configurable

When purchasing:

* Check balance.
* Check inventory space.
* Remove the correct amount of money.
* Give the correct amount of items.
* Update the balance immediately.
* Play a purchase sound.
* Show the amount purchased and money spent.

========================
5. SELL SYSTEM
==============

Create:

/sell

The /sell GUI should allow players to place items into a selling inventory.

VERY IMPORTANT:

Players should NOT sell items directly by typing an item name.

Instead:

/sell

opens a GUI where the player can place items from their inventory into the sell area.

The GUI should have a clearly defined item input area.

Players place items into the sell slots.

The plugin detects every sellable item and calculates how much the player will receive.

Example:

Player puts:

64 Kelp

into the sell GUI.

If Kelp sells for $40 each:

64 × $40 = $2,560.00

The GUI should display:

You will receive:
$2,560.00

There should be a large GREEN STAINED GLASS PANE / GREEN GLASS button labelled:

SELL

Example lore:

Click to sell all items

Total:
$2,560.00

When the player clicks the green SELL button:

* Remove the items from the sell GUI.
* Add the calculated money to the player's SBSMP balance.
* Play a configurable sell sound.
* Show a confirmation message.

Example:

Sold 64 Kelp for $2,560.00.

The GUI should update the total automatically whenever items are added or removed.

If an item is not sellable:

* Do not give money for it.
* Clearly indicate that it cannot be sold.
* Do not delete the item.

The player must be able to take their items back out of the GUI before selling.

========================
6. SELL GUI DESIGN
==================

Make the GUI similar to a modern DonutSMP-style economy GUI.

Use:

GREEN STAINED GLASS PANE
for the main SELL button.

The button should show:

SELL ITEMS

Total:
$2,560.00

Also add a RED STAINED GLASS PANE button:

CANCEL

Clicking CANCEL should return all deposited items to the player's inventory.

The GUI should prevent players from accidentally losing items.

Add a configurable title such as:

SELL ITEMS

Use a clean, modern GUI layout.

========================
7. SHOP ITEM FORMAT
===================

Make every shop item configurable like:

obsidian:
slot: 9
purchase-inventory-title: 'ʙᴜʏɪɴɢ ᴏʙsɪᴅɪᴀɴ'
displayName: '&fObsidian'
material: OBSIDIAN
price: 700
max-stack: 64

Also support:

kelp:
slot: 10
displayName: '&fKelp'
material: KELP
price: 40
max-stack: 64

The same item configuration should support both buying and selling where appropriate.

========================
8. SCOREBOARD
=============

Create a configurable SBSMP scoreboard.

Example:

&f&lSWEETBLOSSOM
&8&m----------------
&fPlayer: &d%player_name%
&fBalance: &a$%sbsmp_balance%
&fOnline: &f%server_online%
&8&m----------------
&dplay.sbsmp.net

IMPORTANT:
The BALANCE line must use the SBSMP custom economy balance, NOT EssentialsX balance.

Balance should update automatically when:

* Player receives money.
* Player pays someone.
* Player buys something.
* Player sells something.
* Admin deposits money.
* Admin removes money.

========================
9. NUMBER FORMAT
================

Use exactly:

$0.00

Examples:

$1.00
$40.00
$700.00
$2,560.00
$132,500.25
$1,000,000.00

Do not use:
132,34
1.000,00
$1.2

Always use two decimal places.

========================
10. PERMISSIONS
===============

Use these permission nodes:

sbsmp.balance
sbsmp.balance.others
sbsmp.pay
sbsmp.shop
sbsmp.sell

Admin:

sbsmp.admin.deposit
sbsmp.admin.remove
sbsmp.admin.setbal

Do NOT automatically give these permissions to everyone.

========================
11. CONFIGURATION
=================

Everything should be configurable:

* Shop items
* Buy prices
* Sell prices
* GUI titles
* GUI slots
* GUI materials
* Messages
* Sounds
* Scoreboard
* Currency symbol
* Decimal places
* Thousands separator
* Permissions

Example:

currency:
symbol: "$"
decimal-places: 2
thousands-separator: ","
decimal-separator: "."

========================
12. DATA SAFETY
===============

Balances must survive:

* Server restart
* Plugin reload
* Player leaving
* Player joining

Use UUIDs rather than player names for balance storage.

Prevent duplication exploits.

When selling items:

* Calculate the amount before removing items.
* Only remove items after the transaction has been successfully validated.
* Never allow players to create money by manipulating the GUI.

When buying:

* Check the balance before giving items.
* Check inventory space.
* Complete the transaction atomically.

========================
13. COMMANDS SUMMARY
====================

/bal
/balance
/bal 

/pay  

/shop

/sell

/deposit  
/remove  
/setbal  

========================
14. IMPORTANT SBSMP REQUIREMENT
===============================

This is for SweetBlossomSMP.

The economy must be a CUSTOM SBSMP economy system.

Do not connect the main balance to EssentialsX.

Do not use EssentialsX /bal.

Do not use Vault as the actual balance storage.

The scoreboard, /bal, /pay, /shop, /sell, deposit and remove commands must all use the SAME SBSMP balance database/API.

Create clean Java code with separate classes for:

* EconomyManager
* BalanceStorage
* BalanceFormatter
* BalancePlaceholder
* PayCommand
* BalanceCommand
* ShopCommand
* SellCommand
* SellGUI
* ShopGUI
* EconomyAdminCommand
* ScoreboardManager
* ConfigurationManager

Make the plugin modular so more economy features can be added later.
Kodari AI
KodariSep 17 at 5:37 pm 2
SweetBlossomEconomy
A custom economy plugin for SweetBlossomSMP Paper servers featuring a persistent UUID-based balance system with /bal, /pay, /deposit, /remove, and /setbal commands. Includes a configurable GUI shop with categories and buy prices, an interactive sell GUI with automatic total calculation and safe item handling, PlaceholderAPI integration, and a live-updating scoreboard. All balances stored independently of EssentialsX and Vault, formatted with configurable currency symbols and decimal separators. Modular architecture with EconomyManager, BalanceStorage, BalanceFormatter, BalancePlaceholder, PayCommand, BalanceCommand, ShopCommand, SellCommand, SellGUI, ShopGUI, EconomyAdminCommand, ScoreboardManager, and ConfigurationManager classes. Full LuckPerms permission support and config.yml customization for prices, GUI layouts, messages, and sounds.
  1. Create the Paper 1.21.11/Java 21 Gradle project and plugin metadata.

  2. Implement UUID-backed SBSMP balances, formatting, commands, permissions, and optional PlaceholderAPI support.

  3. Implement configurable shop purchasing and protected sell GUI flows.

  4. Add scoreboard updates, configuration defaults, sounds, messages, and GUI event routing.

Implemented the SweetBlossomSMP custom economy plugin from scratch with:

  • UUID-based persistent balances in balances.yml

  • /bal, /balance, /pay

  • /deposit, /remove, /setbal

  • Configurable shop and purchase menus

  • Protected sell GUI with sell/cancel controls

  • Configurable prices, materials, messages, sounds, permissions, and formatting

  • Custom SBSMP balance formatting such as $1,250.50

  • Optional PlaceholderAPI placeholder: %sbsmp_balance%

  • Configurable sidebar scoreboard using the custom SBSMP balance

  • Paper 1.21.11 and Java 21 project setup

  • LuckPerms-compatible permission nodes

  • Transaction validation for purchases, payments, and sales

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
22 1,480
src/main/java/com/sweetblossom/sbsmp/SweetBlossomSMP.java
package com.sweetblossom.sbsmp;

import com.sweetblossom.sbsmp.command.BalanceCommand;
import com.sweetblossom.sbsmp.command.EconomyAdminCommand;
import com.sweetblossom.sbsmp.command.PayCommand;
import com.sweetblossom.sbsmp.command.SellCommand;
import com.sweetblossom.sbsmp.command.ShopCommand;
import com.sweetblossom.sbsmp.config.ConfigurationManager;
import com.sweetblossom.sbsmp.economy.BalanceFormatter;
import com.sweetblossom.sbsmp.economy.EconomyManager;
import com.sweetblossom.sbsmp.gui.GuiListener;
import com.sweetblossom.sbsmp.placeholder.BalancePlaceholder;
import com.sweetblossom.sbsmp.scoreboard.ScoreboardManager;
import com.sweetblossom.sbsmp.storage.BalanceStorage;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Objects;

public final class SweetBlossomSMP extends JavaPlugin {
    private ConfigurationManager configurationManager;
    private BalanceStorage balanceStorage;
    private BalanceFormatter balanceFormatter;
    private EconomyManager economyManager;
    private ScoreboardManager scoreboardManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        configurationManager = new ConfigurationManager(this);
        balanceStorage = new BalanceStorage(this);
        balanceFormatter = new BalanceFormatter(configurationManager);
        economyManager = new EconomyManager(balanceStorage, balanceFormatter, configurationManager);
        scoreboardManager = new ScoreboardManager(this, economyManager, configurationManager);

        Bukkit.getPluginManager().registerEvents(new GuiListener(), this);
        Bukkit.getPluginManager().registerEvents(scoreboardManager, this);
        scoreboardManager.start();

        registerCommands();
        if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
            new BalancePlaceholder(this).register();
        }
    }

    @Override
    public void onDisable() {
        if (scoreboardManager != null) {
            scoreboardManager.stop();
        }
        if (balanceStorage != null) {
            balanceStorage.save();
        }
    }

    private void registerCommands() {
        BalanceCommand balanceCommand = new BalanceCommand(this);
        ShopCommand shopCommand = new ShopCommand(this);
        SellCommand sellCommand = new SellCommand(this);
        Objects.requireNonNull(getCommand("bal")).setExecutor(balanceCommand);
        Objects.requireNonNull(getCommand("pay")).setExecutor(new PayCommand(this));
        Objects.requireNonNull(getCommand("shop")).setExecutor(shopCommand);
        Objects.requireNonNull(getCommand("sell")).setExecutor(sellCommand);
        EconomyAdminCommand adminCommand = new EconomyAdminCommand(this);
        for (String name : new String[]{"deposit", "remove", "setbal"}) {
            PluginCommand command = Objects.requireNonNull(getCommand(name));
            command.setExecutor(adminCommand);
            command.setTabCompleter(adminCommand);
        }
    }

    public ConfigurationManager configuration() {
        return configurationManager;
    }

    public BalanceStorage balanceStorage() {
        return balanceStorage;
    }

    public BalanceFormatter balanceFormatter() {
        return balanceFormatter;
    }

    public EconomyManager economy() {
        return economyManager;
    }
}