Large Auction Cleanup + Auction Events

- Auction Enums
- Better Notification Handling
- Auction Cancelation Events
- Lang Key Cleanup
This commit is contained in:
Kam committed 2026-02-18 04:55:03 -05:00
1 parent 0512588a7a
commit 4510b3bbd1
31 files changed
+889 -578

No files matched your search

@@ -40,7 +40,7 @@ public class AuctionConfigSync {
public static String getEffectiveCurrencyName() {
if (ConfigMarket.UseVault && VaultUtil.isEnabled()) {
String vaultName = VaultUtil.getCurrencyNamePlural();
if (vaultName != null && !vaultName.isEmpty() && !vaultName.equals("coins")) {
if (vaultName != null && !vaultName.isEmpty()) {
return vaultName;
}
}
@@ -11,22 +11,27 @@ import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import noppes.npcs.CustomNpcs;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.EventHooks;
import noppes.npcs.LogWriter;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.IAuctionHandler;
import noppes.npcs.api.handler.data.IAuctionListing;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.config.ConfigMarket;
import noppes.npcs.constants.EnumAuctionLogAction;
import noppes.npcs.constants.EnumAuctionSort;
import noppes.npcs.constants.EnumAuctionStatus;
import noppes.npcs.constants.EnumClaimType;
import noppes.npcs.constants.EnumNotificationType;
import noppes.npcs.controllers.data.PlayerDataScript;
import noppes.npcs.controllers.data.AuctionBlacklist;
import noppes.npcs.controllers.data.AuctionClaim;
import noppes.npcs.controllers.data.AuctionFilter;
import noppes.npcs.controllers.data.AuctionListing;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.controllers.data.PlayerTradeData;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.player.AuctionEvent;
import noppes.npcs.util.CustomNPCsThreader;
import java.io.File;
@@ -138,52 +143,56 @@ public class AuctionController implements IAuctionHandler {
}
private void endAuction(AuctionListing listing) {
listing.status = EnumAuctionStatus.ENDED;
synchronized (listing) {
if (listing.status != EnumAuctionStatus.ACTIVE) return;
// Remove from seller's active listings
removeFromPlayerListings(listing.sellerUUID, listing.id);
listing.status = EnumAuctionStatus.ENDED;
// Remove from bidder's active bids if any
if (listing.highBidderUUID != null) {
removeFromPlayerBids(listing.highBidderUUID, listing.id);
}
// Remove from seller's active listings
removeFromPlayerListings(listing.sellerUUID, listing.id);
// Get item display name safely
String itemDisplayName = listing.item != null ? listing.item.getDisplayName() : "Unknown Item";
// Remove from bidder's active bids if any
if (listing.highBidderUUID != null) {
removeFromPlayerBids(listing.highBidderUUID, listing.id);
}
if (listing.hasBids()) {
// Auction sold - create claims
AuctionClaim itemClaim = AuctionClaim.createItemWonClaim(
listing.highBidderUUID, listing.highBidderName, listing.id, listing.item);
addClaimToPlayer(listing.highBidderUUID, itemClaim);
// Get item display name safely
String itemDisplayName = listing.item != null ? listing.item.getDisplayName() : "Unknown Item";
long saleAmount = listing.currentBid;
long tax = (long) (saleAmount * ConfigMarket.SalesTaxPercent);
long sellerReceives = saleAmount - tax;
if (listing.hasBids()) {
// Auction sold - create claims
AuctionClaim itemClaim = AuctionClaim.createItemWonClaim(
listing.highBidderUUID, listing.highBidderName, listing.id, listing.item);
addClaimToPlayer(listing.highBidderUUID, itemClaim);
AuctionClaim currencyClaim = AuctionClaim.createCurrencyClaim(
listing.sellerUUID, listing.sellerName, listing.id, sellerReceives,
itemDisplayName, listing.highBidderName);
addClaimToPlayer(listing.sellerUUID, currencyClaim);
long saleAmount = listing.currentBid;
long tax = (long) (saleAmount * ConfigMarket.SalesTaxPercent);
long sellerReceives = saleAmount - tax;
// Notifications
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_WON, listing.id,
"You won the auction for " + itemDisplayName + "!");
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
"Your " + itemDisplayName + " sold for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
AuctionClaim currencyClaim = AuctionClaim.createCurrencyClaim(
listing.sellerUUID, listing.sellerName, listing.id, sellerReceives,
itemDisplayName, listing.highBidderName);
addClaimToPlayer(listing.sellerUUID, currencyClaim);
logAuction("SOLD", listing.sellerName, itemDisplayName, saleAmount,
"Winner: " + listing.highBidderName + ", Tax: " + tax);
} else {
// No bids - return item to seller
AuctionClaim returnClaim = AuctionClaim.createItemReturnedClaim(
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
addClaimToPlayer(listing.sellerUUID, returnClaim);
// Notifications
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_WON, listing.id,
"You won the auction for " + itemDisplayName + "!");
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
"Your " + itemDisplayName + " sold for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_EXPIRED, listing.id,
"Your auction for " + itemDisplayName + " expired with no bids.");
logAuction(EnumAuctionLogAction.SOLD, listing.sellerName, itemDisplayName, saleAmount,
"Winner: " + listing.highBidderName + ", Tax: " + tax);
} else {
// No bids - return item to seller
AuctionClaim returnClaim = AuctionClaim.createItemReturnedClaim(
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
addClaimToPlayer(listing.sellerUUID, returnClaim);
logAuction("EXPIRED", listing.sellerName, itemDisplayName, listing.startingPrice, "No bids");
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_EXPIRED, listing.id,
"Your auction for " + itemDisplayName + " expired with no bids.");
logAuction(EnumAuctionLogAction.EXPIRED, listing.sellerName, itemDisplayName, listing.startingPrice, "No bids");
}
}
}
@@ -280,6 +289,15 @@ public class AuctionController implements IAuctionHandler {
return "You cannot afford the listing fee (" + fee + " " + ConfigMarket.CurrencyName + ").";
}
// Fire auction create event (cancelable)
PlayerDataScript createHandler = ScriptController.Instance.getPlayerScripts(player);
IPlayer iCreator = (IPlayer) NpcAPI.Instance().getIEntity(player);
AuctionEvent.CreateEvent createEvent = new AuctionEvent.CreateEvent(
iCreator, NpcAPI.Instance().getIItemStack(item), startingPrice, buyoutPrice);
if (EventHooks.onAuctionCreate(createHandler, createEvent)) {
return "Auction creation was cancelled.";
}
// Deduct fee
if (!currency.withdraw(fee)) {
return "Failed to deduct listing fee.";
@@ -295,7 +313,7 @@ public class AuctionController implements IAuctionHandler {
markDirty();
logAuction("CREATED", playerName, item.getDisplayName(), startingPrice,
logAuction(EnumAuctionLogAction.CREATED, playerName, item.getDisplayName(), startingPrice,
"Buyout: " + (buyoutPrice > 0 ? buyoutPrice : "None") + ", Fee: " + fee);
return null; // Success
@@ -307,55 +325,74 @@ public class AuctionController implements IAuctionHandler {
return "Listing not found.";
}
if (!listing.status.canCancel()) {
return "This auction cannot be cancelled.";
synchronized (listing) {
if (!listing.status.canCancel()) {
return "This auction cannot be cancelled.";
}
UUID playerUUID = player.getUniqueID();
if (!isAdmin && !listing.isSeller(playerUUID)) {
return "You can only cancel your own listings.";
}
// Fire auction cancel event (cancelable)
PlayerDataScript cancelHandler = ScriptController.Instance.getPlayerScripts(player);
IPlayer iCanceller = (IPlayer) NpcAPI.Instance().getIEntity(player);
AuctionEvent.CancelEvent cancelEvent = new AuctionEvent.CancelEvent(iCanceller, listing, isAdmin);
if (EventHooks.onAuctionCancel(cancelHandler, cancelEvent)) {
return "Auction cancellation was prevented.";
}
// Handle penalty if there are bids
if (listing.hasBids()) {
long penalty = (long) (listing.currentBid * ConfigMarket.CancellationPenaltyPercent);
// Refund bidder (no item - can't rebid on cancelled auction)
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
listing.highBidderUUID, listing.highBidderName, listing.id, listing.currentBid,
listing.item.getDisplayName(), listing.sellerName, null);
addClaimToPlayer(listing.highBidderUUID, refundClaim);
// Remove from bidder's active bids
removeFromPlayerBids(listing.highBidderUUID, listing.id);
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_OUTBID, listing.id,
"The auction for " + listing.item.getDisplayName() + " was cancelled. Your bid has been refunded.");
// Return item to seller
AuctionClaim itemClaim = AuctionClaim.createItemReturnedClaim(
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
addClaimToPlayer(listing.sellerUUID, itemClaim);
// Deduct cancellation penalty from seller
if (penalty > 0) {
PlayerData sellerData = PlayerDataController.Instance.getData(listing.sellerUUID);
if (sellerData != null) {
sellerData.tradeData.withdraw(penalty);
sellerData.save();
}
}
logAuction(EnumAuctionLogAction.CANCELLED, listing.sellerName, listing.item.getDisplayName(), listing.currentBid,
"Penalty: " + penalty + ", Bidder refunded: " + listing.highBidderName +
(isAdmin ? ", Cancelled by admin: " + player.getCommandSenderName() : ""));
} else {
// No bids - just return item
AuctionClaim itemClaim = AuctionClaim.createItemReturnedClaim(
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
addClaimToPlayer(listing.sellerUUID, itemClaim);
logAuction(EnumAuctionLogAction.CANCELLED, listing.sellerName, listing.item.getDisplayName(), listing.startingPrice,
"No bids" + (isAdmin ? ", Cancelled by admin: " + player.getCommandSenderName() : ""));
}
// Remove from seller's active listings
removeFromPlayerListings(listing.sellerUUID, listing.id);
listing.status = EnumAuctionStatus.CANCELLED;
markDirty();
}
UUID playerUUID = player.getUniqueID();
if (!isAdmin && !listing.isSeller(playerUUID)) {
return "You can only cancel your own listings.";
}
// Handle penalty if there are bids
if (listing.hasBids()) {
long penalty = (long) (listing.currentBid * ConfigMarket.CancellationPenaltyPercent);
// Refund bidder (no item - can't rebid on cancelled auction)
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
listing.highBidderUUID, listing.highBidderName, listing.id, listing.currentBid,
listing.item.getDisplayName(), listing.sellerName, null);
addClaimToPlayer(listing.highBidderUUID, refundClaim);
// Remove from bidder's active bids
removeFromPlayerBids(listing.highBidderUUID, listing.id);
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_OUTBID, listing.id,
"The auction for " + listing.item.getDisplayName() + " was cancelled. Your bid has been refunded.");
// Return item to seller
AuctionClaim itemClaim = AuctionClaim.createItemReturnedClaim(
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
addClaimToPlayer(listing.sellerUUID, itemClaim);
logAuction("CANCELLED", listing.sellerName, listing.item.getDisplayName(), listing.currentBid,
"Penalty: " + penalty + ", Bidder refunded: " + listing.highBidderName +
(isAdmin ? ", Cancelled by admin: " + player.getCommandSenderName() : ""));
} else {
// No bids - just return item
AuctionClaim itemClaim = AuctionClaim.createItemReturnedClaim(
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
addClaimToPlayer(listing.sellerUUID, itemClaim);
logAuction("CANCELLED", listing.sellerName, listing.item.getDisplayName(), listing.startingPrice,
"No bids" + (isAdmin ? ", Cancelled by admin: " + player.getCommandSenderName() : ""));
}
// Remove from seller's active listings
removeFromPlayerListings(listing.sellerUUID, listing.id);
listing.status = EnumAuctionStatus.CANCELLED;
markDirty();
return null; // Success
}
@@ -376,75 +413,85 @@ public class AuctionController implements IAuctionHandler {
return "Listing not found.";
}
// Check status and expiry
if (!listing.status.canBid()) {
return "This auction has ended.";
synchronized (listing) {
// Check status and expiry
if (!listing.status.canBid()) {
return "This auction has ended.";
}
if (listing.isExpired()) {
return "This auction has ended.";
}
// CRITICAL: Prevent bidding on own items
if (listing.isSeller(playerUUID)) {
return "You cannot bid on your own auction.";
}
// Prevent rebidding if already highest bidder
if (listing.isHighBidder(playerUUID)) {
return "You are already the highest bidder. Use buyout if you want to purchase immediately.";
}
// Check minimum bid
long minBid = listing.getMinimumBid(ConfigMarket.MinBidIncrementPercent);
if (bidAmount < minBid) {
return "Bid must be at least " + minBid + " " + ConfigMarket.CurrencyName + ".";
}
// Check currency
PlayerData playerData = PlayerData.get(player);
if (playerData == null) {
return "Could not access player data.";
}
PlayerTradeData currency = playerData.tradeData;
// Store previous bidder info
UUID previousBidder = listing.highBidderUUID;
long previousBid = listing.currentBid;
// Full bid amount charged since we don't allow rebidding
long amountToCharge = bidAmount;
if (!currency.canAfford(amountToCharge)) {
return "You cannot afford this bid.";
}
// Fire auction bid event (cancelable)
PlayerDataScript bidHandler = ScriptController.Instance.getPlayerScripts(player);
IPlayer iBidder = (IPlayer) NpcAPI.Instance().getIEntity(player);
AuctionEvent.BidEvent bidEvent = new AuctionEvent.BidEvent(iBidder, listing, bidAmount);
if (EventHooks.onAuctionBid(bidHandler, bidEvent)) {
return "Bid was cancelled.";
}
// Deduct bid from new bidder FIRST
if (!currency.withdraw(amountToCharge)) {
return "Failed to deduct bid amount.";
}
// Refund previous bidder (include item for rebid option)
if (listing.hasBids() && previousBidder != null) {
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
previousBidder, listing.highBidderName, listing.id, previousBid,
listing.item.getDisplayName(), playerName, listing.item);
addClaimToPlayer(previousBidder, refundClaim);
// Remove from previous bidder's active bids
removeFromPlayerBids(previousBidder, listing.id);
sendNotificationToPlayer(previousBidder, EnumNotificationType.AUCTION_OUTBID, listing.id,
"You were outbid on " + listing.item.getDisplayName() + "!");
}
// Update listing
listing.highBidderUUID = playerUUID;
listing.highBidderName = playerName;
listing.currentBid = bidAmount;
listing.bidCount++;
}
if (listing.isExpired()) {
return "This auction has ended.";
}
// CRITICAL: Prevent bidding on own items
if (listing.isSeller(playerUUID)) {
return "You cannot bid on your own auction.";
}
// Prevent rebidding if already highest bidder
if (listing.isHighBidder(playerUUID)) {
return "You are already the highest bidder. Use buyout if you want to purchase immediately.";
}
// Check minimum bid
long minBid = listing.getMinimumBid(ConfigMarket.MinBidIncrementPercent);
if (bidAmount < minBid) {
return "Bid must be at least " + minBid + " " + ConfigMarket.CurrencyName + ".";
}
// Check currency
PlayerData playerData = PlayerData.get(player);
if (playerData == null) {
return "Could not access player data.";
}
PlayerTradeData currency = playerData.tradeData;
// Store previous bidder info
UUID previousBidder = listing.highBidderUUID;
long previousBid = listing.currentBid;
// Full bid amount charged since we don't allow rebidding
long amountToCharge = bidAmount;
if (!currency.canAfford(amountToCharge)) {
return "You cannot afford this bid.";
}
// Deduct bid from new bidder FIRST
if (!currency.withdraw(amountToCharge)) {
return "Failed to deduct bid amount.";
}
// Refund previous bidder (include item for rebid option)
if (listing.hasBids() && previousBidder != null) {
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
previousBidder, listing.highBidderName, listing.id, previousBid,
listing.item.getDisplayName(), playerName, listing.item);
addClaimToPlayer(previousBidder, refundClaim);
// Remove from previous bidder's active bids
removeFromPlayerBids(previousBidder, listing.id);
sendNotificationToPlayer(previousBidder, EnumNotificationType.AUCTION_OUTBID, listing.id,
"You were outbid on " + listing.item.getDisplayName() + "!");
}
// Update listing
listing.highBidderUUID = playerUUID;
listing.highBidderName = playerName;
listing.currentBid = bidAmount;
listing.bidCount++;
// Add to new bidder's active bids
addToPlayerBids(playerUUID, listing.id);
@@ -453,7 +500,7 @@ public class AuctionController implements IAuctionHandler {
markDirty();
logAuction("BID", playerName, listing.item.getDisplayName(), bidAmount,
logAuction(EnumAuctionLogAction.BID, playerName, listing.item.getDisplayName(), bidAmount,
"Bids: " + listing.bidCount + ", Seller: " + listing.sellerName);
return null; // Success
@@ -472,97 +519,107 @@ public class AuctionController implements IAuctionHandler {
return "Listing not found.";
}
// Check status and expiry
if (!listing.status.canBid()) {
return "This auction has ended.";
}
if (listing.isExpired()) {
return "This auction has ended.";
}
if (!listing.hasBuyout()) {
return "This auction does not have a buyout price.";
}
// CRITICAL: Prevent buying own items
if (listing.isSeller(playerUUID)) {
return "You cannot buy your own auction.";
}
// Check currency
PlayerData playerData = PlayerData.get(player);
if (playerData == null) {
return "Could not access player data.";
}
PlayerTradeData currency = playerData.tradeData;
// If buyer is already the high bidder, only charge the difference
boolean isCurrentBidder = listing.isHighBidder(playerUUID);
long amountToCharge = isCurrentBidder
? (listing.buyoutPrice - listing.currentBid)
: listing.buyoutPrice;
if (!currency.canAfford(amountToCharge)) {
if (isCurrentBidder) {
return "You cannot afford the remaining " + amountToCharge + " " + ConfigMarket.CurrencyName + " for buyout.";
synchronized (listing) {
// Check status and expiry
if (!listing.status.canBid()) {
return "This auction has ended.";
}
return "You cannot afford the buyout price.";
if (listing.isExpired()) {
return "This auction has ended.";
}
if (!listing.hasBuyout()) {
return "This auction does not have a buyout price.";
}
// CRITICAL: Prevent buying own items
if (listing.isSeller(playerUUID)) {
return "You cannot buy your own auction.";
}
// Check currency
PlayerData playerData = PlayerData.get(player);
if (playerData == null) {
return "Could not access player data.";
}
PlayerTradeData currency = playerData.tradeData;
// If buyer is already the high bidder, only charge the difference
boolean isCurrentBidder = listing.isHighBidder(playerUUID);
long amountToCharge = isCurrentBidder
? (listing.buyoutPrice - listing.currentBid)
: listing.buyoutPrice;
if (!currency.canAfford(amountToCharge)) {
if (isCurrentBidder) {
return "You cannot afford the remaining " + amountToCharge + " " + ConfigMarket.CurrencyName + " for buyout.";
}
return "You cannot afford the buyout price.";
}
// Fire auction buyout event (cancelable)
PlayerDataScript buyoutHandler = ScriptController.Instance.getPlayerScripts(player);
IPlayer iBuyer = (IPlayer) NpcAPI.Instance().getIEntity(player);
AuctionEvent.BuyoutEvent buyoutEvent = new AuctionEvent.BuyoutEvent(iBuyer, listing);
if (EventHooks.onAuctionBuyout(buyoutHandler, buyoutEvent)) {
return "Buyout was cancelled.";
}
// Deduct buyout amount
if (!currency.withdraw(amountToCharge)) {
return "Failed to deduct buyout amount.";
}
// Refund previous bidder if any AND they're not the buyer (no item - auction ended via buyout)
if (listing.hasBids() && listing.highBidderUUID != null && !isCurrentBidder) {
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
listing.highBidderUUID, listing.highBidderName, listing.id, listing.currentBid,
listing.item.getDisplayName(), playerName, null);
addClaimToPlayer(listing.highBidderUUID, refundClaim);
// Remove from previous bidder's active bids
removeFromPlayerBids(listing.highBidderUUID, listing.id);
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_OUTBID, listing.id,
"The auction for " + listing.item.getDisplayName() + " was bought out. Your bid has been refunded.");
} else if (isCurrentBidder) {
// Current bidder is buying out - just remove from their active bids
removeFromPlayerBids(playerUUID, listing.id);
}
// Create claims
AuctionClaim itemClaim = AuctionClaim.createItemWonClaim(playerUUID, playerName, listing.id, listing.item);
addClaimToPlayer(playerUUID, itemClaim);
long saleAmount = listing.buyoutPrice;
long tax = (long) (saleAmount * ConfigMarket.SalesTaxPercent);
long sellerReceives = saleAmount - tax;
AuctionClaim currencyClaim = AuctionClaim.createCurrencyClaim(
listing.sellerUUID, listing.sellerName, listing.id, sellerReceives,
listing.item.getDisplayName(), playerName);
addClaimToPlayer(listing.sellerUUID, currencyClaim);
// Notifications
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
"Your " + listing.item.getDisplayName() + " was bought out for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
// Remove from seller's active listings
removeFromPlayerListings(listing.sellerUUID, listing.id);
listing.status = EnumAuctionStatus.ENDED;
listing.highBidderUUID = playerUUID;
listing.highBidderName = playerName;
listing.currentBid = listing.buyoutPrice;
markDirty();
logAuction(EnumAuctionLogAction.BUYOUT, playerName, listing.item.getDisplayName(), listing.buyoutPrice,
"Seller: " + listing.sellerName + ", Tax: " + tax);
}
// Deduct buyout amount
if (!currency.withdraw(amountToCharge)) {
return "Failed to deduct buyout amount.";
}
// Refund previous bidder if any AND they're not the buyer (no item - auction ended via buyout)
if (listing.hasBids() && listing.highBidderUUID != null && !isCurrentBidder) {
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
listing.highBidderUUID, listing.highBidderName, listing.id, listing.currentBid,
listing.item.getDisplayName(), playerName, null);
addClaimToPlayer(listing.highBidderUUID, refundClaim);
// Remove from previous bidder's active bids
removeFromPlayerBids(listing.highBidderUUID, listing.id);
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_OUTBID, listing.id,
"The auction for " + listing.item.getDisplayName() + " was bought out. Your bid has been refunded.");
} else if (isCurrentBidder) {
// Current bidder is buying out - just remove from their active bids
removeFromPlayerBids(playerUUID, listing.id);
}
// Create claims
AuctionClaim itemClaim = AuctionClaim.createItemWonClaim(playerUUID, playerName, listing.id, listing.item);
addClaimToPlayer(playerUUID, itemClaim);
long saleAmount = listing.buyoutPrice;
long tax = (long) (saleAmount * ConfigMarket.SalesTaxPercent);
long sellerReceives = saleAmount - tax;
AuctionClaim currencyClaim = AuctionClaim.createCurrencyClaim(
listing.sellerUUID, listing.sellerName, listing.id, sellerReceives,
listing.item.getDisplayName(), playerName);
addClaimToPlayer(listing.sellerUUID, currencyClaim);
// Notifications
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
"Your " + listing.item.getDisplayName() + " was bought out for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
// Remove from seller's active listings
removeFromPlayerListings(listing.sellerUUID, listing.id);
listing.status = EnumAuctionStatus.ENDED;
listing.highBidderUUID = playerUUID;
listing.highBidderName = playerName;
listing.currentBid = listing.buyoutPrice;
markDirty();
logAuction("BUYOUT", playerName, listing.item.getDisplayName(), listing.buyoutPrice,
"Seller: " + listing.sellerName + ", Tax: " + tax);
return null; // Success
}
@@ -615,6 +672,14 @@ public class AuctionController implements IAuctionHandler {
return "Item data is missing.";
}
// Fire auction claim event (cancelable)
PlayerDataScript itemClaimHandler = ScriptController.Instance.getPlayerScripts(player);
IPlayer iItemClaimer = (IPlayer) NpcAPI.Instance().getIEntity(player);
AuctionEvent.ClaimEvent itemClaimEvent = new AuctionEvent.ClaimEvent(iItemClaimer, claim);
if (EventHooks.onAuctionClaim(itemClaimHandler, itemClaimEvent)) {
return "Claim was prevented.";
}
// Check inventory space
if (!player.inventory.addItemStackToInventory(claim.item.copy())) {
return "Your inventory is full.";
@@ -628,7 +693,7 @@ public class AuctionController implements IAuctionHandler {
// Cleanup listing if no more claims
cleanupListingIfComplete(claim.listingId);
logAuction("CLAIMED", player.getCommandSenderName(), claim.item.getDisplayName(), 0, "Item claimed");
logAuction(EnumAuctionLogAction.CLAIMED, player.getCommandSenderName(), claim.item.getDisplayName(), 0, "Item claimed");
return null; // Success
}
@@ -652,6 +717,14 @@ public class AuctionController implements IAuctionHandler {
return "This is not a currency claim.";
}
// Fire auction claim event (cancelable)
PlayerDataScript currencyClaimHandler = ScriptController.Instance.getPlayerScripts(player);
IPlayer iCurrencyClaimer = (IPlayer) NpcAPI.Instance().getIEntity(player);
AuctionEvent.ClaimEvent currencyClaimEvent = new AuctionEvent.ClaimEvent(iCurrencyClaimer, claim);
if (EventHooks.onAuctionClaim(currencyClaimHandler, currencyClaimEvent)) {
return "Claim was prevented.";
}
if (!playerData.tradeData.deposit(claim.currency)) {
return "Failed to deposit currency.";
}
@@ -664,7 +737,7 @@ public class AuctionController implements IAuctionHandler {
// Cleanup listing if no more claims
cleanupListingIfComplete(claim.listingId);
logAuction("CLAIMED", player.getCommandSenderName(), ConfigMarket.CurrencyName, claim.currency,
logAuction(EnumAuctionLogAction.CLAIMED, player.getCommandSenderName(), ConfigMarket.CurrencyName, claim.currency,
claim.type == EnumClaimType.REFUND ? "Refund claimed" : "Sale proceeds claimed");
return null; // Success
@@ -993,7 +1066,7 @@ public class AuctionController implements IAuctionHandler {
if (expired > 0) {
playerData.updateClient = true;
playerData.save();
logAuction("CLAIM_EXPIRED", player.getCommandSenderName(), "Multiple", expired,
logAuction(EnumAuctionLogAction.CLAIM_EXPIRED, player.getCommandSenderName(), "Multiple", expired,
expired + " claims expired on login");
}
}
@@ -1041,40 +1114,12 @@ public class AuctionController implements IAuctionHandler {
// Logging
// =========================================
private void logAuction(String action, String playerName, String itemName, long amount, String details) {
if (!ConfigMarket.AuctionLoggingEnabled) return;
private void logAuction(EnumAuctionLogAction action, String playerName, String itemName, long amount, String details) {
if (!action.shouldLog()) return;
boolean shouldLog = false;
switch (action) {
case "CREATED":
shouldLog = ConfigMarket.LogAuctionCreated;
break;
case "BID":
shouldLog = ConfigMarket.LogAuctionBid;
break;
case "BUYOUT":
shouldLog = ConfigMarket.LogAuctionBuyout;
break;
case "SOLD":
shouldLog = ConfigMarket.LogAuctionSold;
break;
case "EXPIRED":
shouldLog = ConfigMarket.LogAuctionExpired;
break;
case "CANCELLED":
shouldLog = ConfigMarket.LogAuctionCancelled;
break;
case "CLAIMED":
case "CLAIM_EXPIRED":
shouldLog = ConfigMarket.LogAuctionClaimed;
break;
}
if (shouldLog) {
String logMessage = String.format("[AUCTION:%s] Player: %s, Item: %s, Amount: %d, Details: %s",
action, playerName, itemName, amount, details);
LogWriter.info(logMessage);
}
String logMessage = String.format("[AUCTION:%s] Player: %s, Item: %s, Amount: %d, Details: %s",
action.name(), playerName, itemName, amount, details);
LogWriter.info(logMessage);
}
// =========================================
@@ -1141,7 +1186,9 @@ public class AuctionController implements IAuctionHandler {
File fileOld = new File(saveDir, "auction.dat_old");
File fileCurrent = new File(saveDir, "auction.dat");
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew));
try (FileOutputStream fos = new FileOutputStream(fileNew)) {
CompressedStreamTools.writeCompressed(compound, fos);
}
// Backup rotation
if (fileOld.exists()) fileOld.delete();
@@ -1210,7 +1257,10 @@ public class AuctionController implements IAuctionHandler {
}
private void loadFromFile(File file) throws Exception {
NBTTagCompound compound = CompressedStreamTools.readCompressed(new FileInputStream(file));
NBTTagCompound compound;
try (FileInputStream fis = new FileInputStream(file)) {
compound = CompressedStreamTools.readCompressed(fis);
}
readFromNBT(compound);
}
@@ -1398,7 +1448,12 @@ public class AuctionController implements IAuctionHandler {
}
public void adminCancelListing(String listingId, EntityPlayer admin, String reason) {
AuctionListing listing = listings.get(listingId);
String itemName = listing != null && listing.item != null ? listing.item.getDisplayName() : "Unknown";
cancelListing(listingId, admin, true);
if (reason != null && !reason.isEmpty()) {
logAuction(EnumAuctionLogAction.CANCELLED, admin.getCommandSenderName(), itemName, 0, "Admin cancel - Reason: " + reason);
}
}
public void clearEndedListings() {
@@ -2,6 +2,8 @@ package noppes.npcs.controllers;
import noppes.npcs.api.event.IAbilityEvent;
import noppes.npcs.api.event.IAnimationEvent;
import noppes.npcs.api.event.IAuctionEvent;
import noppes.npcs.api.event.IEnergyBarrierEvent;
import noppes.npcs.api.event.IPlayerAbilityEvent;
import noppes.npcs.api.event.IBlockEvent;
import noppes.npcs.api.event.ICustomGuiEvent;
@@ -123,6 +125,12 @@ public class ScriptHookController implements IScriptHookHandler {
hook(NPC, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
hook(NPC, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
// Energy Barrier
hook(NPC, ENERGY_BARRIER_SPAWNED, IEnergyBarrierEvent.SpawnedEvent.class);
hook(NPC, ENERGY_BARRIER_TICK, IEnergyBarrierEvent.UpdateEvent.class);
hook(NPC, ENERGY_BARRIER_HIT, IEnergyBarrierEvent.HitEvent.class);
hook(NPC, ENERGY_BARRIER_DESTROYED, IEnergyBarrierEvent.DestroyedEvent.class);
// Animation
hook(NPC, ANIMATION_START, IAnimationEvent.Started.class);
hook(NPC, ANIMATION_END, IAnimationEvent.Ended.class);
@@ -230,6 +238,12 @@ public class ScriptHookController implements IScriptHookHandler {
hook(PLAYER, ENERGY_PROJECTILE_BLOCK_IMPACT, IEnergyProjectileEvent.BlockImpactEvent.class);
hook(PLAYER, ENERGY_PROJECTILE_EXPIRED, IEnergyProjectileEvent.ExpiredEvent.class);
// Energy Barrier
hook(PLAYER, ENERGY_BARRIER_SPAWNED, IEnergyBarrierEvent.SpawnedEvent.class);
hook(PLAYER, ENERGY_BARRIER_TICK, IEnergyBarrierEvent.UpdateEvent.class);
hook(PLAYER, ENERGY_BARRIER_HIT, IEnergyBarrierEvent.HitEvent.class);
hook(PLAYER, ENERGY_BARRIER_DESTROYED, IEnergyBarrierEvent.DestroyedEvent.class);
// Ability
hook(PLAYER, ABILITY_START, IPlayerAbilityEvent.StartEvent.class);
hook(PLAYER, ABILITY_EXECUTE, IPlayerAbilityEvent.ExecuteEvent.class);
@@ -238,6 +252,13 @@ public class ScriptHookController implements IScriptHookHandler {
hook(PLAYER, ABILITY_INTERRUPT, IPlayerAbilityEvent.InterruptEvent.class);
hook(PLAYER, ABILITY_COMPLETE, IPlayerAbilityEvent.CompleteEvent.class);
// Auction
hook(PLAYER, AUCTION_CREATE, IAuctionEvent.CreateEvent.class);
hook(PLAYER, AUCTION_BID, IAuctionEvent.BidEvent.class);
hook(PLAYER, AUCTION_BUYOUT, IAuctionEvent.BuyoutEvent.class);
hook(PLAYER, AUCTION_CANCEL, IAuctionEvent.CancelEvent.class);
hook(PLAYER, AUCTION_CLAIM, IAuctionEvent.ClaimEvent.class);
// Profile
hook(PLAYER, PROFILE_CHANGE, IPlayerEvent.ProfileEvent.Changed.class);
hook(PLAYER, PROFILE_REMOVE, IPlayerEvent.ProfileEvent.Removed.class);
@@ -13,12 +13,13 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.Iterator;
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<>();
private static volatile Set<String> blacklistedItems = new HashSet<>();
private static volatile Set<Pattern> wildcardPatterns = new HashSet<>();
private static volatile Set<String> blacklistedMods = new HashSet<>();
private static volatile Set<String> blacklistedNBTTags = new HashSet<>();
// Built-in bound item requirement keys (always blocked)
private static final String SOULBIND_KEY = "cnpc_soulbind";
@@ -28,10 +29,10 @@ public class AuctionBlacklist {
private static final String BYPASS_PERMISSION = "customnpcs.auction.blacklist.bypass";
public static void reload() {
blacklistedItems.clear();
wildcardPatterns.clear();
blacklistedMods.clear();
blacklistedNBTTags.clear();
Set<String> newItems = new HashSet<>();
Set<Pattern> newWildcards = new HashSet<>();
Set<String> newMods = new HashSet<>();
Set<String> newNBTTags = new HashSet<>();
// Load blacklisted items
for (String item : ConfigMarket.BlacklistedItems) {
@@ -40,23 +41,29 @@ public class AuctionBlacklist {
if (item.contains("*")) {
String regex = "^" + item.replace(".", "\\.").replace("*", ".*") + "$";
wildcardPatterns.add(Pattern.compile(regex));
newWildcards.add(Pattern.compile(regex));
} else {
blacklistedItems.add(item);
newItems.add(item);
}
}
// Load blacklisted mods
for (String mod : ConfigMarket.BlacklistedMods) {
if (mod == null || mod.isEmpty()) continue;
blacklistedMods.add(mod.toLowerCase().trim());
newMods.add(mod.toLowerCase().trim());
}
// Load blacklisted NBT tags
for (String tag : ConfigMarket.BlacklistedNBTTags) {
if (tag == null || tag.isEmpty()) continue;
blacklistedNBTTags.add(tag.trim());
newNBTTags.add(tag.trim());
}
// Atomic swap
blacklistedItems = newItems;
wildcardPatterns = newWildcards;
blacklistedMods = newMods;
blacklistedNBTTags = newNBTTags;
}
/**
@@ -78,7 +85,6 @@ public class AuctionBlacklist {
* 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")
@@ -86,6 +92,8 @@ public class AuctionBlacklist {
return true;
}
if (!ConfigMarket.BlacklistEnabled) return false;
// Get registry name
GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(item.getItem());
if (uid == null) return true;
@@ -172,9 +180,13 @@ public class AuctionBlacklist {
if (registryName.contains("*")) {
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
wildcardPatterns.add(Pattern.compile(regex));
Set<Pattern> newWildcards = new HashSet<>(wildcardPatterns);
newWildcards.add(Pattern.compile(regex));
wildcardPatterns = newWildcards;
} else {
blacklistedItems.add(registryName);
Set<String> newItems = new HashSet<>(blacklistedItems);
newItems.add(registryName);
blacklistedItems = newItems;
}
return true;
}
@@ -185,30 +197,55 @@ public class AuctionBlacklist {
if (registryName.contains("*")) {
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
return wildcardPatterns.removeIf(p -> p.pattern().equals(regex));
Set<Pattern> newWildcards = new HashSet<>(wildcardPatterns);
boolean removed = false;
Iterator<Pattern> it = newWildcards.iterator();
while (it.hasNext()) {
if (it.next().pattern().equals(regex)) {
it.remove();
removed = true;
}
}
wildcardPatterns = newWildcards;
return removed;
} else {
return blacklistedItems.remove(registryName);
Set<String> newItems = new HashSet<>(blacklistedItems);
boolean removed = newItems.remove(registryName);
blacklistedItems = newItems;
return removed;
}
}
public static boolean addMod(String modId) {
if (modId == null || modId.isEmpty()) return false;
return blacklistedMods.add(modId.toLowerCase().trim());
Set<String> newMods = new HashSet<>(blacklistedMods);
boolean added = newMods.add(modId.toLowerCase().trim());
blacklistedMods = newMods;
return added;
}
public static boolean removeMod(String modId) {
if (modId == null || modId.isEmpty()) return false;
return blacklistedMods.remove(modId.toLowerCase().trim());
Set<String> newMods = new HashSet<>(blacklistedMods);
boolean removed = newMods.remove(modId.toLowerCase().trim());
blacklistedMods = newMods;
return removed;
}
public static boolean addNBTTag(String tag) {
if (tag == null || tag.isEmpty()) return false;
return blacklistedNBTTags.add(tag.trim());
Set<String> newTags = new HashSet<>(blacklistedNBTTags);
boolean added = newTags.add(tag.trim());
blacklistedNBTTags = newTags;
return added;
}
public static boolean removeNBTTag(String tag) {
if (tag == null || tag.isEmpty()) return false;
return blacklistedNBTTags.remove(tag.trim());
Set<String> newTags = new HashSet<>(blacklistedNBTTags);
boolean removed = newTags.remove(tag.trim());
blacklistedNBTTags = newTags;
return removed;
}
// =========================================
@@ -140,7 +140,7 @@ public class AuctionClaim implements IAuctionClaim {
@Override
public boolean isCurrencyClaim() {
return type == EnumClaimType.CURRENCY;
return type.isCurrency();
}
@Override
@@ -4,16 +4,12 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import noppes.npcs.constants.EnumAuctionSort;
import java.util.regex.Pattern;
/**
* Filter for auction listings.
* 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);
public String searchText;
private String searchText;
public EnumAuctionSort sortBy;
// Cached normalized search for efficiency
@@ -32,9 +28,8 @@ public class AuctionFilter {
/** Normalize string for search (strip colors, lowercase, trim) */
public static String normalizeForSearch(String input) {
if (input == null || input.isEmpty()) return "";
String stripped = COLOR_CODE_PATTERN.matcher(input).replaceAll("");
stripped = EnumChatFormatting.getTextWithoutFormattingCodes(stripped);
return stripped.toLowerCase().trim();
String stripped = EnumChatFormatting.getTextWithoutFormattingCodes(input);
return stripped != null ? stripped.toLowerCase().trim() : input.toLowerCase().trim();
}
/** Check if item name or seller name matches search text */
@@ -1,64 +0,0 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.constants.EnumNotificationType;
import java.util.UUID;
public class AuctionNotification {
public String id;
public UUID playerUUID;
public EnumNotificationType type;
public String listingId;
public String message;
public long timestamp;
public boolean sent;
public AuctionNotification() {
this.id = UUID.randomUUID().toString();
this.timestamp = System.currentTimeMillis();
this.sent = false;
}
public AuctionNotification(UUID playerUUID, EnumNotificationType type, String listingId, String message) {
this();
this.playerUUID = playerUUID;
this.type = type;
this.listingId = listingId;
this.message = message;
}
public boolean isForPlayer(UUID uuid) {
return playerUUID != null && playerUUID.equals(uuid);
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setString("ID", id);
compound.setString("PlayerUUID", playerUUID != null ? playerUUID.toString() : "");
compound.setInteger("Type", type.ordinal());
compound.setString("ListingID", listingId != null ? listingId : "");
compound.setString("Message", message != null ? message : "");
compound.setLong("Timestamp", timestamp);
compound.setBoolean("Sent", sent);
return compound;
}
public void readFromNBT(NBTTagCompound compound) {
id = compound.getString("ID");
String playerUUIDStr = compound.getString("PlayerUUID");
playerUUID = playerUUIDStr.isEmpty() ? null : UUID.fromString(playerUUIDStr);
type = EnumNotificationType.fromOrdinal(compound.getInteger("Type"));
listingId = compound.getString("ListingID");
message = compound.getString("Message");
timestamp = compound.getLong("Timestamp");
sent = compound.getBoolean("Sent");
}
public static AuctionNotification fromNBT(NBTTagCompound compound) {
AuctionNotification notification = new AuctionNotification();
notification.readFromNBT(compound);
return notification;
}
}
@@ -8,7 +8,6 @@ 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;
@@ -129,12 +128,13 @@ public class PlayerTradeData implements IPlayerTradeData {
// Built-in currency
long newBalance = this.balance + amount;
if (newBalance > ConfigMarket.MaxBalance) {
return false;
}
// Overflow protection
if (newBalance < this.balance) {
// Overflow protection
return false;
newBalance = ConfigMarket.MaxBalance;
}
// Cap at MaxBalance instead of rejecting
if (newBalance > ConfigMarket.MaxBalance) {
newBalance = ConfigMarket.MaxBalance;
}
this.balance = newBalance;
this.lifetimeEarned += amount;
@@ -341,18 +341,16 @@ public class PlayerTradeData implements IPlayerTradeData {
*/
public int processExpiredClaims() {
int expirationDays = ConfigMarket.ClaimExpirationDays;
int removed = 0;
Iterator<AuctionClaim> iterator = claims.iterator();
while (iterator.hasNext()) {
AuctionClaim claim = iterator.next();
List<AuctionClaim> expired = new ArrayList<>();
for (AuctionClaim claim : claims) {
if (!claim.claimed && claim.isExpired(expirationDays)) {
claims.remove(claim);
removed++;
expired.add(claim);
}
}
return removed;
if (!expired.isEmpty()) {
claims.removeAll(expired);
}
return expired.size();
}
// =========================================