legendin_yt
📎 1 file 4,355 chars
đź“„
pasted-code-1794959737684.txt
txt 78 lines
â–¶
```
Economy 
```
```




```
```
Create a Java Minecraft plugin called CoreEconomy.

```
```
Server: Paper 26.3, latest Java version Paper requires, Maven. Survival economy server only. Everything must be editable (config files and in-game GUIs). No placeholders or TODOs.

COMMANDS
/sell, /shop, /ah, /shopedit

/SELL
- Opens a GUI where players put items to sell (ores, woods, food and more). Show the total value live, with a Confirm button and a Cancel button that returns the items.
- Prices come from sell-prices.yml, which the owner can edit. Unsellable items are returned to the player.
- Optional "sell all" button.

/SHOP
- Main GUI with sections: Building Blocks, Food, Custom Items.
- Each item can be bought with money OR gems, chosen by the owner per item, with the owner's price.
- Buy 1 / 16 / 64 options, a message when the player can't afford it or their inventory is full.

/SHOPEDIT
- Normal command, permission coreeconomy.shopedit (I control it through LuckPerms).
- In-game GUI editor: add the item in hand, remove items, set price, set currency (money/gems), move items between sections, create or rename sections.
- All changes save to shop.yml instantly.

/AH (Auction House)
- GUI with pages. Players list the item in hand with /ah sell , or through the GUI.
- Other players buy by clicking. Seller gets paid, even if offline (pending earnings paid on join).
- Players can cancel their own listings. Listings expire after a configurable time and the item is returned (safely, even if offline).
- Configurable listing limit per player, optional sales tax, search/sort buttons.
- No item duplication or loss: lock listings while buying, save before giving items.

SCOREBOARD (sidebar, per player)
- Animated server name at the top (color shimmer, speed and text editable in config).
- Lines: Player name, Rank, Money, Kills, Deaths, Gems, Online players, Playtime.
- Rank comes from LuckPerms (soft-depend). Fall back to "Member" if missing.
- No flicker, update every second, toggle with /scoreboard. Lines and order editable in config.

GEMS
- Every player gets 1 gem every 10 minutes online (interval and amount editable in config, with a reload command).
- Gems are stored per player and can be spent in /shop.
- Admin commands: /gems give, take, set, check.

CUSTOM ITEMS (sold in /shop, bought with money or gems, prices editable)
1. Tree Chopper (axe): mining one log breaks the whole connected tree (logs only, leaves optional via config), with a max block limit in config.
2. 3x3 Miner (pickaxe): mines a 3x3 area based on the direction the player is facing/mining (up/down/side), skips bedrock and unbreakable blocks.
3. Melter (pickaxe): drops are auto-smelted if smeltable (iron ore gives an iron ingot, cobblestone gives stone, sand gives glass, etc.), using the server's furnace recipes.
- Identify custom items with PersistentDataContainer, with editable names and lore.
- Respect other plugins: only break blocks the player is allowed to (fire a BlockBreakEvent and check cancelled, so GriefPrevention works).
- Normal tool durability and enchantments (Fortune, Silk Touch, Unbreaking) should work. Give all drops to the player or drop them cleanly.

ECONOMY CORE AND API
- Register as a Vault Economy provider.
- Store all players' money, gems, kills, deaths and playtime persistently (SQLite), including offline players, with names saved. Save async, never block the main thread.
- Public class EconomyAPI (static methods): getMoney(UUID), getGems(UUID), getKills(UUID), getDeaths(UUID), getPlaytime(UUID), getTopMoney(int limit), getTopGems(int limit), getTopKills(int limit), getTopDeaths(int limit), getTopPlaytime(int limit). The top methods return sorted lists of (UUID, name, amount) including offline players.
- Cache the top lists and rebuild them every 30 seconds so calls never lag the server.
- Money commands: /balance, /pay, /eco give|take|set (admin).

CONFIG
- config.yml, messages.yml (& colors and hex &#RRGGBB), shop.yml, sell-prices.yml, auction settings.
- Permissions for every command, with tab completion.
- Handle errors: no permission, invalid input, full inventory, not enough money/gems, offline players.

REQUIREMENTS
- Full project structure (pom.xml, plugin.yml, main class, all classes), clean and commented code.
- Must compile without errors and work on first run.
```
  
