ShadowDriftXD

Create a production-ready standalone Paper plugin called "Auction".

Target:

  • Minecraft 1.21.11
  • Paper
  • Java
  • Runs on Paper servers behind Velocity
  • MySQL/MariaDB
  • Vault-compatible economy
  • LuckPerms-compatible permissions
  • Plugin name must simply be "Auction"

Create an Auction House similar in general functionality to DonutSMP's "/ah".

COMMANDS:

/ah /ah sell <price> /ah selling /ah expired /ah cancel <id>

Make aliases configurable.

LISTING:

Players can list the item they are currently holding.

Example: "/ah sell 5000"

Validate:

  • Player is holding an item
  • Price is greater than zero
  • Player has permission
  • Item can be safely removed

Preserve complete ItemStack data, including enchantments, lore, names, attributes, custom model data and item components.

GUI:

"/ah" opens a paginated Auction House GUI.

Display:

  • Item
  • Price
  • Seller
  • Time remaining

Include:

  • Pagination
  • Previous/next
  • Refresh
  • Close
  • Categories
  • Price sorting
  • Newest sorting

Categories:

  • Weapons
  • Armor
  • Tools
  • Blocks
  • Ores
  • Food
  • Miscellaneous

Clicking a listing opens a confirmation GUI.

PURCHASE:

When purchasing:

  1. Verify the listing still exists.
  2. Verify the item still exists.
  3. Verify the buyer has enough money.
  4. Verify the buyer can receive the item.
  5. Withdraw money.
  6. Give the item to the buyer.
  7. Pay the seller.
  8. Remove the listing.

Prevent double purchases and GUI race conditions.

If inventory is full, do not charge the buyer.

SELLER FEATURES:

Players can:

  • View active listings
  • Cancel their own listings
  • View expired listings
  • Reclaim expired items

EXPIRATION:

Make auction duration configurable.

When an auction expires:

  • Remove it from active listings.
  • Store the item as expired.
  • Allow the seller to reclaim it.

DATABASE:

Use MySQL/MariaDB.

Store:

  • Listing ID
  • Seller UUID
  • Seller name
  • ItemStack data
  • Price
  • Server name
  • Creation time
  • Expiration time
  • Status

ECONOMY:

Use Vault.

Make transactions safe against:

  • Server crashes
  • Disconnects
  • Double purchases
  • Economy failures
  • Inventory-full situations

PERMISSIONS:

auction.use auction.sell auction.cancel auction.admin

ADMIN:

/auctionadmin reload /auctionadmin remove <id>

Make GUI titles, items, slots, sounds and messages configurable.

Provide:

  • Complete source code
  • plugin.yml
  • config.yml
  • Database implementation
  • Vault integration
  • GUI system
  • Commands
  • Item serialization
  • README
  • Build instructions

Keep Auction completely independent from Homes and Orders.

Kodari AI
KodariSep 23 at 4:53 am 2
AuctionHouse
A comprehensive auction house plugin for Paper servers featuring a paginated GUI with categories, sorting, and search. Players can list items from their hand with full metadata preservation, browse and purchase listings, manage active and expired auctions, and reclaim expired items. Includes MySQL persistence, Vault economy integration, LuckPerms permissions, configurable durations and aliases, admin commands, and crash-safe transaction handling with race condition prevention. Features configurable GUI titles, items, slots, sounds, and messages. Fully independent plugin with complete source, plugin.yml, config.yml, database schema, and build instructions.
  1. Set up the Paper 1.21.11/Java 21 project and configurable plugin metadata.

  2. Build MySQL persistence, item serialization, Vault-backed listing/purchase flows, and expiry handling.

  3. Add player/admin commands, paginated GUIs, configurable messages/items/sounds, and setup documentation.

Created the Auction Paper plugin project with Java 21 build configuration, plugin metadata, configurable GUI and messages, MySQL/MariaDB persistence, Vault economy integration, item serialization, player/admin commands, and README setup instructions.

The GUI includes pagination, categories, newest/price sorting, listing confirmation, seller listings, cancellation, and expired-item reclaim. /ah aliases are configurable; LuckPerms works through Bukkit permissions.

Transaction limitation: Vault cannot atomically coordinate economy changes with SQL and inventory updates. The plugin reserves listings to prevent concurrent purchases and leaves interrupted purchases locked as PENDING rather than risk a duplicate sale. Those rows require manual review after a crash; this limitation and recovery guidance are documented in the README. I did not run a build in this session.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
README.md
settings.gradle
Code
15 1,553
src/main/java/com/kodari/auction/AuctionPlugin.java
package com.kodari.auction;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;

