Alex Melloni

Paper 1.21.8 Trade Plugin (Java 21)

Create a secure trade plugin with Vault economy.

1. Request

  • /trade <player> sends clickable text: [Accept] [Deny]. Expires in 30s.

2. GUI (54 slots)

  • Left (0-3, 9-12, 18-21, 27-30, 36-39): Initiator items.
  • Right (5-8, 14-17, 23-26, 32-35, 41-44): Target items.
  • Center (4,13,22,31,40): Gray Glass dividers.
  • Rules: Players can only edit their own side.

3. Money Offer

  • Slots 48 (Left) & 50 (Right): Oak Sign.
  • Click opens chat input for Vault balance.
  • Update lore: Offer: $<amount>.

4. Confirm & Safety

  • Slots 45 (Left) & 53 (Right): Accept button. Red Glass -> Green Glass.
  • Item/money edits reset both to Red.
  • Both Green: Check space (drop if full), swap items/Vault funds, close.
  • Anti-Dupe: GUI close, logoff, or death cancels trade and refunds items safely.
Kodari AI
KodariSep 16 at 7:17 pm 3
SecureTradeGUI
A secure player-to-player trading plugin with Vault economy integration. Features a 54-slot GUI with item exchange zones, gray glass dividers, and per-player item management. Includes money offers via oak sign buttons with chat input for Vault balance, lore updates showing offered amounts. Dual confirmation system with red-to-green accept buttons that reset on any trade modification. Anti-duplication safeguards cancel trades on GUI close, logout, or death, safely refunding items. Clickable trade requests with accept/deny options expiring after 30 seconds. Automatic inventory space checking with item dropping if full during trade completion.
  1. Create the Gradle/Paper/Vault project metadata.

  2. Implement trade requests, clickable accept/deny handling, and expiration.

  3. Implement the shared 54-slot trade session with side restrictions, money input, confirmations, refunds, and safe completion.

  4. Register commands/listeners and lifecycle cleanup.

  1. Created the Paper 1.21.8 / Java 21 Gradle project with Vault economy dependency and plugin metadata.

  2. Added /trade <player> requests with clickable Accept/Deny buttons and 30-second expiration.

  3. Implemented the 54-slot trade GUI with:

    • Separate editable item sides

    • Oak Sign money offers

    • Chat-based amount input

    • Red/green acceptance controls

    • Confirmation resets after item or money changes

  4. Added secure completion with Vault withdrawals/deposits, inventory delivery, full-inventory item drops, and rollback handling.

  5. Added cancellation/refunds for GUI close, disconnect, death, and plugin shutdown, plus command and event registration.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
trade luxury
Code
10 885
src/main/java/com/kodari/securetrade/SecureTradePlugin.java
package com.kodari.securetrade;

import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

public final class SecureTradePlugin extends JavaPlugin {
    private TradeManager tradeManager;

    @Override
    public void onEnable() {
        RegisteredServiceProvider<Economy> registration = getServer().getServicesManager().getRegistration(Economy.class);
        if (registration == null || registration.getProvider() == null) {
            getLogger().severe("Vault economy provider was not found.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }

        this.tradeManager = new TradeManager(this, registration.getProvider());
        TradeCommand command = new TradeCommand(tradeManager);
        getCommand("trade").setExecutor(command);
        getCommand("trade").setTabCompleter(command);

        TradeListener listener = new TradeListener(tradeManager);
        Bukkit.getPluginManager().registerEvents(listener, this);
        getLogger().info("SecureTrade enabled.");
    }

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