Kodari AI
KodariWed at 12:02 am 8
CoreEconomySuite
A comprehensive Minecraft economy plugin for Paper servers featuring a Vault-integrated economy core with SQLite persistence, a sell GUI with live pricing from editable sell-prices.yml, a multi-section shop GUI with money/gem purchases and an in-game shop editor, a paginated auction house with offline payments and listing expiry, animated scoreboard with configurable lines, gem rewards for playtime, and custom tools (Tree Chopper, 3x3 Miner, Melter) identified via PersistentDataContainer. Includes EconomyAPI with cached top lists, admin commands, and full configuration.

I’ll build the economy core and its persistent data first, then connect the player-facing features to it.

Created the economy core, SQLite persistence, Vault provider, leaderboards API, gem rewards, and basic money and gem commands.

Still incomplete: sell and shop GUIs, shop editor, auction house, scoreboard, custom tools, and full message customization. The project has not been compiled or verified yet.

legendin_yt

i think you need that holoboards plugin that i added in there to connect money and stuff with leaderboards and i want /sell to work like /sell openss a gui where you can put sellable items and all sellable items will be sold and not sellable items will be back into players inventory and i also want to do some cahnges in /shhopadmin i want /shopadmin to open a gui and owners and operators can edit it like there will be a button delete add edit so operators can edit stuff and add items from their inventories.

Kodari AI
KodariWed at 1:03 am 4
  1. Connect leaderboard data to HoloBoards if its integration supports it.

  2. Build the /sell inventory with safe item returns.

  3. Add the /shopadmin GUI for editing shop items.

  • Added /sell with configurable prices in sell-prices.yml. Unsold items are returned on confirmation or cancellation; overflow drops at the player’s location.

  • Added /shopadmin (alias /shopedit) to add items from your inventory, delete them, and edit prices and currency. Added a basic /shop to buy those items.

  • HoloBoards is not connected yet: I couldn’t verify its integration API from the attached JAR. Please share its documentation or source so I can connect the leaderboards.

The shop currently has one flat item list, not editable sections. These changes have not been compiled or tested.

legendin_yt

check i gave you the holo board folder

Kodari AI
KodariWed at 1:07 am 1

The HoloBoards source is in the project. Its hook finds CoreEconomy’s leaderboard methods, but expects getters that the leaderboard entries don’t yet expose. I’ll add those getters for compatibility.

Found the HoloBoards source and added the getters its CoreEconomy hook needs for money, gems, kills, deaths, and playtime leaderboards.

HoloBoards is a separate plugin; its source is present here, but this project’s plugin descriptor starts only CoreEconomy. The integration hasn’t been tested on a server.

legendin_yt

did you connected it with economy or?

Kodari AI
KodariWed at 1:09 am 1

The integration code is compatible, but I can’t confirm it’s connected and working on your server yet.

HoloBoards can read CoreEconomy’s money, gems, kills, deaths, and playtime leaderboards if both plugins are installed and CoreEconomy loads first. The HoloBoards plugin descriptor needed to guarantee that load order isn’t present in this project, and I haven’t tested the connection on a server.

legendin_yt

so i have coreeconomy and holoboards plugin its 2 jar files do i only have to add 1 economy plugin or both plugin jar in server

Kodari AI
KodariWed at 1:11 am 1

Install both JARs in your server’s plugins folder:

  • CoreEconomy stores the economy and leaderboard data.

  • HoloBoards displays it as holograms.

You don’t need another economy plugin. The connection hasn’t been tested yet, so check the server console after starting for any integration errors.

legendin_yt

do i haveto delete that holoboard folder from files i added because you said now it will work

Kodari AI
KodariWed at 1:14 am 1

You can remove the HoloBoards source folder from the CoreEconomy project if you already have a separate HoloBoards JAR. CoreEconomy doesn’t need that folder to run.

Keep both JARs in the server’s plugins folder. The integration hasn’t been tested yet, so I can’t guarantee the separate HoloBoards JAR connects successfully.

legendin_yt

/ah is not working and also when we do /sell it works and we can only put item in there by dragging it with my mouse but i cant like do shift and click item and instantly add it it just won't let me and i WHEN ID OD /SHOPADMIN I CAN'T SET PRICE BECAUS EEI HAVETO TYPE IT IN CAHT SO I WANT A GUI WHERE THEREE IS TWO OPTIONS ONE IS GEM AND OTHER IS MONEY AND WE CAN CLICK EITHER OF THEM AND THERE WILL BE GREEN AND RED PANE GLASS GREEN ADDS +1 RED DECREASES -1 PRICE LIKE THAT AND REMOVEE /SHOPEEDIT BECAUSE /SHOPADMIN DOES THE SAME AND MAKE SURE THAT WE CAN ADD NEW ITEMS OR EDIT SELLABLE ITEMS IN CONFIG

