damnsarthak
📎 1 file 1,642 chars
📄
pasted-code-1777985350141.txt
txt 73 lines
▶
Create a Minecraft Spigot/Paper plugin (Java) named "TapBankAPI".

Purpose: Economy + Banking + Stock Market system with API for web/mobile apps.

Dependencies: Vault (required), EssentialsX (optional).

Command:
/tapi (permission: tapbank.admin, OP only)

* Generates UUID API key
* Saves in config.yml
* Sends: "API Key:  (Use in Authorization: Bearer )"

API Server:

* Embedded HTTP server (default port 8080, configurable)
* All requests require header: Authorization: Bearer 
* Rate limit + log all requests

Basic Endpoints:
GET /balance?player=
POST /pay {from,to,amount}
GET /baltop

Stock Market System:

* Stocks: DIAMOND_CORP (DMC), GOLD_INC (GLD), NETHERITE_LTD (NTH), EMERALD_BANK (EMB)
* Each stock: price, volatility, trend
* Auto price update every X seconds:
  price += random(-volatility,+volatility)

Player Portfolio:

* Stored in YAML/SQLite
* Tracks owned stocks

Commands:
/stock list → show stocks
/stock buy  
/stock sell  
/stock portfolio

Stock API:
GET /stocks → list prices
GET /portfolio?player=
POST /buyStock {player,symbol,amount}
POST /sellStock {player,symbol,amount}

Bank Features:

* Deposit/Withdraw
* Transaction history
* Optional interest system

Security:

* Validate API key
* Prevent invalid/negative trades

Config.yml:

* API port
* API keys
* stock update interval
* volatility values
* feature toggles

Structure:
Main, APIController, EconomyManager, StockManager, CommandHandler, DataStorage

Goal:
Secure real-time bank + stock system connected to external web app.
Kodari AI
KodariMay 5 at 12:51 pm 17,511 (v2)

I’ll create a comprehensive economy and banking plugin with a stock market system and REST API integration.

TapBankAPI
A comprehensive economy and banking plugin with integrated stock market system and REST API for external web/mobile applications. Features real-time stock trading with dynamic price updates, player portfolios, transaction management, and secure API endpoints protected by bearer token authentication. Integrates with Vault for economy operations and provides rate-limited HTTP access for remote balance queries, payments, and stock operations.

Perfect! I’ve created TapBankAPI - a comprehensive economy and stock market system with REST API support.

What’s Included:

Core Features:

  • ✅ Vault integration for economy operations

  • ✅ Embedded HTTP server (port 8080, configurable)

  • ✅ Bearer token authentication for all API endpoints

  • ✅ Rate limiting (30 req/min per IP)

  • ✅ Stock market with 4 stocks (DMC, GLD, NTH, EMB)

  • ✅ Dynamic price updates with volatility and trends

  • ✅ Player portfolios saved to YAML

Commands:

  • /tapi - Generate API keys (admin only)

  • /stock list - View all stocks and prices

  • /stock buy <symbol> <amount> - Buy stocks

  • /stock sell <symbol> <amount> - Sell stocks

  • /stock portfolio - View owned stocks

API Endpoints:

  • GET /balance?player=<name> - Get player balance

  • POST /pay - Transfer money (JSON: from, to, amount)

  • GET /baltop - Top 10 richest players

  • GET /stocks - All stock prices

  • GET /portfolio?player=<name> - Player’s stock holdings

  • POST /buyStock - Buy stocks via API (JSON: player, symbol, amount)

  • POST /sellStock - Sell stocks via API (JSON: player, symbol, amount)

Security:

  • API key validation on all endpoints

  • Rate limiting with 429 responses

  • Request logging built-in

  • Negative amount validation

All endpoints require: Authorization: Bearer <API_KEY>

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
15 1,324
src/main/java/com/example/tapbankapi/TapBankAPI.java
package com.example.tapbankapi;

import com.example.tapbankapi.api.APIServer;
import com.example.tapbankapi.command.StockCommand;
import com.example.tapbankapi.command.TapAPICommand;
import com.example.tapbankapi.config.ConfigManager;
import com.example.tapbankapi.data.DataStorage;
import com.example.tapbankapi.economy.EconomyManager;
import com.example.tapbankapi.stock.StockManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class TapBankAPI extends JavaPlugin {
    
    private ConfigManager configManager;
    private EconomyManager economyManager;
    private StockManager stockManager;
    private DataStorage dataStorage;
    private APIServer apiServer;
    
    @Override
    public void onEnable() {
        this.configManager = new ConfigManager(this);
        this.configManager.loadConfig();
        
        this.economyManager = new EconomyManager(this);
        if (!this.economyManager.setupEconomy()) {
            getLogger().severe("Vault not found! Disabling plugin.");
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }
        
        this.dataStorage = new DataStorage(this);
        this.dataStorage.loadData();
        
        this.stockManager = new StockManager(this);
        this.stockManager.initialize();
        this.stockManager.startPriceUpdates();
        
        getCommand("tapi").setExecutor(new TapAPICommand(this));
        getCommand("stock").setExecutor(new StockCommand(this));
        
        if (this.configManager.isApiEnabled()) {
            this.apiServer = new APIServer(this);
            this.apiServer.start();
        }
        
        getLogger().info("TapBankAPI has been enabled!");
    }
    
    @Override
    public void onDisable() {
        if (this.stockManager != null) {
            this.stockManager.stopPriceUpdates();
        }
        
        if (this.dataStorage != null) {
            this.dataStorage.saveData();
        }
        
        if (this.apiServer != null) {
            this.apiServer.stop();
        }
        
        getLogger().info("TapBankAPI has been disabled!");
    }
}