mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 15:03:30 +00:00
835 lines
27 KiB
Markdown
835 lines
27 KiB
Markdown
# CustomNPC+ 1.11 Market Update - Implementation Plan
|
||
|
||
## Overview
|
||
|
||
The 1.11 Market Update introduces a comprehensive economy system for CustomNPC+:
|
||
|
||
1. **Currency System** - Built-in CNPC+ currency with optional Vault integration
|
||
2. **Trader Enhancements** - Stock system, currency-based trades, reset timers
|
||
3. **Auction House** - Global auction system with bidding, buyout, and claims
|
||
|
||
---
|
||
|
||
## 1. Currency System
|
||
|
||
### Status: IMPLEMENTED
|
||
|
||
The currency system provides a unified economy for CNPC+ features.
|
||
|
||
### Features
|
||
- **Built-in CNPC+ Currency** - Stored in PlayerData, persists across profile slots
|
||
- **Vault Integration** - Optional, when enabled all operations use Vault instead
|
||
- **Scripting API** - Full access via `IPlayer` methods
|
||
|
||
### Key Files
|
||
| File | Purpose |
|
||
|------|---------|
|
||
| `PlayerCurrencyData.java` | Per-player currency storage, Vault delegation |
|
||
| `IPlayerCurrencyData.java` | API interface for currency operations |
|
||
| `ConfigMarket.java` | Currency configuration (UseVault, CurrencyName, StartingBalance, MaxBalance) |
|
||
| `VaultUtil.java` | Vault API integration via reflection |
|
||
|
||
### Configuration (ConfigMarket.java)
|
||
```
|
||
Market.Currency:
|
||
- Use Vault: false
|
||
- Currency Name: "Coins"
|
||
- Starting Balance: 0
|
||
- Max Balance: 2147483647
|
||
```
|
||
|
||
### Scripting API (IPlayer)
|
||
```javascript
|
||
player.getCurrencyBalance() // Get balance
|
||
player.setCurrencyBalance(amount) // Set balance
|
||
player.depositCurrency(amount) // Add currency (returns success)
|
||
player.withdrawCurrency(amount) // Remove currency (returns success)
|
||
player.canAffordCurrency(amount) // Check if can afford
|
||
player.isUsingVaultCurrency() // Check if Vault is active
|
||
player.getFormattedCurrencyBalance() // Get formatted string
|
||
```
|
||
|
||
---
|
||
|
||
## 2. Trader Enhancements
|
||
|
||
### Status: COMPLETE
|
||
|
||
---
|
||
|
||
### 2.1 Stock System - IMPLEMENTED
|
||
|
||
Traders can have limited stock that resets on configurable schedules.
|
||
|
||
#### Stock Modes
|
||
| Mode | Description | Status |
|
||
|------|-------------|--------|
|
||
| **Global** | All players share the same stock pool | ✅ Working |
|
||
| **Per-Player** | Each player has their own stock counts | ✅ Working |
|
||
|
||
#### Stock Reset Types (EnumStockReset)
|
||
| Type | Description | Status |
|
||
|------|-------------|--------|
|
||
| `NONE` | Stock never resets | ✅ Working |
|
||
| `MCDAILY` | Resets every MC day (24000 ticks) | ✅ Working |
|
||
| `MCWEEKLY` | Resets every 7 MC days (168000 ticks) | ✅ Working |
|
||
| `MCCUSTOM` | Custom MC tick interval | ✅ Working |
|
||
| `RLDAILY` | Resets every 24 real-life hours | ✅ Working |
|
||
| `RLWEEKLY` | Resets every 7 real-life days | ✅ Working |
|
||
| `RLCUSTOM` | Custom real-time interval | ✅ Working |
|
||
|
||
#### Stock UI Features - IMPLEMENTED
|
||
| Feature | Status | Notes |
|
||
|---------|--------|-------|
|
||
| Stock count per item | ✅ | Shows to right of output slot |
|
||
| Out of stock indicator | ✅ | Dark overlay + red count |
|
||
| Reset timer countdown | ✅ | Real-time client-side countdown in top-right |
|
||
| "Reopen Trader" message | ✅ | Shows when countdown reaches 0 |
|
||
| Admin stock configuration | ✅ | SubGuiNpcTraderStock |
|
||
| Per-slot stock limits | ✅ | SubGuiNpcTraderStockSlots |
|
||
| Reset stock button | ✅ | With confirmation dialog |
|
||
| Reset cooldown button | ✅ | With confirmation dialog |
|
||
|
||
#### Key Files
|
||
| File | Purpose |
|
||
|------|---------|
|
||
| `TraderStock.java` | Core stock data class with per-player/global modes |
|
||
| `TraderStock.PlayerTraderStock` | Inner class for per-player tracking |
|
||
| `EnumStockReset.java` | Reset type enum with intervals |
|
||
| `SubGuiNpcTraderStock.java` | Main stock configuration GUI |
|
||
| `SubGuiNpcTraderStockSlots.java` | Per-slot stock limit editor |
|
||
| `SubGuiNpcTraderStockReset.java` | Stock reset confirmation |
|
||
| `SubGuiNpcTraderCooldownReset.java` | Cooldown reset confirmation |
|
||
|
||
---
|
||
|
||
### 2.2 Trader Currency Support - IMPLEMENTED
|
||
|
||
Trades can require BOTH items AND currency (additive costs).
|
||
|
||
#### Trade Entry Structure
|
||
Each trade slot can have:
|
||
- **Sold Item** - What the player receives ✅
|
||
- **Currency 1** - First item cost (existing) ✅
|
||
- **Currency 2** - Second item cost (existing) ✅
|
||
- **Currency Cost** - CNPC+ Currency / Vault cost ✅ NEW
|
||
|
||
#### Example Trades
|
||
| Sold Item | Item Cost | Currency Cost |
|
||
|-----------|-----------|---------------|
|
||
| Diamond | 2 Emeralds | $0 |
|
||
| Diamond Sword | 5 Diamonds | $100 |
|
||
| Special Armor | None | $500 |
|
||
| Enchanted Book | 1 Book + 10 Lapis | $50 |
|
||
|
||
#### Implementation Details
|
||
- Currency cost stored as `long[] currencyCost[18]` in RoleTrader
|
||
- Default to 0 (no currency cost) for legacy compatibility ✅
|
||
- Check both item AND currency requirements before purchase ✅
|
||
- Withdraw currency on successful purchase ✅
|
||
- NBT serialization for persistence ✅
|
||
|
||
---
|
||
|
||
### 2.3 Player Trader GUI - IMPLEMENTED
|
||
|
||
#### Layout (256px wide)
|
||
- 3 columns × 6 rows = 18 trade slots
|
||
- Column width: 80px
|
||
- Per slot: [Currency1][Currency2] = [Output]
|
||
- Player inventory positioned below
|
||
|
||
#### Display Features
|
||
| Element | Position | Status |
|
||
|---------|----------|--------|
|
||
| "Trader" label | Top-left | ✅ |
|
||
| Reset countdown | Top-right | ✅ Real-time ticking |
|
||
| Stock count | Right of each trade | ✅ Green/Red |
|
||
| Player balance | Bottom-right | ✅ |
|
||
| Status message | Bottom-left | ✅ On hover |
|
||
|
||
#### Status Messages (on hover)
|
||
| Condition | Message | Color |
|
||
|-----------|---------|-------|
|
||
| Out of stock | "Out of Stock ($COST)" | Red |
|
||
| Can't afford balance | "Insufficient Balance ($COST)" | Red |
|
||
| Missing item currency | "Unavailable ($COST)" | Red |
|
||
| Slot disabled | "Slot Disabled ($COST)" | Orange |
|
||
| Can purchase | "Available ($COST)" | Green |
|
||
|
||
Cost suffix only appears if trade has currency cost > 0.
|
||
|
||
---
|
||
|
||
### 2.4 Multi-Player Sync - IMPLEMENTED
|
||
|
||
#### MarketRegistry System
|
||
Central registry for linked market synchronization across all NPCs sharing the same market.
|
||
|
||
| Component | Purpose |
|
||
|-----------|---------|
|
||
| `MarketRegistry.java` | Central registry tracking traders and viewers per market |
|
||
| `marketTraders` | `Map<String, Set<RoleTrader>>` - All traders using each market |
|
||
| `marketViewers` | `Map<String, Set<EntityPlayerMP>>` - All players viewing each market |
|
||
|
||
#### Viewer Tracking System
|
||
| Feature | Status | Notes |
|
||
|---------|--------|-------|
|
||
| Register viewer on GUI open | ✅ | For shared stock mode (linked or local) |
|
||
| Unregister on GUI close | ✅ | Via onContainerClosed |
|
||
| Sync after purchase | ✅ | All viewers updated market-wide |
|
||
| Per-player mode optimization | ✅ | Only sync to purchasing player |
|
||
| Disconnected player cleanup | ✅ | Removed before sync |
|
||
| NPC unload cleanup | ✅ | Via delete() → onUnload() |
|
||
|
||
#### Sync Behavior by Mode
|
||
| Mode | Linked Market | Behavior |
|
||
|------|---------------|----------|
|
||
| Shared Stock | Yes | All viewers across ALL NPCs with same market see update immediately |
|
||
| Shared Stock | No | All viewers of THIS NPC see update immediately |
|
||
| Per-Player Stock | Yes/No | Only purchasing player receives update |
|
||
|
||
#### Data Flow
|
||
```
|
||
Purchase on NPC1 (market="shop1")
|
||
↓
|
||
consumeStock() → Market.save() → MarketRegistry.syncMarket("shop1")
|
||
↓
|
||
┌──────────────────────────────────────────────┐
|
||
│ 1. Update ALL traders' stock data │
|
||
│ (NPC1, NPC2, NPC3... all with "shop1") │
|
||
│ 2. Sync ALL viewers across ALL those NPCs │
|
||
└──────────────────────────────────────────────┘
|
||
```
|
||
|
||
---
|
||
|
||
### 2.5 Key Files Modified/Created
|
||
|
||
| File | Changes |
|
||
|------|---------|
|
||
| `MarketRegistry.java` | NEW - Central registry for linked market sync |
|
||
| `RoleTrader.java` | currencyCost[], viewer tracking (local + registry), syncAllViewers(), resetCooldown(), delete() cleanup |
|
||
| `ContainerNPCTrader.java` | Layout constants, currency/stock validation, viewer registration |
|
||
| `GuiNPCTrader.java` | Client-side countdown, stock display, status messages |
|
||
| `GetTraderData.java` | Network packet for requesting trader data (IGuiData pattern) |
|
||
| `TraderStock.java` | Stock management with per-player/global modes, thread-safe methods |
|
||
| `EnumStockReset.java` | Reset type definitions with lang key support |
|
||
| `SubGuiNpcTraderStock.java` | Stock configuration dialog, custom time validation |
|
||
| `SubGuiNpcTraderStockSlots.java` | Per-slot stock limits |
|
||
| `SubGuiNpcTraderStockReset.java` | Stock reset confirmation |
|
||
| `SubGuiNpcTraderCooldownReset.java` | Cooldown reset confirmation |
|
||
| `GuiNPCInterface.java` | Fixed SubGui background tiling for smaller widths |
|
||
| `Market.java` | Fixed save logic for linked markets |
|
||
| `IRoleTrader.java` | Extended API with stock manipulation methods |
|
||
| `ScriptRoleTrader.java` | Implemented new API methods |
|
||
|
||
---
|
||
|
||
### 2.6 Resolved Issues
|
||
|
||
All previously identified issues have been fixed:
|
||
|
||
#### Critical Issues - FIXED
|
||
| Issue | Fix |
|
||
|-------|-----|
|
||
| Market load overwrites reset | Reordered `interact()` to load market BEFORE stock reset check |
|
||
| recordHistory flag inverted | Removed inverted early return in `Market.save()` |
|
||
| API returns wrong item | Fixed `getSellOption()` to return `inventorySold` instead of `inventoryCurrency` |
|
||
|
||
#### Medium Priority - FIXED
|
||
| Issue | Fix |
|
||
|-------|-----|
|
||
| Thread safety | Added `synchronized` to `getAvailableStock()`, `consumeStock()`, `resetStock()` |
|
||
| Per-player cleanup | `playerStock.clear()` called on stock reset |
|
||
| Linked market sync | Implemented `MarketRegistry` for market-wide sync |
|
||
| Custom time validation | Added min validation (1 tick MC, 1000ms RL) in `SubGuiNpcTraderStock` |
|
||
|
||
#### Low Priority - FIXED
|
||
| Issue | Fix |
|
||
|-------|-----|
|
||
| lastPurchaseTime unused | Removed from `PlayerTraderStock` |
|
||
| Currency format | Verified working correctly for all ranges |
|
||
| Hardcoded reset types | Now uses `EnumStockReset.getDisplayNames()` with lang keys |
|
||
|
||
---
|
||
|
||
### 2.7 Scripting API - IMPLEMENTED
|
||
|
||
Full API available via `IRoleTrader` interface:
|
||
|
||
```javascript
|
||
// Stock Configuration
|
||
trader.isStockEnabled()
|
||
trader.setStockEnabled(boolean)
|
||
trader.isPerPlayerStock()
|
||
trader.setPerPlayerStock(boolean)
|
||
trader.getStockResetType() // Returns int (0-6 for EnumStockReset)
|
||
trader.setStockResetType(int)
|
||
trader.getCustomResetTime()
|
||
trader.setCustomResetTime(long)
|
||
|
||
// Stock Limits
|
||
trader.getMaxStock(slot) // Max stock for slot (-1 = unlimited)
|
||
trader.setMaxStock(slot, amount)
|
||
|
||
// Stock Queries
|
||
trader.getAvailableStock(slot) // Global mode
|
||
trader.getAvailableStock(slot, player) // Per-player mode
|
||
trader.getCurrentStock(slot) // Current stock (global)
|
||
trader.getPlayerPurchased(slot, player) // Amount purchased by player
|
||
|
||
// Stock Manipulation
|
||
trader.setCurrentStock(slot, amount) // Set current stock (global)
|
||
trader.setPlayerPurchased(slot, player, amount) // Set player's purchased amount
|
||
trader.resetStock() // Reset all stock to max
|
||
trader.resetCooldown() // Reset cooldown timer
|
||
|
||
// Time Queries
|
||
trader.getLastResetTime() // Timestamp of last reset
|
||
trader.getTimeUntilReset() // Time remaining until next reset
|
||
|
||
// Currency Cost System
|
||
trader.getCurrencyCost(slot)
|
||
trader.setCurrencyCost(slot, amount)
|
||
trader.hasCurrencyCost(slot)
|
||
```
|
||
|
||
---
|
||
|
||
## 3. Auction House System
|
||
|
||
### Status: NOT STARTED (Fresh implementation)
|
||
|
||
### 3.1 Architecture Overview
|
||
|
||
```
|
||
┌─────────────────────────────────────────────────────────────┐
|
||
│ AuctionController │
|
||
│ - Manages all auction data │
|
||
│ - Handles listing/bidding/buyout logic │
|
||
│ - Processes claims │
|
||
│ - Saves/loads auction data │
|
||
└─────────────────────────────────────────────────────────────┘
|
||
│
|
||
▼
|
||
┌─────────────────────────────────────────────────────────────┐
|
||
│ AuctionNotification │
|
||
│ - Tracks pending notifications per player │
|
||
│ - Sends notifications on login │
|
||
│ - Types: Won, Outbid, Sold, Expired, Claimed │
|
||
└─────────────────────────────────────────────────────────────┘
|
||
```
|
||
|
||
### 3.2 GUI Structure
|
||
|
||
```
|
||
GuiAuctionHouse (Base GUI - opened via Auctioneer NPC)
|
||
│
|
||
├── GuiAuction (Browse/Search auctions)
|
||
│ - Paginated item display (ContainerAuction)
|
||
│ - Next/Back page buttons
|
||
│ - Filter button → opens GuiAuctionFilter
|
||
│ - My Auctions button → opens GuiAuctionClaims
|
||
│ - Sell button → opens GuiAuctionSell
|
||
│ - Click item → SubGuiAuctionDetails
|
||
│
|
||
├── GuiAuctionSell (Create new listing)
|
||
│ - Item slot for item to sell
|
||
│ - Starting price input
|
||
│ - Buyout price input (0 = no buyout)
|
||
│ - Listing fee display
|
||
│ - Create button
|
||
│
|
||
├── GuiAuctionClaims (My Auctions / Claims)
|
||
│ - Active listings tab
|
||
│ - Pending claims tab (items + currency to collect)
|
||
│ - Cancel listing button
|
||
│ - Claim all button
|
||
│
|
||
└── GuiAuctionFilter (Filter settings)
|
||
- Search text
|
||
- Sort options (EnumAuctionSort)
|
||
- Price range (min/max)
|
||
- Show my listings only toggle
|
||
```
|
||
|
||
### 3.3 Admin GUI
|
||
|
||
```
|
||
GuiManageAuction (Admin tool - like ManageMagic, ManageQuests)
|
||
│
|
||
├── Active Auctions Tab
|
||
│ - View all auctions
|
||
│ - Cancel any auction (with reason)
|
||
│ - View auction details
|
||
│
|
||
├── Blacklist Tab (Stub for future)
|
||
│ - Add/remove blacklisted items
|
||
│ - Add/remove blacklisted mods
|
||
│
|
||
└── Settings Tab
|
||
- View current config values
|
||
- Quick reference for config file
|
||
```
|
||
|
||
### 3.4 Data Structures
|
||
|
||
#### AuctionListing
|
||
```java
|
||
public class AuctionListing {
|
||
int id; // Unique listing ID
|
||
UUID sellerUUID; // Seller's UUID
|
||
String sellerName; // Seller's display name
|
||
ItemStack item; // Item being sold
|
||
long startingPrice; // Minimum starting bid
|
||
long buyoutPrice; // Instant buy price (0 = no buyout)
|
||
long currentBid; // Current highest bid
|
||
UUID highBidderUUID; // Current high bidder (null if no bids)
|
||
String highBidderName; // High bidder display name
|
||
int bidCount; // Number of bids placed
|
||
long createdTime; // When listing was created
|
||
long endTime; // When auction ends
|
||
EnumAuctionStatus status; // ACTIVE, ENDED, CANCELLED, CLAIMED
|
||
}
|
||
```
|
||
|
||
#### AuctionClaim
|
||
```java
|
||
public class AuctionClaim {
|
||
int id; // Unique claim ID
|
||
UUID playerUUID; // Player who can claim
|
||
int listingId; // Related auction listing
|
||
EnumClaimType type; // ITEM, CURRENCY, REFUND
|
||
ItemStack item; // Item to claim (if type = ITEM)
|
||
long currency; // Currency to claim (if type = CURRENCY/REFUND)
|
||
long createdTime; // When claim was created
|
||
boolean claimed; // Whether claimed
|
||
}
|
||
```
|
||
|
||
#### AuctionFilter
|
||
```java
|
||
public class AuctionFilter {
|
||
String searchText; // Item name search
|
||
EnumAuctionSort sortBy; // Sort order
|
||
long minPrice; // Minimum price filter
|
||
long maxPrice; // Maximum price filter (0 = no max)
|
||
boolean myListingsOnly; // Show only my listings
|
||
}
|
||
```
|
||
|
||
#### Enums
|
||
```java
|
||
public enum EnumAuctionStatus {
|
||
ACTIVE, // Auction is live
|
||
ENDED, // Auction ended (winner determined)
|
||
CANCELLED, // Cancelled by seller or admin
|
||
CLAIMED // All claims processed
|
||
}
|
||
|
||
public enum EnumAuctionSort {
|
||
NEWEST, // Most recently listed
|
||
ENDING_SOON, // Ending soonest
|
||
PRICE_LOW, // Lowest current price
|
||
PRICE_HIGH, // Highest current price
|
||
MOST_BIDS // Most bid activity
|
||
}
|
||
|
||
public enum EnumClaimType {
|
||
ITEM, // Winner claims item
|
||
CURRENCY, // Seller claims sale currency
|
||
REFUND // Outbid player claims refund
|
||
}
|
||
```
|
||
|
||
### 3.5 AuctionController
|
||
|
||
Main controller handling all auction logic.
|
||
|
||
#### Core Methods
|
||
```java
|
||
// Listing Management
|
||
int createListing(EntityPlayer seller, ItemStack item, long startingPrice, long buyoutPrice)
|
||
void cancelListing(int listingId, EntityPlayer player, boolean isAdmin)
|
||
List<AuctionListing> getActiveListings(AuctionFilter filter, int page, int pageSize)
|
||
AuctionListing getListing(int listingId)
|
||
int getPlayerListingCount(UUID playerUUID)
|
||
|
||
// Bidding
|
||
boolean placeBid(int listingId, EntityPlayer bidder, long bidAmount)
|
||
boolean buyout(int listingId, EntityPlayer buyer)
|
||
|
||
// Claims
|
||
List<AuctionClaim> getPlayerClaims(UUID playerUUID)
|
||
boolean claimItem(int claimId, EntityPlayer player)
|
||
boolean claimCurrency(int claimId, EntityPlayer player)
|
||
void claimAll(EntityPlayer player)
|
||
|
||
// Lifecycle
|
||
void processEndedAuctions() // Called on tick, creates claims for ended auctions
|
||
void onPlayerLogin(EntityPlayer player) // Send pending notifications
|
||
|
||
// Persistence
|
||
void save()
|
||
void load()
|
||
```
|
||
|
||
#### Auction Flow
|
||
|
||
**Creating a Listing:**
|
||
1. Validate item not blacklisted
|
||
2. Check player has listing slots available
|
||
3. Deduct listing fee from player
|
||
4. Remove item from player inventory
|
||
5. Create AuctionListing with ACTIVE status
|
||
6. Save
|
||
|
||
**Placing a Bid:**
|
||
1. Validate auction is ACTIVE
|
||
2. Validate bid > current bid + minimum increment
|
||
3. Validate bidder has enough currency
|
||
4. Deduct bid amount from bidder
|
||
5. If previous bidder exists, create REFUND claim for them
|
||
6. Update listing with new bid/bidder
|
||
7. Apply snipe protection if needed
|
||
8. Save
|
||
|
||
**Buyout:**
|
||
1. Validate auction is ACTIVE and has buyout price
|
||
2. Validate buyer has enough currency
|
||
3. Deduct buyout amount from buyer
|
||
4. If previous bidder exists, create REFUND claim
|
||
5. Create ITEM claim for buyer
|
||
6. Create CURRENCY claim for seller (minus sales tax)
|
||
7. Set status to ENDED
|
||
8. Save
|
||
|
||
**Auction Ends (no buyout):**
|
||
1. If bids exist:
|
||
- Create ITEM claim for high bidder
|
||
- Create CURRENCY claim for seller (minus sales tax)
|
||
2. If no bids:
|
||
- Create ITEM claim for seller (item returned)
|
||
3. Set status to ENDED
|
||
4. Save
|
||
|
||
### 3.6 Snipe Protection
|
||
|
||
When a bid is placed with less than `SnipeProtectionMinutes` remaining:
|
||
- Extend the auction end time TO `SnipeProtectionMinutes` from now
|
||
- Never extend beyond `SnipeProtectionMinutes`
|
||
- Default: 2 minutes
|
||
|
||
Example: Auction ends in 30 seconds, someone bids → Timer resets to 2:00
|
||
|
||
### 3.7 Notifications
|
||
|
||
#### AuctionNotification Class
|
||
```java
|
||
public class AuctionNotification {
|
||
UUID playerUUID;
|
||
EnumNotificationType type;
|
||
int listingId;
|
||
String message;
|
||
long timestamp;
|
||
}
|
||
|
||
public enum EnumNotificationType {
|
||
AUCTION_WON, // You won an auction
|
||
AUCTION_OUTBID, // You were outbid
|
||
AUCTION_SOLD, // Your item sold
|
||
AUCTION_EXPIRED, // Your auction expired (no bids)
|
||
CLAIM_READY // You have items/currency to claim
|
||
}
|
||
```
|
||
|
||
Notifications are queued and sent when player logs in.
|
||
|
||
### 3.8 Permissions
|
||
|
||
| Permission | Default | Description |
|
||
|------------|---------|-------------|
|
||
| `customnpcs.auction.use` | true | Can use auction house |
|
||
| `customnpcs.auction.sell` | true | Can create listings |
|
||
| `customnpcs.auction.slots.X` | 5 | Max listing slots (X = number) |
|
||
| `customnpcs.auction.admin` | op | Admin auction management |
|
||
|
||
---
|
||
|
||
## 4. Configuration
|
||
|
||
### ConfigMarket.java Structure
|
||
|
||
```java
|
||
// =========================================
|
||
// Market General
|
||
// =========================================
|
||
public static boolean MarketEnabled = true;
|
||
|
||
// =========================================
|
||
// Currency (Market.Currency)
|
||
// =========================================
|
||
public static boolean UseVault = false;
|
||
public static String CurrencyName = "Coins";
|
||
public static long StartingBalance = 0;
|
||
public static long MaxBalance = Long.MAX_VALUE;
|
||
|
||
// =========================================
|
||
// Trader (Market.Trader)
|
||
// =========================================
|
||
public static boolean EnableStockByDefault = false;
|
||
public static String DefaultResetType = "NONE";
|
||
|
||
// =========================================
|
||
// Auction (Market.Auction)
|
||
// =========================================
|
||
public static boolean AuctionEnabled = true;
|
||
public static int AuctionDuration = 24; // Hours
|
||
public static long ListingFee = 10; // Flat fee to create listing
|
||
public static double SalesTaxPercent = 0.05; // 5% tax on sales
|
||
public static int DefaultMaxListings = 5; // Per player
|
||
public static int SnipeProtectionMinutes = 2; // Snipe protection timer
|
||
public static int ClaimExpirationDays = 30; // Days before unclaimed items deleted
|
||
public static double MinBidIncrementPercent = 0.05; // 5% minimum bid increase
|
||
```
|
||
|
||
---
|
||
|
||
## 5. File Structure
|
||
|
||
### New Files to Create
|
||
|
||
```
|
||
constants/
|
||
EnumAuctionStatus.java
|
||
EnumAuctionSort.java
|
||
EnumClaimType.java
|
||
EnumNotificationType.java
|
||
|
||
controllers/
|
||
AuctionController.java
|
||
AuctionNotification.java
|
||
|
||
controllers/data/
|
||
AuctionListing.java
|
||
AuctionClaim.java
|
||
AuctionFilter.java
|
||
|
||
roles/
|
||
RoleAuctioneer.java
|
||
|
||
containers/
|
||
ContainerAuction.java
|
||
|
||
client/gui/player/
|
||
GuiAuctionHouse.java (Base GUI)
|
||
GuiAuction.java (Browse auctions)
|
||
GuiAuctionSell.java (Create listing)
|
||
GuiAuctionClaims.java (My auctions/claims)
|
||
GuiAuctionFilter.java (Filter settings)
|
||
SubGuiAuctionDetails.java (View listing details)
|
||
|
||
client/gui/global/
|
||
GuiManageAuction.java (Admin management)
|
||
|
||
network/packets/
|
||
AuctionDataPacket.java (Server → Client data sync)
|
||
AuctionActionPacket.java (Client → Server actions)
|
||
```
|
||
|
||
### Files to Modify
|
||
|
||
```
|
||
CustomNpcs.java - Initialize AuctionController
|
||
ServerTickHandler.java - Process ended auctions, login notifications
|
||
EnumRoleType.java - Add Auctioneer
|
||
EnumGuiType.java - Add auction GUI types
|
||
DataAdvanced.java - Handle Auctioneer role
|
||
PacketHandler.java - Register auction packets
|
||
CustomNpcsPermissions.java - Auction permissions
|
||
ConfigMarket.java - Add Auction section
|
||
RoleTrader.java - Add currency cost per trade
|
||
ContainerNPCTrader.java - Currency + stock integration
|
||
en_US.lang - All auction lang keys
|
||
```
|
||
|
||
---
|
||
|
||
## 6. Data Storage
|
||
|
||
### Auction Data File
|
||
Location: `customnpcs/auction.dat`
|
||
|
||
Structure:
|
||
```
|
||
NBTTagCompound root
|
||
├── NextListingId: int
|
||
├── NextClaimId: int
|
||
├── Listings: NBTTagList
|
||
│ └── [AuctionListing NBT...]
|
||
├── Claims: NBTTagList
|
||
│ └── [AuctionClaim NBT...]
|
||
└── PendingNotifications: NBTTagList
|
||
└── [AuctionNotification NBT...]
|
||
```
|
||
|
||
---
|
||
|
||
## 7. Lang Keys
|
||
|
||
```properties
|
||
# Auction House
|
||
auction.title=Auction House
|
||
auction.browse=Browse
|
||
auction.sell=Sell
|
||
auction.claims=My Auctions
|
||
auction.filter=Filter
|
||
|
||
# Browse
|
||
auction.nextPage=Next >
|
||
auction.prevPage=< Prev
|
||
auction.page=Page %d of %d
|
||
auction.noResults=No auctions found
|
||
auction.refresh=Refresh
|
||
|
||
# Listing Display
|
||
auction.seller=Seller: %s
|
||
auction.currentBid=Current Bid: %s
|
||
auction.buyout=Buyout: %s
|
||
auction.timeLeft=Time Left: %s
|
||
auction.bids=%d bids
|
||
auction.noBids=No bids
|
||
|
||
# Create Listing
|
||
auction.sell.title=Create Listing
|
||
auction.sell.startingPrice=Starting Price
|
||
auction.sell.buyoutPrice=Buyout Price
|
||
auction.sell.noBuyout=(0 = no buyout)
|
||
auction.sell.fee=Listing Fee: %s
|
||
auction.sell.create=Create Listing
|
||
auction.sell.noItem=Place an item to sell
|
||
|
||
# Claims
|
||
auction.claims.title=My Auctions
|
||
auction.claims.active=Active Listings
|
||
auction.claims.pending=Pending Claims
|
||
auction.claims.claimAll=Claim All
|
||
auction.claims.cancel=Cancel Listing
|
||
auction.claims.empty=No pending claims
|
||
|
||
# Filter
|
||
auction.filter.title=Filter Auctions
|
||
auction.filter.search=Search
|
||
auction.filter.minPrice=Min Price
|
||
auction.filter.maxPrice=Max Price
|
||
auction.filter.myOnly=My Listings Only
|
||
auction.filter.apply=Apply
|
||
|
||
# Sort Options
|
||
auction.sort.newest=Newest
|
||
auction.sort.endingSoon=Ending Soon
|
||
auction.sort.priceLow=Price: Low to High
|
||
auction.sort.priceHigh=Price: High to Low
|
||
auction.sort.mostBids=Most Bids
|
||
|
||
# Notifications
|
||
auction.notify.won=You won the auction for %s!
|
||
auction.notify.outbid=You were outbid on %s!
|
||
auction.notify.sold=Your %s sold for %s!
|
||
auction.notify.expired=Your auction for %s expired with no bids.
|
||
auction.notify.claim=You have items to claim at the Auction House.
|
||
|
||
# Errors
|
||
auction.error.notEnoughCurrency=Not enough currency!
|
||
auction.error.auctionEnded=This auction has ended.
|
||
auction.error.bidTooLow=Bid must be at least %s.
|
||
auction.error.maxListings=You have reached your maximum listings.
|
||
auction.error.blacklisted=This item cannot be auctioned.
|
||
auction.error.noAuctioneer=You must visit an Auctioneer NPC.
|
||
|
||
# Trader Currency
|
||
trader.currencyCost=Currency Cost
|
||
trader.outOfStock=Out of Stock
|
||
trader.stock=Stock: %d
|
||
```
|
||
|
||
---
|
||
|
||
## 8. Implementation Order
|
||
|
||
### Phase 1: Trader Currency Integration - COMPLETE ✅
|
||
1. ~~Add `currencyCost` field to RoleTrader trades~~
|
||
2. ~~Update ContainerNPCTrader to check/deduct currency~~
|
||
3. ~~Update trader setup GUI with currency input~~
|
||
4. ~~Test with existing item trades (backward compatibility)~~
|
||
|
||
### Phase 2: Trader Stock UI - COMPLETE ✅
|
||
1. ~~Add stock display to player trader GUI~~
|
||
2. ~~Show "Out of Stock" indicator~~
|
||
3. ~~Verify reset timers working~~
|
||
4. ~~Real-time client-side countdown~~
|
||
5. ~~Status messages with costs~~
|
||
6. ~~Reset cooldown button with confirmation~~
|
||
|
||
### Phase 2.5: Trader Sync System - COMPLETE ✅
|
||
1. ~~Implement MarketRegistry for linked market sync~~
|
||
2. ~~Viewer tracking (market-wide and local)~~
|
||
3. ~~NPC unload cleanup~~
|
||
4. ~~Thread safety for stock operations~~
|
||
|
||
### Phase 3: Auction Core
|
||
1. Create enums (EnumAuctionStatus, EnumAuctionSort, etc.)
|
||
2. Create data classes (AuctionListing, AuctionClaim, AuctionFilter)
|
||
3. Create AuctionController with core logic
|
||
4. Create RoleAuctioneer
|
||
5. Add to CustomNpcs initialization
|
||
|
||
### Phase 4: Auction GUI
|
||
1. Create GuiAuctionHouse base
|
||
2. Create GuiAuction (browse)
|
||
3. Create GuiAuctionSell
|
||
4. Create GuiAuctionClaims
|
||
5. Create GuiAuctionFilter
|
||
6. Create SubGuiAuctionDetails
|
||
7. Create ContainerAuction
|
||
|
||
### Phase 5: Auction Network
|
||
1. Create AuctionDataPacket
|
||
2. Create AuctionActionPacket
|
||
3. Register packets
|
||
|
||
### Phase 6: Admin & Polish
|
||
1. Create GuiManageAuction
|
||
2. Add permissions
|
||
3. Add notifications system
|
||
4. Add lang keys
|
||
5. Testing
|
||
|
||
---
|
||
|
||
## 9. Design Decisions
|
||
|
||
| Decision | Choice | Rationale |
|
||
|----------|--------|-----------|
|
||
| Claims System | Everything to claims | Prevents offline handling issues |
|
||
| Auction Duration | Single config value | Simplicity over flexibility |
|
||
| Snipe Protection | Reset to X minutes | Fair bidding, prevents last-second sniping |
|
||
| Listing Fees | Flat fee only | Simple, predictable |
|
||
| Sales Tax | Percentage of sale | Scales with item value |
|
||
| Data Storage | Single .dat file | Consistent with quests/dialogs |
|
||
| Blacklist | Stub for now | Complex feature for later |
|
||
| Currency per Trade | Additive with items | Backward compatible, flexible |
|
||
|
||
---
|
||
|
||
## 10. Future Considerations (Not in 1.11)
|
||
|
||
- Category-based filtering
|
||
- Advanced blacklist system (items, mods, NBT patterns)
|
||
- Auction history/statistics
|
||
- Command-based auction access
|
||
- Auction house tax sink
|
||
- Reserve prices
|
||
- Private auctions
|