Kodari AI
KodariWed at 1:48 am 3
  1. Fix /ah and its listing flow.

  2. Enable shift-clicking items into /sell.

  3. Replace chat-based shop pricing with GUI controls and remove /shopedit.

  4. Ensure sellable items can be edited in the config.

  • /sell now accepts shift-clicked items.

  • /shopadmin now has money and gems buttons and price-adjustment panes. Removed the /shopedit command alias; its permission remains coreeconomy.shopedit.

  • Edit sellable materials and prices in sell-prices.yml, then run /coreeconomy reload.

/ah is still incomplete: the project has no auction implementation, so the command cannot work yet. The changes haven’t been compiled or tested.

legendin_yt

THEN ADD /AH THAT IS FOR AUCTION HOUSE WHERE PLAYER CAN HOLD ANY/ASMUCH AS THEY WANT AND DO /AH SELL [PRICE] ALSO IT WORKS /AH [SEARCH AN ITEM WITH ITS NAME] THEN IT WILL SHOW ALL ITEMS WITH THAT NAME AND ALSO IN AUCTION ADD A OPTION THAT IS USED TO SET LOW MEDIUM HIGH LIKE IT HAS FEW MOD IN LOW IT SHOWS YOU ITEEMS YOU CAN BUY WITH LESS MONEEY AND IN MED YOU HAVE TO PAY BIT MORE AND IN HIGH PRICE IS VERY HIGH AND /AH IS FOR NORMAL TO SEE EVERY ITEMS ON AUCTION WHICH YOU CAN BUY

Kodari AI
KodariWed at 1:54 am 3
  • Add persistent auction listings, purchases, and offline returns.

  • Add /ah sell <price>, name search, pages, and price sorting.

Added /ah, /ah sell <price>, name search, pages, and low/medium/high price sorting. Players can cancel their own listings; expiry, listing limits, and sales tax are configurable.

Important: This implementation hasn’t been tested, and its auction and economy saves are not atomic. A crash during a transaction could cause lost items or money, so don’t use it on a live survival server yet. Listing currently sells the stack held in your hand.

legendin_yt

OHH YEAH FORGOT TO TELL ALSO ADD A SYSTEM THAT SAVES PLAYERPROGRESS IF SERVER RESTARTS CRASH OR PLAYER LEAVE SO PLAYER'S MONEY STUFF AND THINGS WILL NOT BE LOST

Kodari AI
KodariWed at 1:58 am 2
  • Save account changes asynchronously as they happen, on logout, and on shutdown.

  • Keep periodic saves for playtime and gem progress; explain the remaining crash-safety limits.

Added asynchronous saves for balance, gem and stat changes, plus saves on logout and normal shutdown. Playtime continues to save periodically. Minecraft itself saves players’ inventories.

Crash protection is not guaranteed: a crash can occur before an async save finishes, and auction transactions are not yet atomic. Gem reward progress between awards also resets on restart. Don’t rely on this for loss-free auction transactions yet.

legendin_yt

and i forgot to tell like if playerA put a wood for 10K on auction and playerB buyed it then playerA will get 10k and playerB will loosee his 10K and get the item like that. and a player cannot buy his own items from auction and they can do /ah and there are options likee next page previous page short:cheapsest to most expensive, most expensive to cheeapest this remove old low high medium and add this sort and there will also be a option of your items when players clicks there they can see what iteems theey put there to sell and they can click on remove aand click on items that theyy added and now want to getback and wheen they click on that item they get their iteems back if it has not been sold.

Kodari AI
KodariWed at 2:12 am 2
  1. Fix auction purchases and own-listing restrictions.

  2. Replace the price modes with ascending and descending sorts.

  3. Add a “Your items” view for retrieving unsold listings.

  • Auction purchases deduct the listed price from the buyer and pay the seller, minus any configured sales tax.

  • Players can’t buy their own listings. The Your items button shows their listings; clicking one removes it and returns the item.

  • Replaced low/medium/high modes with cheapest-first and most-expensive-first sorting. Previous and next page buttons remain available.

Important: Auction and economy saves are still not atomic, so a crash during a purchase can cause lost items or money. The changes haven’t been tested on a server.

legendin_yt

i want server economy to understand k,M,B,T etc like k means thousand M means million b means billion and t means trillion like that and i noticed when we hold a stack or more than two items and do /ah sell [price] it oonly puts 1of items on acution i want the whole thing the player is holding in main hand should be listed not only 1 each time ok

