mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 09:39:48 +00:00
Merge branch 'dev' into syntax-highlighter-unified
This commit is contained in:
commit
39a43a339b
78 files changed
+4554
-1446
No files matched your search
@@ -25,7 +25,7 @@ public class AuctionConfigSync {
|
||||
compound.setString("CurrencyName", getEffectiveCurrencyName());
|
||||
compound.setInteger("AuctionDurationHours", ConfigMarket.AuctionDurationHours);
|
||||
compound.setDouble("MinBidIncrement", ConfigMarket.MinBidIncrementPercent);
|
||||
compound.setInteger("MaxActiveListings", ConfigMarket.DefaultMaxListings);
|
||||
compound.setInteger("MaxActiveListings", ConfigMarket.DefaultMaxTrades);
|
||||
compound.setInteger("ClaimExpirationDays", ConfigMarket.ClaimExpirationDays);
|
||||
return compound;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -364,6 +364,17 @@ public class PlayerDataController {
|
||||
return data;
|
||||
}
|
||||
|
||||
public PlayerData getData(UUID uuid) {
|
||||
EntityPlayer player = getPlayerFromUUID(uuid);
|
||||
PlayerData data;
|
||||
if (player == null) {
|
||||
data = new PlayerData();
|
||||
data.setNBT(PlayerDataController.Instance.loadPlayerData(uuid.toString()));
|
||||
} else
|
||||
data = PlayerData.get(player);
|
||||
return data;
|
||||
}
|
||||
|
||||
public void addPlayerMessage(String username, PlayerMail mail) {
|
||||
mail.time = System.currentTimeMillis();
|
||||
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import kamkeel.npcs.util.AttributeItemUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AuctionBlacklist {
|
||||
private static Set<String> blacklistedItems = new HashSet<>();
|
||||
private static Set<Pattern> wildcardPatterns = new HashSet<>();
|
||||
private static Set<String> blacklistedMods = new HashSet<>();
|
||||
private static Set<String> blacklistedNBTTags = new HashSet<>();
|
||||
|
||||
// Built-in bound item requirement keys (always blocked)
|
||||
private static final String SOULBIND_KEY = "cnpc_soulbind";
|
||||
private static final String PROFILE_SLOT_KEY = "cnpc_profile_slot";
|
||||
|
||||
// Bypass permission
|
||||
private static final String BYPASS_PERMISSION = "customnpcs.auction.blacklist.bypass";
|
||||
|
||||
public static void reload() {
|
||||
blacklistedItems.clear();
|
||||
wildcardPatterns.clear();
|
||||
blacklistedMods.clear();
|
||||
blacklistedNBTTags.clear();
|
||||
|
||||
// Load blacklisted items
|
||||
for (String item : ConfigMarket.BlacklistedItems) {
|
||||
if (item == null || item.isEmpty()) continue;
|
||||
item = item.toLowerCase().trim();
|
||||
|
||||
if (item.contains("*")) {
|
||||
String regex = "^" + item.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
wildcardPatterns.add(Pattern.compile(regex));
|
||||
} else {
|
||||
blacklistedItems.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Load blacklisted mods
|
||||
for (String mod : ConfigMarket.BlacklistedMods) {
|
||||
if (mod == null || mod.isEmpty()) continue;
|
||||
blacklistedMods.add(mod.toLowerCase().trim());
|
||||
}
|
||||
|
||||
// Load blacklisted NBT tags
|
||||
for (String tag : ConfigMarket.BlacklistedNBTTags) {
|
||||
if (tag == null || tag.isEmpty()) continue;
|
||||
blacklistedNBTTags.add(tag.trim());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player can bypass the blacklist (OP or has permission)
|
||||
*/
|
||||
public static boolean canBypass(EntityPlayer player) {
|
||||
if (player == null) return false;
|
||||
|
||||
// Check OP status
|
||||
if (player.canCommandSenderUseCommand(2, BYPASS_PERMISSION)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check custom permission
|
||||
return CustomNpcsPermissions.hasCustomPermission(player, BYPASS_PERMISSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is blacklisted (without bypass check)
|
||||
*/
|
||||
public static boolean isBlacklisted(ItemStack item) {
|
||||
if (!ConfigMarket.BlacklistEnabled) return false;
|
||||
if (item == null || item.getItem() == null) return true;
|
||||
|
||||
// Check bound items (always blocked, even if blacklist is "disabled")
|
||||
if (hasBoundRequirement(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get registry name
|
||||
GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(item.getItem());
|
||||
if (uid == null) return true;
|
||||
|
||||
String registryName = (uid.modId + ":" + uid.name).toLowerCase();
|
||||
String modId = uid.modId.toLowerCase();
|
||||
|
||||
// Check exact item match
|
||||
if (blacklistedItems.contains(registryName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check wildcard patterns
|
||||
for (Pattern pattern : wildcardPatterns) {
|
||||
if (pattern.matcher(registryName).matches()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check mod blacklist
|
||||
if (blacklistedMods.contains(modId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check NBT tags
|
||||
if (item.hasTagCompound() && !blacklistedNBTTags.isEmpty()) {
|
||||
NBTTagCompound tag = item.getTagCompound();
|
||||
for (String nbtKey : blacklistedNBTTags) {
|
||||
if (tag.hasKey(nbtKey)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is blacklisted for a specific player (with bypass check)
|
||||
*/
|
||||
public static boolean isBlacklistedForPlayer(ItemStack item, EntityPlayer player) {
|
||||
if (canBypass(player)) return false;
|
||||
return isBlacklisted(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registry name of an item
|
||||
*/
|
||||
public static String getRegistryName(ItemStack item) {
|
||||
if (item == null || item.getItem() == null) return null;
|
||||
GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(item.getItem());
|
||||
if (uid == null) return null;
|
||||
return uid.modId + ":" + uid.name;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Bound Item Checking (RPGCore/Requirements)
|
||||
// =========================================
|
||||
|
||||
/**
|
||||
* Check if item has soulbind or profile slot requirement.
|
||||
* Requirements are stored under: item.stackTagCompound/RPGCore/Requirements
|
||||
*/
|
||||
private static boolean hasBoundRequirement(ItemStack item) {
|
||||
if (item == null || !item.hasTagCompound()) return false;
|
||||
|
||||
NBTTagCompound root = item.getTagCompound();
|
||||
if (!root.hasKey(AttributeItemUtil.TAG_RPGCORE)) return false;
|
||||
|
||||
NBTTagCompound rpgCore = root.getCompoundTag(AttributeItemUtil.TAG_RPGCORE);
|
||||
if (!rpgCore.hasKey(AttributeItemUtil.TAG_REQUIREMENTS)) return false;
|
||||
|
||||
NBTTagCompound requirements = rpgCore.getCompoundTag(AttributeItemUtil.TAG_REQUIREMENTS);
|
||||
return requirements.hasKey(SOULBIND_KEY) || requirements.hasKey(PROFILE_SLOT_KEY);
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Runtime Blacklist Management
|
||||
// =========================================
|
||||
|
||||
public static boolean addItem(String registryName) {
|
||||
if (registryName == null || registryName.isEmpty()) return false;
|
||||
registryName = registryName.toLowerCase().trim();
|
||||
|
||||
if (registryName.contains("*")) {
|
||||
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
wildcardPatterns.add(Pattern.compile(regex));
|
||||
} else {
|
||||
blacklistedItems.add(registryName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean removeItem(String registryName) {
|
||||
if (registryName == null || registryName.isEmpty()) return false;
|
||||
registryName = registryName.toLowerCase().trim();
|
||||
|
||||
if (registryName.contains("*")) {
|
||||
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
return wildcardPatterns.removeIf(p -> p.pattern().equals(regex));
|
||||
} else {
|
||||
return blacklistedItems.remove(registryName);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean addMod(String modId) {
|
||||
if (modId == null || modId.isEmpty()) return false;
|
||||
return blacklistedMods.add(modId.toLowerCase().trim());
|
||||
}
|
||||
|
||||
public static boolean removeMod(String modId) {
|
||||
if (modId == null || modId.isEmpty()) return false;
|
||||
return blacklistedMods.remove(modId.toLowerCase().trim());
|
||||
}
|
||||
|
||||
public static boolean addNBTTag(String tag) {
|
||||
if (tag == null || tag.isEmpty()) return false;
|
||||
return blacklistedNBTTags.add(tag.trim());
|
||||
}
|
||||
|
||||
public static boolean removeNBTTag(String tag) {
|
||||
if (tag == null || tag.isEmpty()) return false;
|
||||
return blacklistedNBTTags.remove(tag.trim());
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Getters for listing
|
||||
// =========================================
|
||||
|
||||
public static List<String> getBlacklistedItems() {
|
||||
List<String> result = new ArrayList<>(blacklistedItems);
|
||||
for (Pattern p : wildcardPatterns) {
|
||||
// Convert regex back to wildcard format
|
||||
String pattern = p.pattern();
|
||||
pattern = pattern.substring(1, pattern.length() - 1); // Remove ^ and $
|
||||
pattern = pattern.replace("\\.", ".").replace(".*", "*");
|
||||
result.add(pattern);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getBlacklistedMods() {
|
||||
return new ArrayList<>(blacklistedMods);
|
||||
}
|
||||
|
||||
public static List<String> getBlacklistedNBTTags() {
|
||||
return new ArrayList<>(blacklistedNBTTags);
|
||||
}
|
||||
}
|
||||
@@ -2,28 +2,39 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.handler.data.IAuctionClaim;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
import noppes.npcs.constants.EnumClaimType;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuctionClaim {
|
||||
public class AuctionClaim implements IAuctionClaim {
|
||||
public String id;
|
||||
public UUID playerUUID;
|
||||
public String playerName;
|
||||
public String listingId;
|
||||
public EnumClaimType type;
|
||||
public ItemStack item;
|
||||
public ItemStack item; // The item (for ITEM claims only)
|
||||
public String itemName; // Display name of item (for CURRENCY/REFUND tooltip)
|
||||
public String otherPlayerName; // Buyer name (CURRENCY) or who outbid (REFUND)
|
||||
public long currency;
|
||||
public long createdTime;
|
||||
public boolean claimed;
|
||||
public boolean isReturned; // For ITEM claims: true if returned to seller, false if won by buyer
|
||||
|
||||
public AuctionClaim() {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
this.createdTime = System.currentTimeMillis();
|
||||
this.claimed = false;
|
||||
this.isReturned = false;
|
||||
this.itemName = "";
|
||||
this.otherPlayerName = "";
|
||||
}
|
||||
|
||||
public static AuctionClaim createItemClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
/** Create claim for winning an item (buyer won auction or buyout) */
|
||||
public static AuctionClaim createItemWonClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
claim.playerName = playerName;
|
||||
@@ -31,28 +42,50 @@ public class AuctionClaim {
|
||||
claim.type = EnumClaimType.ITEM;
|
||||
claim.item = item != null ? item.copy() : null;
|
||||
claim.currency = 0;
|
||||
claim.isReturned = false;
|
||||
return claim;
|
||||
}
|
||||
|
||||
public static AuctionClaim createCurrencyClaim(UUID playerUUID, String playerName, String listingId, long currency) {
|
||||
/** Create claim for returned item (seller's expired/cancelled listing) */
|
||||
public static AuctionClaim createItemReturnedClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
claim.playerName = playerName;
|
||||
claim.listingId = listingId;
|
||||
claim.type = EnumClaimType.ITEM;
|
||||
claim.item = item != null ? item.copy() : null;
|
||||
claim.currency = 0;
|
||||
claim.isReturned = true;
|
||||
return claim;
|
||||
}
|
||||
|
||||
/** Create claim for seller's proceeds (stores item name for tooltip, not full item) */
|
||||
public static AuctionClaim createCurrencyClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String buyerName) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
claim.playerName = playerName;
|
||||
claim.listingId = listingId;
|
||||
claim.type = EnumClaimType.CURRENCY;
|
||||
claim.item = null;
|
||||
claim.item = null; // No item stored for currency claims
|
||||
claim.itemName = itemName != null ? itemName : "";
|
||||
claim.otherPlayerName = buyerName != null ? buyerName : "";
|
||||
claim.currency = currency;
|
||||
claim.isReturned = false;
|
||||
return claim;
|
||||
}
|
||||
|
||||
public static AuctionClaim createRefundClaim(UUID playerUUID, String playerName, String listingId, long currency) {
|
||||
/** Create claim for outbid refund (stores item for display and rebid option) */
|
||||
public static AuctionClaim createRefundClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String outbidderName, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
claim.playerName = playerName;
|
||||
claim.listingId = listingId;
|
||||
claim.type = EnumClaimType.REFUND;
|
||||
claim.item = null;
|
||||
claim.item = item != null ? item.copy() : null; // Store item for display and rebid
|
||||
claim.itemName = itemName != null ? itemName : "";
|
||||
claim.otherPlayerName = outbidderName != null ? outbidderName : "";
|
||||
claim.currency = currency;
|
||||
claim.isReturned = false;
|
||||
return claim;
|
||||
}
|
||||
|
||||
@@ -71,6 +104,95 @@ public class AuctionClaim {
|
||||
return playerUUID != null && playerUUID.equals(uuid);
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// IAuctionClaim Implementation
|
||||
// =========================================
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerUUID() {
|
||||
return playerUUID != null ? playerUUID.toString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getListingId() {
|
||||
return listingId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return type.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemClaim() {
|
||||
return type == EnumClaimType.ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurrencyClaim() {
|
||||
return type == EnumClaimType.CURRENCY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRefundClaim() {
|
||||
return type == EnumClaimType.REFUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getItem() {
|
||||
return item != null ? NpcAPI.Instance().getIItemStack(item) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemName() {
|
||||
return itemName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOtherPlayerName() {
|
||||
return otherPlayerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCreatedTime() {
|
||||
return createdTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClaimed() {
|
||||
return claimed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReturnedItem() {
|
||||
return isReturned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDaysUntilExpiration() {
|
||||
return getDaysUntilExpiration(ConfigMarket.ClaimExpirationDays);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpired() {
|
||||
return isExpired(ConfigMarket.ClaimExpirationDays);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("ID", id);
|
||||
compound.setString("PlayerUUID", playerUUID != null ? playerUUID.toString() : "");
|
||||
@@ -84,9 +206,12 @@ public class AuctionClaim {
|
||||
compound.setTag("Item", itemTag);
|
||||
}
|
||||
|
||||
compound.setString("ItemName", itemName != null ? itemName : "");
|
||||
compound.setString("OtherPlayerName", otherPlayerName != null ? otherPlayerName : "");
|
||||
compound.setLong("Currency", currency);
|
||||
compound.setLong("CreatedTime", createdTime);
|
||||
compound.setBoolean("Claimed", claimed);
|
||||
compound.setBoolean("IsReturned", isReturned);
|
||||
|
||||
return compound;
|
||||
}
|
||||
@@ -107,9 +232,12 @@ public class AuctionClaim {
|
||||
item = null;
|
||||
}
|
||||
|
||||
itemName = compound.getString("ItemName");
|
||||
otherPlayerName = compound.getString("OtherPlayerName");
|
||||
currency = compound.getLong("Currency");
|
||||
createdTime = compound.getLong("CreatedTime");
|
||||
claimed = compound.getBoolean("Claimed");
|
||||
isReturned = compound.getBoolean("IsReturned");
|
||||
}
|
||||
|
||||
public static AuctionClaim fromNBT(NBTTagCompound compound) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Filter for auction listings.
|
||||
* Supports search by item name and sorting options.
|
||||
* Supports search by item name or seller name and sorting options.
|
||||
*/
|
||||
public class AuctionFilter {
|
||||
private static final Pattern COLOR_CODE_PATTERN = Pattern.compile("§[0-9a-fk-or]", Pattern.CASE_INSENSITIVE);
|
||||
@@ -37,26 +37,42 @@ public class AuctionFilter {
|
||||
return stripped.toLowerCase().trim();
|
||||
}
|
||||
|
||||
/** Check if item name matches search text */
|
||||
public boolean matchesSearch(String itemName) {
|
||||
/** Check if item name or seller name matches search text */
|
||||
public boolean matchesSearch(String itemName, String sellerName) {
|
||||
if (!hasSearchText()) return true;
|
||||
String normalized = normalizeForSearch(itemName);
|
||||
return normalized.contains(normalizedSearch);
|
||||
String normalizedItem = normalizeForSearch(itemName);
|
||||
String normalizedSeller = normalizeForSearch(sellerName);
|
||||
// Match if search text is found in either item name or seller name
|
||||
return normalizedItem.contains(normalizedSearch) || normalizedSeller.contains(normalizedSearch);
|
||||
}
|
||||
|
||||
/** Advanced search - all words must be present */
|
||||
public boolean matchesSearchAdvanced(String itemName) {
|
||||
/** Legacy method - only checks item name */
|
||||
public boolean matchesSearch(String itemName) {
|
||||
return matchesSearch(itemName, "");
|
||||
}
|
||||
|
||||
/** Advanced search - all words must be present in item name OR seller name */
|
||||
public boolean matchesSearchAdvanced(String itemName, String sellerName) {
|
||||
if (!hasSearchText()) return true;
|
||||
String normalized = normalizeForSearch(itemName);
|
||||
String normalizedItem = normalizeForSearch(itemName);
|
||||
String normalizedSeller = normalizeForSearch(sellerName);
|
||||
String[] words = normalizedSearch.split("\\s+");
|
||||
for (String word : words) {
|
||||
if (!word.isEmpty() && !normalized.contains(word)) {
|
||||
return false;
|
||||
if (!word.isEmpty()) {
|
||||
// Word must be in item name OR seller name
|
||||
if (!normalizedItem.contains(word) && !normalizedSeller.contains(word)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Legacy method - only checks item name */
|
||||
public boolean matchesSearchAdvanced(String itemName) {
|
||||
return matchesSearchAdvanced(itemName, "");
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
searchText = "";
|
||||
sortBy = EnumAuctionSort.NEWEST;
|
||||
|
||||
@@ -2,11 +2,15 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.handler.data.IAuctionListing;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
import noppes.npcs.constants.EnumAuctionStatus;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuctionListing {
|
||||
public class AuctionListing implements IAuctionListing {
|
||||
public String id;
|
||||
public UUID sellerUUID;
|
||||
public String sellerName;
|
||||
@@ -40,22 +44,6 @@ public class AuctionListing {
|
||||
this.endTime = this.createdTime + durationMs;
|
||||
}
|
||||
|
||||
public boolean hasBids() {
|
||||
return bidCount > 0 && highBidderUUID != null;
|
||||
}
|
||||
|
||||
public boolean hasBuyout() {
|
||||
return buyoutPrice > 0;
|
||||
}
|
||||
|
||||
public boolean isExpired() {
|
||||
return System.currentTimeMillis() >= endTime;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return status == EnumAuctionStatus.ACTIVE && !isExpired();
|
||||
}
|
||||
|
||||
public long getTimeRemaining() {
|
||||
return Math.max(0, endTime - System.currentTimeMillis());
|
||||
}
|
||||
@@ -88,6 +76,136 @@ public class AuctionListing {
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// IAuctionListing Implementation
|
||||
// =========================================
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSellerUUID() {
|
||||
return sellerUUID != null ? sellerUUID.toString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSellerName() {
|
||||
return sellerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getItem() {
|
||||
return item != null ? NpcAPI.Instance().getIItemStack(item) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartingPrice() {
|
||||
return startingPrice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBuyoutPrice() {
|
||||
return buyoutPrice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCurrentBid() {
|
||||
return currentBid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHighBidderUUID() {
|
||||
return highBidderUUID != null ? highBidderUUID.toString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHighBidderName() {
|
||||
return highBidderName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBidCount() {
|
||||
return bidCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCreatedTime() {
|
||||
return createdTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRemainingTime() {
|
||||
return getTimeRemaining();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatus() {
|
||||
return status.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMinimumBid() {
|
||||
return getMinimumBid(ConfigMarket.MinBidIncrementPercent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSeller(String playerUUID) {
|
||||
if (playerUUID == null || sellerUUID == null) return false;
|
||||
return sellerUUID.toString().equals(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHighBidder(String playerUUID) {
|
||||
if (playerUUID == null || highBidderUUID == null) return false;
|
||||
return highBidderUUID.toString().equals(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemainingTimeFormatted() {
|
||||
long remaining = getTimeRemaining();
|
||||
if (remaining <= 0) return "Ended";
|
||||
|
||||
long hours = remaining / (60 * 60 * 1000);
|
||||
long minutes = (remaining % (60 * 60 * 1000)) / (60 * 1000);
|
||||
|
||||
if (hours > 0) {
|
||||
return hours + "h " + minutes + "m";
|
||||
} else if (minutes > 0) {
|
||||
return minutes + "m";
|
||||
} else {
|
||||
long seconds = (remaining % (60 * 1000)) / 1000;
|
||||
return seconds + "s";
|
||||
}
|
||||
}
|
||||
|
||||
// Override existing methods with @Override annotation
|
||||
@Override
|
||||
public boolean hasBids() {
|
||||
return bidCount > 0 && highBidderUUID != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBuyout() {
|
||||
return buyoutPrice > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpired() {
|
||||
return System.currentTimeMillis() >= endTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return status == EnumAuctionStatus.ACTIVE && !isExpired();
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("ID", id);
|
||||
compound.setString("SellerUUID", sellerUUID != null ? sellerUUID.toString() : "");
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.util.VaultUtil;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.handler.IPlayerCurrencyData;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
/**
|
||||
* Stores player currency balance.
|
||||
* This data is NOT profile slot bound - all profile slots share the same currency pool.
|
||||
* When Vault API is available and UseVault config is enabled, operations delegate to Vault.
|
||||
* The built-in CNPC+ currency data is always preserved in NBT, but unused when Vault is active.
|
||||
*/
|
||||
public class PlayerCurrencyData implements IPlayerCurrencyData {
|
||||
private final PlayerData playerData;
|
||||
|
||||
// Built-in CNPC+ currency (always saved, used as fallback)
|
||||
private long balance;
|
||||
private long lifetimeEarned;
|
||||
private long lifetimeSpent;
|
||||
|
||||
public PlayerCurrencyData(PlayerData playerData) {
|
||||
this.playerData = playerData;
|
||||
this.balance = ConfigMarket.StartingBalance;
|
||||
this.lifetimeEarned = 0;
|
||||
this.lifetimeSpent = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Vault should be used for currency operations.
|
||||
* Requires both config enabled AND Vault actually available.
|
||||
*/
|
||||
private boolean shouldUseVault() {
|
||||
return ConfigMarket.UseVault && VaultUtil.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get player name for Vault operations
|
||||
*/
|
||||
private String getPlayerName() {
|
||||
if (playerData != null && playerData.player != null) {
|
||||
return playerData.player.getCommandSenderName();
|
||||
}
|
||||
return playerData != null ? playerData.playername : null;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
if (compound.hasKey("CurrencyBalance")) {
|
||||
this.balance = compound.getLong("CurrencyBalance");
|
||||
} else {
|
||||
this.balance = ConfigMarket.StartingBalance;
|
||||
}
|
||||
this.lifetimeEarned = compound.getLong("CurrencyLifetimeEarned");
|
||||
this.lifetimeSpent = compound.getLong("CurrencyLifetimeSpent");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
// Always save built-in currency data (preserved even when using Vault)
|
||||
compound.setLong("CurrencyBalance", this.balance);
|
||||
compound.setLong("CurrencyLifetimeEarned", this.lifetimeEarned);
|
||||
compound.setLong("CurrencyLifetimeSpent", this.lifetimeSpent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current balance
|
||||
*/
|
||||
@Override
|
||||
public long getBalance() {
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
return (long) VaultUtil.getBalance(playerName);
|
||||
}
|
||||
}
|
||||
return balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the balance directly (use with caution)
|
||||
*/
|
||||
@Override
|
||||
public void setBalance(long balance) {
|
||||
if (balance < 0) {
|
||||
balance = 0;
|
||||
}
|
||||
if (balance > ConfigMarket.MaxBalance) {
|
||||
balance = ConfigMarket.MaxBalance;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
VaultUtil.setBalance(playerName, balance);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add currency to balance (deposit)
|
||||
*
|
||||
* @param amount Amount to add
|
||||
* @return true if successful, false if would exceed max balance
|
||||
*/
|
||||
@Override
|
||||
public boolean deposit(long amount) {
|
||||
if (amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
boolean success = VaultUtil.addMoney(playerName, amount);
|
||||
if (success) {
|
||||
this.lifetimeEarned += amount;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
// Built-in currency
|
||||
long newBalance = this.balance + amount;
|
||||
if (newBalance > ConfigMarket.MaxBalance) {
|
||||
return false;
|
||||
}
|
||||
if (newBalance < this.balance) {
|
||||
// Overflow protection
|
||||
return false;
|
||||
}
|
||||
this.balance = newBalance;
|
||||
this.lifetimeEarned += amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove currency from balance (withdraw)
|
||||
*
|
||||
* @param amount Amount to remove
|
||||
* @return true if successful, false if insufficient funds
|
||||
*/
|
||||
@Override
|
||||
public boolean withdraw(long amount) {
|
||||
if (amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
boolean success = VaultUtil.withdrawMoney(playerName, amount);
|
||||
if (success) {
|
||||
this.lifetimeSpent += amount;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
// Built-in currency
|
||||
if (this.balance < amount) {
|
||||
return false;
|
||||
}
|
||||
this.balance -= amount;
|
||||
this.lifetimeSpent += amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player can afford an amount
|
||||
*/
|
||||
@Override
|
||||
public boolean canAfford(long amount) {
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
return VaultUtil.has(playerName, amount);
|
||||
}
|
||||
}
|
||||
return this.balance >= amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lifetime earned currency
|
||||
*/
|
||||
@Override
|
||||
public long getLifetimeEarned() {
|
||||
return lifetimeEarned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lifetime spent currency
|
||||
*/
|
||||
@Override
|
||||
public long getLifetimeSpent() {
|
||||
return lifetimeSpent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the balance for display
|
||||
*/
|
||||
@Override
|
||||
public String formatBalance() {
|
||||
if (shouldUseVault()) {
|
||||
return VaultUtil.format(getBalance());
|
||||
}
|
||||
return formatAmount(this.balance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an amount for display
|
||||
*/
|
||||
public static String formatAmount(long amount) {
|
||||
return String.format("%,d %s", amount, ConfigMarket.CurrencyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Vault is being used for currency operations.
|
||||
* Returns true only if config is enabled AND Vault is actually available.
|
||||
*/
|
||||
@Override
|
||||
public boolean isUsingVault() {
|
||||
return shouldUseVault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Vault is configured (regardless of availability)
|
||||
*/
|
||||
public boolean isVaultConfigured() {
|
||||
return ConfigMarket.UseVault;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.handler.IPlayerBankData;
|
||||
import noppes.npcs.api.handler.IPlayerCurrencyData;
|
||||
import noppes.npcs.api.handler.IPlayerTradeData;
|
||||
import noppes.npcs.api.handler.IPlayerData;
|
||||
import noppes.npcs.api.handler.IPlayerDialogData;
|
||||
import noppes.npcs.api.handler.IPlayerFactionData;
|
||||
@@ -46,6 +46,8 @@ import java.io.FileOutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
||||
|
||||
public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public PlayerDialogData dialogData = new PlayerDialogData(this);
|
||||
public PlayerBankData bankData = new PlayerBankData(this);
|
||||
@@ -60,8 +62,8 @@ 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(this);
|
||||
// Trade data (currency + auction claims) - shared across all profile slots
|
||||
public PlayerTradeData tradeData = new PlayerTradeData(this);
|
||||
|
||||
public ActionManager actionManager = new ActionManager();
|
||||
public PlayerDataScript scriptData;
|
||||
@@ -134,6 +136,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
animationData.readFromNBT(data);
|
||||
effectData.readFromNBT(data);
|
||||
magicData.readToNBT(data);
|
||||
tradeData.readFromNBT(data);
|
||||
|
||||
if (player != null) {
|
||||
playername = player.getCommandSenderName();
|
||||
@@ -176,6 +179,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
animationData.writeToNBT(compound);
|
||||
effectData.writeToNBT(compound);
|
||||
magicData.writeToNBT(compound);
|
||||
tradeData.writeToNBT(compound);
|
||||
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
@@ -228,6 +232,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
transportData.saveNBTData(compound);
|
||||
factionData.saveNBTData(compound);
|
||||
mailData.saveNBTData(compound);
|
||||
tradeData.writeToNBT(compound);
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
DBCAddon.instance.writeToNBT(this, compound);
|
||||
@@ -241,6 +246,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
transportData.loadNBTData(data);
|
||||
factionData.loadNBTData(data);
|
||||
mailData.loadNBTData(data);
|
||||
tradeData.readFromNBT(data);
|
||||
if (player != null) {
|
||||
playername = player.getCommandSenderName();
|
||||
uuid = player.getPersistentID().toString();
|
||||
@@ -401,8 +407,8 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
return mailData;
|
||||
}
|
||||
|
||||
public IPlayerCurrencyData getCurrencyData() {
|
||||
return currencyData;
|
||||
public IPlayerTradeData getTradeData() {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
public synchronized void save() {
|
||||
@@ -414,9 +420,6 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
}
|
||||
|
||||
final NBTTagCompound compound = getNBT();
|
||||
// Currency data is saved at player level, NOT per profile slot
|
||||
currencyData.writeToNBT(compound);
|
||||
|
||||
final String filename;
|
||||
if (ConfigMain.DatFormat) {
|
||||
filename = uuid + ".dat";
|
||||
@@ -453,10 +456,6 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
if (data.hasNoTags()) {
|
||||
data = getNBT();
|
||||
}
|
||||
|
||||
// Load currency BEFORE setNBT - currency is player-level, NOT per profile slot
|
||||
currencyData.readFromNBT(data);
|
||||
|
||||
setNBT(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,414 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.util.VaultUtil;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.api.handler.IPlayerTradeData;
|
||||
import noppes.npcs.api.handler.data.IAuctionClaim;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* Stores player's trade-related data: currency and auction claims.
|
||||
* This data is shared across all profile slots.
|
||||
* Uses CopyOnWriteArrayList for thread-safety when adding claims asynchronously.
|
||||
*/
|
||||
public class PlayerTradeData implements IPlayerTradeData {
|
||||
// NBT key used by trade data - excluded from per-slot profile saving
|
||||
public static final String NBT_KEY = "TradeData";
|
||||
|
||||
private final PlayerData playerData;
|
||||
|
||||
// =========================================
|
||||
// Currency Data
|
||||
// =========================================
|
||||
|
||||
// Built-in CNPC+ currency (always saved, used as fallback)
|
||||
private long balance;
|
||||
private long lifetimeEarned;
|
||||
private long lifetimeSpent;
|
||||
|
||||
// =========================================
|
||||
// Auction Claims Data
|
||||
// =========================================
|
||||
|
||||
// Thread-safe list for claims - can be modified from CNPC+ thread
|
||||
private final CopyOnWriteArrayList<AuctionClaim> claims = new CopyOnWriteArrayList<>();
|
||||
|
||||
public PlayerTradeData(PlayerData playerData) {
|
||||
this.playerData = playerData;
|
||||
this.balance = ConfigMarket.StartingBalance;
|
||||
this.lifetimeEarned = 0;
|
||||
this.lifetimeSpent = 0;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Currency Methods
|
||||
// =========================================
|
||||
|
||||
/**
|
||||
* Check if Vault should be used for currency operations.
|
||||
* Requires both config enabled AND Vault actually available.
|
||||
*/
|
||||
private boolean shouldUseVault() {
|
||||
return ConfigMarket.UseVault && VaultUtil.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get player name for Vault operations
|
||||
*/
|
||||
private String getPlayerName() {
|
||||
if (playerData != null && playerData.player != null) {
|
||||
return playerData.player.getCommandSenderName();
|
||||
}
|
||||
return playerData != null ? playerData.playername : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current balance
|
||||
*/
|
||||
@Override
|
||||
public long getBalance() {
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
return (long) VaultUtil.getBalance(playerName);
|
||||
}
|
||||
}
|
||||
return balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the balance directly (use with caution)
|
||||
*/
|
||||
@Override
|
||||
public void setBalance(long balance) {
|
||||
if (balance < 0) {
|
||||
balance = 0;
|
||||
}
|
||||
if (balance > ConfigMarket.MaxBalance) {
|
||||
balance = ConfigMarket.MaxBalance;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
VaultUtil.setBalance(playerName, balance);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add currency to balance (deposit)
|
||||
*
|
||||
* @param amount Amount to add
|
||||
* @return true if successful, false if would exceed max balance
|
||||
*/
|
||||
@Override
|
||||
public boolean deposit(long amount) {
|
||||
if (amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
boolean success = VaultUtil.addMoney(playerName, amount);
|
||||
if (success) {
|
||||
this.lifetimeEarned += amount;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
// Built-in currency
|
||||
long newBalance = this.balance + amount;
|
||||
if (newBalance > ConfigMarket.MaxBalance) {
|
||||
return false;
|
||||
}
|
||||
if (newBalance < this.balance) {
|
||||
// Overflow protection
|
||||
return false;
|
||||
}
|
||||
this.balance = newBalance;
|
||||
this.lifetimeEarned += amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove currency from balance (withdraw)
|
||||
*
|
||||
* @param amount Amount to remove
|
||||
* @return true if successful, false if insufficient funds
|
||||
*/
|
||||
@Override
|
||||
public boolean withdraw(long amount) {
|
||||
if (amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
boolean success = VaultUtil.withdrawMoney(playerName, amount);
|
||||
if (success) {
|
||||
this.lifetimeSpent += amount;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
// Built-in currency
|
||||
if (this.balance < amount) {
|
||||
return false;
|
||||
}
|
||||
this.balance -= amount;
|
||||
this.lifetimeSpent += amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player can afford an amount
|
||||
*/
|
||||
@Override
|
||||
public boolean canAfford(long amount) {
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
return VaultUtil.has(playerName, amount);
|
||||
}
|
||||
}
|
||||
return this.balance >= amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lifetime earned currency
|
||||
*/
|
||||
@Override
|
||||
public long getLifetimeEarned() {
|
||||
return lifetimeEarned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lifetime spent currency
|
||||
*/
|
||||
@Override
|
||||
public long getLifetimeSpent() {
|
||||
return lifetimeSpent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the balance for display
|
||||
*/
|
||||
@Override
|
||||
public String formatBalance() {
|
||||
if (shouldUseVault()) {
|
||||
return VaultUtil.format(getBalance());
|
||||
}
|
||||
return formatAmount(this.balance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an amount for display
|
||||
*/
|
||||
public static String formatAmount(long amount) {
|
||||
return String.format("%,d %s", amount, ConfigMarket.CurrencyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Vault is being used for currency operations.
|
||||
* Returns true only if config is enabled AND Vault is actually available.
|
||||
*/
|
||||
@Override
|
||||
public boolean isUsingVault() {
|
||||
return shouldUseVault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Vault is configured (regardless of availability)
|
||||
*/
|
||||
public boolean isVaultConfigured() {
|
||||
return ConfigMarket.UseVault;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Auction Claims Methods
|
||||
// =========================================
|
||||
|
||||
/**
|
||||
* Add a claim to this player's pending claims.
|
||||
* Thread-safe - can be called from any thread.
|
||||
*/
|
||||
public void addClaim(AuctionClaim claim) {
|
||||
if (claim != null && !claim.claimed) {
|
||||
claims.add(claim);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all unclaimed claims for this player (internal use).
|
||||
* Returns a copy of the list for safe iteration.
|
||||
*/
|
||||
public List<AuctionClaim> getClaimsList() {
|
||||
List<AuctionClaim> result = new ArrayList<>();
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (!claim.claimed) {
|
||||
result.add(claim);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all unclaimed claims for this player (API).
|
||||
*/
|
||||
@Override
|
||||
public IAuctionClaim[] getClaims() {
|
||||
List<AuctionClaim> result = getClaimsList();
|
||||
return result.toArray(new IAuctionClaim[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific claim by ID (internal use).
|
||||
*/
|
||||
public AuctionClaim getClaimInternal(String claimId) {
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (claim.id.equals(claimId) && !claim.claimed) {
|
||||
return claim;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific claim by ID (API).
|
||||
*/
|
||||
@Override
|
||||
public IAuctionClaim getClaim(String claimId) {
|
||||
return getClaimInternal(claimId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a claim as claimed and remove it.
|
||||
*/
|
||||
public boolean claimAndRemove(String claimId) {
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (claim.id.equals(claimId) && !claim.claimed) {
|
||||
claim.claimed = true;
|
||||
claims.remove(claim);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get count of unclaimed claims.
|
||||
*/
|
||||
@Override
|
||||
public int getClaimCount() {
|
||||
int count = 0;
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (!claim.claimed) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player has any unclaimed claims.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasClaims() {
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (!claim.claimed) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process expired claims - removes claims older than expiration days.
|
||||
* Returns number of claims removed.
|
||||
*/
|
||||
public int processExpiredClaims() {
|
||||
int expirationDays = ConfigMarket.ClaimExpirationDays;
|
||||
int removed = 0;
|
||||
|
||||
Iterator<AuctionClaim> iterator = claims.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
AuctionClaim claim = iterator.next();
|
||||
if (!claim.claimed && claim.isExpired(expirationDays)) {
|
||||
claims.remove(claim);
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// NBT Serialization
|
||||
// =========================================
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
NBTTagCompound tradeData = compound.getCompoundTag(NBT_KEY);
|
||||
if (tradeData == null || tradeData.hasNoTags()) {
|
||||
// No trade data found, use defaults
|
||||
this.balance = ConfigMarket.StartingBalance;
|
||||
this.lifetimeEarned = 0;
|
||||
this.lifetimeSpent = 0;
|
||||
claims.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// Currency
|
||||
if (tradeData.hasKey("CurrencyBalance")) {
|
||||
this.balance = tradeData.getLong("CurrencyBalance");
|
||||
} else {
|
||||
this.balance = ConfigMarket.StartingBalance;
|
||||
}
|
||||
this.lifetimeEarned = tradeData.getLong("CurrencyLifetimeEarned");
|
||||
this.lifetimeSpent = tradeData.getLong("CurrencyLifetimeSpent");
|
||||
|
||||
// Claims
|
||||
claims.clear();
|
||||
if (tradeData.hasKey("AuctionClaims")) {
|
||||
NBTTagList claimsList = tradeData.getTagList("AuctionClaims", 10);
|
||||
for (int i = 0; i < claimsList.tagCount(); i++) {
|
||||
AuctionClaim claim = AuctionClaim.fromNBT(claimsList.getCompoundTagAt(i));
|
||||
if (!claim.claimed) {
|
||||
claims.add(claim);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
NBTTagCompound tradeData = new NBTTagCompound();
|
||||
|
||||
// Currency - always save built-in currency data (preserved even when using Vault)
|
||||
tradeData.setLong("CurrencyBalance", this.balance);
|
||||
tradeData.setLong("CurrencyLifetimeEarned", this.lifetimeEarned);
|
||||
tradeData.setLong("CurrencyLifetimeSpent", this.lifetimeSpent);
|
||||
|
||||
// Claims
|
||||
NBTTagList claimsList = new NBTTagList();
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (!claim.claimed) {
|
||||
claimsList.appendTag(claim.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
tradeData.setTag("AuctionClaims", claimsList);
|
||||
|
||||
compound.setTag(NBT_KEY, tradeData);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user