Implement Phase 1: Currency System foundation

- Add ConfigMarket.java with separate market.cfg config file
  - Currency settings (name, starting balance, max balance, Vault integration)
  - Auction settings (durations, fees, snipe protection, claim expiration)
  - Trader settings (stock system defaults)

- Add PlayerCurrencyData.java for balance storage
  - NOT profile slot bound - shared across all slots
  - Tracks balance, lifetime earned, and lifetime spent
  - Deposit/withdraw with overflow protection

- Add VaultHelper.java for Bukkit hybrid server integration
  - Reflection-based VaultAPI integration
  - Falls back to internal currency when Vault unavailable
  - Supports getBalance, deposit, withdraw, transfer operations

- Add CurrencyController.java for currency operations
  - Claims system for auction refunds and NPC payments
  - Claim expiration with configurable days
  - Persistence via currency_claims.dat

- Update PlayerData.java to integrate currency
  - Separate loadCurrency/saveCurrency methods
  - Currency file stored separately from slot data

- Add scripting API methods to ScriptPlayer.java
  - getCurrencyBalance(), addCurrency(), removeCurrency()
  - canAffordCurrency(), getCurrencyName(), formatCurrency()
  - hasPendingClaims(), getPendingClaimsTotal(), claimAllCurrency()
This commit is contained in:
Claude committed 2026-01-04 08:14:29 +00:00
1 parent 4093bf9adf
commit 7e6b17c106
8 files changed
+1211

No files matched your search

@@ -59,6 +59,9 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
public DataSkinOverlays skinOverlays = new DataSkinOverlays(this);
public MagicData magicData = new MagicData();
// Currency data - NOT slot-bound, shared across all profile slots
public PlayerCurrencyData currencyData = new PlayerCurrencyData();
public ActionManager actionManager = new ActionManager();
public PlayerDataScript scriptData;
@@ -443,6 +446,69 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
data = getNBT();
}
setNBT(data);
// Load currency data separately (not slot-bound)
loadCurrency();
}
/**
* Load currency data from separate file (shared across profile slots)
*/
public void loadCurrency() {
if (player == null) return;
File saveDir = PlayerDataController.Instance.getSaveDir();
String filename = player.getPersistentID().toString() + "_currency";
try {
File file = new File(saveDir, filename + ".json");
if (file.exists()) {
NBTTagCompound compound = NBTJsonUtil.LoadFile(file);
currencyData.readFromNBT(compound);
return;
}
// Try dat format
file = new File(saveDir, filename + ".dat");
if (file.exists()) {
NBTTagCompound compound = NBTJsonUtil.loadNBTData(file);
currencyData.readFromNBT(compound);
return;
}
// No currency file exists, use defaults (new player)
currencyData = new PlayerCurrencyData();
} catch (Exception e) {
LogWriter.error("Error loading currency data for " + player.getCommandSenderName(), e);
currencyData = new PlayerCurrencyData();
}
}
/**
* Save currency data to separate file (shared across profile slots)
*/
public synchronized void saveCurrency() {
if (uuid == null || uuid.isEmpty()) return;
final NBTTagCompound compound = new NBTTagCompound();
currencyData.writeToNBT(compound);
final String filename = uuid + "_currency.json";
CustomNPCsThreader.customNPCThread.execute(() -> {
try {
File saveDir = PlayerDataController.Instance.getSaveDir();
File file = new File(saveDir, filename + "_new");
File file1 = new File(saveDir, filename);
NBTJsonUtil.SaveFile(file, compound);
if (file1.exists()) {
file1.delete();
}
file.renameTo(file1);
} catch (Exception e) {
LogWriter.except(e);
}
});
}
public static PlayerData get(EntityPlayer player) {