public final class AuctionPlugin extends JavaPlugin {
    private HikariDataSource dataSource;
    private AuctionRepository repository;
    private AuctionService service;
    private AuctionGuiListener guiListener;
    private Economy economy;
    private ExecutorService databaseExecutor;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        if (!hookEconomy()) {
            getLogger().severe("No Vault economy provider is registered; Auction is disabling.");
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }
        try {
            HikariConfig hikari = new HikariConfig();
            hikari.setJdbcUrl(getConfig().getString("database.jdbc-url"));
            hikari.setUsername(getConfig().getString("database.username"));
            hikari.setPassword(getConfig().getString("database.password"));
            hikari.setMaximumPoolSize(Math.max(2, getConfig().getInt("database.pool-size", 10)));
            hikari.setMinimumIdle(1);
            hikari.setConnectionTimeout(10000);
            hikari.setPoolName("Auction-MySQL");
            dataSource = new HikariDataSource(hikari);
            repository = new AuctionRepository(dataSource);
            repository.initialize();
        } catch (Exception exception) {
            getLogger().severe("Could not initialize the Auction database: " + exception.getMessage());
            if (dataSource != null) {
                dataSource.close();
            }
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }
        databaseExecutor = Executors.newFixedThreadPool(4, runnable -> {
            Thread thread = new Thread(runnable, "Auction-Database");
            thread.setDaemon(true);
            return thread;
        });
        service = new AuctionService(this, repository);
        guiListener = new AuctionGuiListener(this, service, repository);
        Bukkit.getPluginManager().registerEvents(guiListener, this);
        Bukkit.getPluginManager().registerEvents(new AuctionAliasListener(this), this);
        getCommand("ah").setExecutor(new AuctionCommand(this, service));
        getCommand("ah").setTabCompleter(new AuctionCommand(this, service));
        getCommand("auctionadmin").setExecutor(new AuctionAdminCommand(this, service));
        getCommand("auctionadmin").setTabCompleter(new AuctionAdminCommand(this, service));
        Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
            try {
                repository.expireListings(System.currentTimeMillis());
            } catch (SQLException exception) {
                getLogger().warning("Could not expire auction listings: " + exception.getMessage());
            }
        }, 20L, 1200L);
        getLogger().info("Auction enabled. Shared MySQL storage is ready.");
    }

    private boolean hookEconomy() {
        if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
            return false;
        }
        RegisteredServiceProvider<Economy> registration = getServer().getServicesManager().getRegistration(Economy.class);
        if (registration == null) {
            return false;
        }
        economy = registration.getProvider();
        return economy != null;
    }

    @Override
    public void onDisable() {
        if (databaseExecutor != null) {
            databaseExecutor.shutdown();
        }
        if (dataSource != null) {
            dataSource.close();
        }
    }

    public <T> void submit(Callable<T> action, Consumer<T> success, Consumer<Throwable> failure) {
        databaseExecutor.execute(() -> {
            T value;
            try {
                value = action.call();
            } catch (Throwable throwable) {
                getLogger().warning("Auction database operation failed: " + throwable.getMessage());
                dispatch(() -> failure.accept(throwable));
                return;
            }
            dispatch(() -> success.accept(value));
        });
    }

    private void dispatch(Runnable callback) {
        if (!isEnabled()) {
            return;
        }
        Bukkit.getScheduler().runTask(this, () -> {
            if (isEnabled()) {
                callback.run();
            }
        });
    }

    public void message(CommandSender recipient, String key) {
        message(recipient, key, Map.of());
    }

    public void message(CommandSender recipient, String key, Map<String, String> replacements) {
        String prefix = getConfig().getString("messages.prefix", "");
        String text = getConfig().getString("messages." + key, "&cMissing message: " + key);
        for (Map.Entry<String, String> replacement : replacements.entrySet()) {
            text = text.replace("{" + replacement.getKey() + "}", replacement.getValue());
        }
        recipient.sendMessage(color(prefix + text));
    }

    public String color(String text) {
        return ChatColor.translateAlternateColorCodes('&', text);
    }

    public String formatPrice(double price) {
        return economy.format(price);
    }

    public ItemStack menuItem(String path, String fallbackMaterial, Map<String, String> replacements) {
        String material = getConfig().getString("gui.items." + path + ".material", fallbackMaterial);
        ItemStack item = XMaterial.matchXMaterial(material)
                .map(XMaterial::parseItem)
                .orElseGet(() -> XMaterial.matchXMaterial(fallbackMaterial).map(XMaterial::parseItem).orElse(null));
        if (item == null) {
            return null;
        }
        ItemMeta meta = item.getItemMeta();
        if (meta != null) {
            String name = getConfig().getString("gui.items." + path + ".name", "&f" + path);
            meta.setDisplayName(color(replace(name, replacements)));
            List<String> lore = new ArrayList<>();
            for (String line : getConfig().getStringList("gui.items." + path + ".lore")) {
                lore.add(color(replace(line, replacements)));
            }
            meta.setLore(lore);
            item.setItemMeta(meta);
        }
        return item;
    }

    public String replace(String text, Map<String, String> replacements) {
        for (Map.Entry<String, String> replacement : replacements.entrySet()) {
            text = text.replace("{" + replacement.getKey() + "}", replacement.getValue());
        }
        return text;
    }

    public void playSound(Player player, String key) {
        String sound = getConfig().getString("gui.sounds." + key, "UI_BUTTON_CLICK");
        XSound.matchXSound(sound).ifPresent(xSound -> xSound.play(player));
    }

    public AuctionRepository repository() {
        return repository;
    }

    public AuctionGuiListener guiListener() {
        return guiListener;
    }

    public Economy economy() {
        return economy;
    }

    public String serverName() {
        return getConfig().getString("server-name", "server-1");