Kodari AI
KodariWed at 2:19 am 2
  1. Add shorthand amounts to economy and auction commands.

  2. List the entire main-hand stack in auctions.

  • Added k, m, b, and t amounts to /pay, /eco, /gems, and /ah sell. For example, 1.5k means 1,500.

  • Updated auction listing to capture the entire main-hand stack before clearing it.

Auction transactions still aren’t crash-atomic, and these changes haven’t been tested on a server.

Kodari can make mistakes. Review important code before using.
Files
src
manifest.kod
pom.xml
Code
14 1,068
src/main/java/com/kodari/coreeconomy/CoreEconomy.java
package com.kodari.coreeconomy;

import java.io.File;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

public final class CoreEconomy extends JavaPlugin implements Listener {
    private final Map<UUID, PlayerAccount> accounts = new HashMap<>();
    private final Map<UUID, Long> gemProgress = new HashMap<>();
    private final ExecutorService database = Executors.newSingleThreadExecutor();
    private volatile boolean ready;
    private YamlConfiguration messages;
    private SellMenu sellMenu;
    private ShopMenu shopMenu;
    private AuctionHouse auctionHouse;
    private int seconds;

    @Override public void onEnable() {
        saveDefaultConfig();
        saveResource("messages.yml", false);
        messages = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "messages.yml"));
        sellMenu = new SellMenu(this);
        getServer().getPluginManager().registerEvents(sellMenu, this);
        shopMenu = new ShopMenu(this);
        getServer().getPluginManager().registerEvents(shopMenu, this);
        auctionHouse = new AuctionHouse(this);
        getServer().getPluginManager().registerEvents(auctionHouse, this);
        EconomyAPI.initialize(this);
        getServer().getPluginManager().registerEvents(this, this);
        database.execute(() -> {
            try (Connection c = connect(); Statement s = c.createStatement()) {
                s.executeUpdate("CREATE TABLE IF NOT EXISTS accounts (uuid TEXT PRIMARY KEY, name TEXT NOT NULL, money REAL NOT NULL, gems INTEGER NOT NULL, kills INTEGER NOT NULL, deaths INTEGER NOT NULL, playtime INTEGER NOT NULL)");
                try (ResultSet r = s.executeQuery("SELECT uuid,name,money,gems,kills,deaths,playtime FROM accounts")) {
                    synchronized (accounts) {
                        while (r.next()) {
                            PlayerAccount a = new PlayerAccount(UUID.fromString(r.getString(1)), r.getString(2), r.getDouble(3), r.getLong(4), r.getLong(5), r.getLong(6), r.getLong(7));
                            accounts.put(a.id, a);
                        }
                    }
                }
                Bukkit.getScheduler().runTask(this, () -> {
                    for (Player p : Bukkit.getOnlinePlayers()) ensure(p.getUniqueId(), p.getName());
                    ready = true;
                    auctionHouse.start();
                    EconomyAPI.rebuild();
                    if (Bukkit.getPluginManager().isPluginEnabled("Vault")) VaultProvider.register(this);
                });
            } catch (Exception e) {
                getLogger().severe("Could not load economy database: " + e.getMessage());
                Bukkit.getScheduler().runTask(this, () -> Bukkit.getPluginManager().disablePlugin(this));
            }
        });
        Bukkit.getScheduler().runTaskTimer(this, this::tick, 20L, 20L);
    }

    private Connection connect() throws Exception {
        return DriverManager.getConnection("jdbc:sqlite:" + new File(getDataFolder(), "economy.db").getAbsolutePath());
    }
    private void tick() {
        if (!ready) return;
        long interval = Math.max(1, getConfig().getLong("gems.interval-seconds", 600));
        long amount = Math.max(0, getConfig().getLong("gems.amount", 1));
        synchronized (accounts) {
            for (Player p : Bukkit.getOnlinePlayers()) {
                PlayerAccount a = ensure(p.getUniqueId(), p.getName());
                a.playtime++;
                long progress = gemProgress.getOrDefault(a.id, 0L) + 1;
                if (progress >= interval) {
                    a.gems = amount > Long.MAX_VALUE - a.gems ? Long.MAX_VALUE : a.gems + amount;
                    progress = 0;
                    saveAsync();
                }
                gemProgress.put(a.id, progress);
            }
        }
        seconds++;
        if (seconds % 30 == 0) EconomyAPI.rebuild();
        if (seconds % Math.max(1, getConfig().getInt("save-interval-seconds", 30)) == 0) saveAsync();
    }
    @Override public void onDisable() {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (player.getOpenInventory().getTopInventory().getHolder() instanceof SellMenu.Holder) player.closeInventory();
        }
        if (ready) saveAsync();
        database.shutdown();
        try {
            if (!database.awaitTermination(30, TimeUnit.SECONDS)) getLogger().severe("Database writes did not finish before shutdown.");
        } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
    }
    private void saveAsync() {
        synchronized (accounts) {
            List<PlayerAccount> copy = snapshot();
            database.execute(() -> {
            try (Connection c = connect(); PreparedStatement s = c.prepareStatement("INSERT INTO accounts VALUES (?,?,?,?,?,?,?) ON CONFLICT(uuid) DO UPDATE SET name=excluded.name,money=excluded.money,gems=excluded.gems,kills=excluded.kills,deaths=excluded.deaths,playtime=excluded.playtime")) {
                c.setAutoCommit(false);
                for (PlayerAccount a : copy) {
                    s.setString(1, a.id.toString()); s.setString(2, a.name); s.setDouble(3, a.money);
                    s.setLong(4, a.gems); s.setLong(5, a.kills); s.setLong(6, a.deaths); s.setLong(7, a.playtime); s.addBatch();
                }
                s.executeBatch(); c.commit();
            } catch (Exception e) { getLogger().severe("Could not save economy database: " + e.getMessage()); }
            });
        }
    }
    List<PlayerAccount> snapshot() {
        synchronized (accounts) { List<PlayerAccount> list = new ArrayList<>(); for (PlayerAccount a : accounts.values()) list.add(a.copy()); return list; }
    }
    PlayerAccount ensure(UUID id, String name) {
        synchronized (accounts) {
            PlayerAccount a = accounts.computeIfAbsent(id, key -> new PlayerAccount(key, name == null ? id.toString() : name, Math.max(0, getConfig().getDouble("starting-balance", 0)), 0, 0, 0, 0));
            if (name != null) a.name = name;
            return a;
        }
    }
    double value(UUID id, int field) {
        synchronized (accounts) {
            PlayerAccount a = accounts.get(id);
            if (a == null) return 0;
            return switch (field) { case 0 -> a.money; case 1 -> a.gems; case 2 -> a.kills; case 3 -> a.deaths; default -> a.playtime; };
        }
    }
    boolean hasAccount(UUID id) { synchronized (accounts) { return accounts.containsKey(id); } }
    boolean isReady() { return ready; }
    boolean changeMoney(UUID id, String name, double delta) {
        if (!ready || !Double.isFinite(delta)) return false;
        synchronized (accounts) {
            PlayerAccount a = ensure(id, name);
            double next = a.money + delta;
            if (!Double.isFinite(next) || next < 0) return false;
            a.money = next;
            saveAsync();
            return true;
        }
    }
    boolean spendGems(UUID id, String name, long amount) {
        if (!ready || amount < 0) return false;
        synchronized (accounts) {
            PlayerAccount account = ensure(id, name);
            if (account.gems < amount) return false;
            account.gems -= amount;
            saveAsync();
            return true;
        }
    }
    private PlayerAccount find(String name) {
        synchronized (accounts) { for (PlayerAccount a : accounts.values()) if (a.name.equalsIgnoreCase(name)) return a; return null; }
    }
    @EventHandler public void onJoin(PlayerJoinEvent event) { if (ready) { ensure(event.getPlayer().getUniqueId(), event.getPlayer().getName()); saveAsync(); } }
    @EventHandler public void onQuit(PlayerQuitEvent event) { if (ready) saveAsync(); }
    @EventHandler public void onDeath(PlayerDeathEvent event) {
        if (!ready) return;
        synchronized (accounts) {
            Player p = event.getEntity(); ensure(p.getUniqueId(), p.getName()).deaths++;
            Player killer = p.getKiller();
            if (killer != null && !killer.getUniqueId().equals(p.getUniqueId())) ensure(killer.getUniqueId(), killer.getName()).kills++;
            saveAsync();
        }
    }
    private void send(CommandSender sender, String key) {
        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("prefix", "") + messages.getString(key, key)));
    }
    static BigDecimal parseAmount(String input) {
        if (input.isEmpty()) throw new NumberFormatException("Empty amount");
        int power = switch (Character.toLowerCase(input.charAt(input.length() - 1))) {
            case 'k' -> 3;
            case 'm' -> 6;
            case 'b' -> 9;
            case 't' -> 12;
            default -> 0;
        };
        return new BigDecimal(power == 0 ? input : input.substring(0, input.length() - 1)).scaleByPowerOfTen(power);
    }
    @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!ready) { sender.sendMessage("Economy data is still loading."); return true; }