2026-01-23 21:53:12 -05:00
|
|
|
package noppes.npcs.controllers.data;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2026-01-24 15:11:50 -05:00
|
|
|
import noppes.npcs.api.handler.data.IAuctionClaim;
|
|
|
|
|
import noppes.npcs.api.item.IItemStack;
|
|
|
|
|
import noppes.npcs.config.ConfigMarket;
|
2026-01-23 21:53:12 -05:00
|
|
|
import noppes.npcs.constants.EnumClaimType;
|
2026-01-24 15:11:50 -05:00
|
|
|
import noppes.npcs.scripted.NpcAPI;
|
2026-01-23 21:53:12 -05:00
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
2026-01-24 15:11:50 -05:00
|
|
|
public class AuctionClaim implements IAuctionClaim {
|
2026-01-23 21:53:12 -05:00
|
|
|
public String id;
|
|
|
|
|
public UUID playerUUID;
|
|
|
|
|
public String playerName;
|
|
|
|
|
public String listingId;
|
|
|
|
|
public EnumClaimType type;
|
2026-01-24 01:57:46 -05:00
|
|
|
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)
|
2026-01-23 21:53:12 -05:00
|
|
|
public long currency;
|
|
|
|
|
public long createdTime;
|
|
|
|
|
public boolean claimed;
|
2026-01-24 01:57:46 -05:00
|
|
|
public boolean isReturned; // For ITEM claims: true if returned to seller, false if won by buyer
|
2026-01-23 21:53:12 -05:00
|
|
|
|
|
|
|
|
public AuctionClaim() {
|
|
|
|
|
this.id = UUID.randomUUID().toString();
|
|
|
|
|
this.createdTime = System.currentTimeMillis();
|
|
|
|
|
this.claimed = false;
|
2026-01-24 01:57:46 -05:00
|
|
|
this.isReturned = false;
|
|
|
|
|
this.itemName = "";
|
|
|
|
|
this.otherPlayerName = "";
|
2026-01-23 21:53:12 -05:00
|
|
|
}
|
|
|
|
|
|
2026-02-18 05:13:51 -05:00
|
|
|
/**
|
|
|
|
|
* Create claim for winning an item (buyer won auction or buyout)
|
|
|
|
|
*/
|
2026-01-24 01:57:46 -05:00
|
|
|
public static AuctionClaim createItemWonClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
2026-01-23 21:53:12 -05:00
|
|
|
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;
|
2026-01-24 01:57:46 -05:00
|
|
|
claim.isReturned = false;
|
2026-01-23 21:53:12 -05:00
|
|
|
return claim;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-18 05:13:51 -05:00
|
|
|
/**
|
|
|
|
|
* Create claim for returned item (seller's expired/cancelled listing)
|
|
|
|
|
*/
|
2026-01-24 01:57:46 -05:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-18 05:13:51 -05:00
|
|
|
/**
|
|
|
|
|
* Create claim for seller's proceeds (stores item name for tooltip, not full item)
|
|
|
|
|
*/
|
2026-01-24 01:57:46 -05:00
|
|
|
public static AuctionClaim createCurrencyClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String buyerName) {
|
2026-01-23 21:53:12 -05:00
|
|
|
AuctionClaim claim = new AuctionClaim();
|
|
|
|
|
claim.playerUUID = playerUUID;
|
|
|
|
|
claim.playerName = playerName;
|
|
|
|
|
claim.listingId = listingId;
|
|
|
|
|
claim.type = EnumClaimType.CURRENCY;
|
2026-01-24 01:57:46 -05:00
|
|
|
claim.item = null; // No item stored for currency claims
|
|
|
|
|
claim.itemName = itemName != null ? itemName : "";
|
|
|
|
|
claim.otherPlayerName = buyerName != null ? buyerName : "";
|
2026-01-23 21:53:12 -05:00
|
|
|
claim.currency = currency;
|
2026-01-24 01:57:46 -05:00
|
|
|
claim.isReturned = false;
|
2026-01-23 21:53:12 -05:00
|
|
|
return claim;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-18 05:13:51 -05:00
|
|
|
/**
|
|
|
|
|
* Create claim for outbid refund (stores item for display and rebid option)
|
|
|
|
|
*/
|
2026-01-24 03:24:57 -05:00
|
|
|
public static AuctionClaim createRefundClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String outbidderName, ItemStack item) {
|
2026-01-23 21:53:12 -05:00
|
|
|
AuctionClaim claim = new AuctionClaim();
|
|
|
|
|
claim.playerUUID = playerUUID;
|
|
|
|
|
claim.playerName = playerName;
|
|
|
|
|
claim.listingId = listingId;
|
|
|
|
|
claim.type = EnumClaimType.REFUND;
|
2026-01-24 03:24:57 -05:00
|
|
|
claim.item = item != null ? item.copy() : null; // Store item for display and rebid
|
2026-01-24 01:57:46 -05:00
|
|
|
claim.itemName = itemName != null ? itemName : "";
|
|
|
|
|
claim.otherPlayerName = outbidderName != null ? outbidderName : "";
|
2026-01-23 21:53:12 -05:00
|
|
|
claim.currency = currency;
|
2026-01-24 01:57:46 -05:00
|
|
|
claim.isReturned = false;
|
2026-01-23 21:53:12 -05:00
|
|
|
return claim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isExpired(int expirationDays) {
|
|
|
|
|
long expirationMs = expirationDays * 24L * 60L * 60L * 1000L;
|
|
|
|
|
return System.currentTimeMillis() - createdTime > expirationMs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long getDaysUntilExpiration(int expirationDays) {
|
|
|
|
|
long expirationMs = expirationDays * 24L * 60L * 60L * 1000L;
|
|
|
|
|
long remaining = (createdTime + expirationMs) - System.currentTimeMillis();
|
|
|
|
|
return Math.max(0, remaining / (24L * 60L * 60L * 1000L));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isForPlayer(UUID uuid) {
|
|
|
|
|
return playerUUID != null && playerUUID.equals(uuid);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 15:11:50 -05:00
|
|
|
// =========================================
|
|
|
|
|
// 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() {
|
2026-02-18 04:55:03 -05:00
|
|
|
return type.isCurrency();
|
2026-01-24 15:11:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-23 21:53:12 -05:00
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
|
|
|
|
compound.setString("ID", id);
|
|
|
|
|
compound.setString("PlayerUUID", playerUUID != null ? playerUUID.toString() : "");
|
|
|
|
|
compound.setString("PlayerName", playerName != null ? playerName : "");
|
|
|
|
|
compound.setString("ListingID", listingId != null ? listingId : "");
|
|
|
|
|
compound.setInteger("Type", type.ordinal());
|
|
|
|
|
|
|
|
|
|
if (item != null) {
|
|
|
|
|
NBTTagCompound itemTag = new NBTTagCompound();
|
|
|
|
|
item.writeToNBT(itemTag);
|
|
|
|
|
compound.setTag("Item", itemTag);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 01:57:46 -05:00
|
|
|
compound.setString("ItemName", itemName != null ? itemName : "");
|
|
|
|
|
compound.setString("OtherPlayerName", otherPlayerName != null ? otherPlayerName : "");
|
2026-01-23 21:53:12 -05:00
|
|
|
compound.setLong("Currency", currency);
|
|
|
|
|
compound.setLong("CreatedTime", createdTime);
|
|
|
|
|
compound.setBoolean("Claimed", claimed);
|
2026-01-24 01:57:46 -05:00
|
|
|
compound.setBoolean("IsReturned", isReturned);
|
2026-01-23 21:53:12 -05:00
|
|
|
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void readFromNBT(NBTTagCompound compound) {
|
|
|
|
|
id = compound.getString("ID");
|
|
|
|
|
|
|
|
|
|
String playerUUIDStr = compound.getString("PlayerUUID");
|
|
|
|
|
playerUUID = playerUUIDStr.isEmpty() ? null : UUID.fromString(playerUUIDStr);
|
|
|
|
|
playerName = compound.getString("PlayerName");
|
|
|
|
|
|
|
|
|
|
listingId = compound.getString("ListingID");
|
|
|
|
|
type = EnumClaimType.fromOrdinal(compound.getInteger("Type"));
|
|
|
|
|
|
|
|
|
|
if (compound.hasKey("Item")) {
|
|
|
|
|
item = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("Item"));
|
|
|
|
|
} else {
|
|
|
|
|
item = null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 01:57:46 -05:00
|
|
|
itemName = compound.getString("ItemName");
|
|
|
|
|
otherPlayerName = compound.getString("OtherPlayerName");
|
2026-01-23 21:53:12 -05:00
|
|
|
currency = compound.getLong("Currency");
|
|
|
|
|
createdTime = compound.getLong("CreatedTime");
|
|
|
|
|
claimed = compound.getBoolean("Claimed");
|
2026-01-24 01:57:46 -05:00
|
|
|
isReturned = compound.getBoolean("IsReturned");
|
2026-01-23 21:53:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AuctionClaim fromNBT(NBTTagCompound compound) {
|
|
|
|
|
AuctionClaim claim = new AuctionClaim();
|
|
|
|
|
claim.readFromNBT(compound);
|
|
|
|
|
return claim;
|
|
|
|
|
}
|
|
|
|
|
}
|