Refactor auction system: consolidate controllers, add lang keys, remove categories

- Consolidate AuctionLogger and AuctionNotificationController into AuctionController
- Add inline logging and notification methods to AuctionController
- Add comprehensive LANG keys for all auction GUI strings
- Update EnumAuctionSort and EnumAuctionDuration to use lang keys
- Remove category filtering system (EnumAuctionCategory deleted)
- Update AuctionFilter to remove category references
- Update GuiAuction and all sub-GUIs to use StatCollector.translateToLocal()
- Update AuctionListing to remove category field and NBT serialization
This commit is contained in:
Claude committed 2026-01-04 10:26:56 +00:00
1 parent a1de79053b
commit 740c2852e5
15 files changed
+374 -1165

No files matched your search

@@ -62,7 +62,6 @@ import noppes.npcs.controllers.VaultHelper;
import noppes.npcs.controllers.CurrencyController;
import noppes.npcs.controllers.AuctionBlacklist;
import noppes.npcs.controllers.AuctionController;
import noppes.npcs.controllers.AuctionNotificationController;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.QuestController;
import noppes.npcs.controllers.RecipeController;
@@ -313,7 +312,6 @@ public class CustomNpcs {
new CurrencyController();
new AuctionBlacklist();
new AuctionController();
new AuctionNotificationController();
RecipeController.Instance.load();
new BankController();
DialogController.Instance.load();
@@ -10,7 +10,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
import noppes.npcs.client.AnalyticsTracking;
import noppes.npcs.controllers.AuctionNotificationController;
import noppes.npcs.controllers.AuctionController;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.controllers.data.action.ActionManager;
@@ -68,8 +68,8 @@ public class ServerTickHandler {
SyncController.syncEffects(player);
// Send pending auction notifications
if (AuctionNotificationController.Instance != null) {
AuctionNotificationController.Instance.onPlayerLogin(player);
if (AuctionController.Instance != null) {
AuctionController.Instance.onPlayerLogin(player);
}
}
@@ -3,17 +3,13 @@ package noppes.npcs.client.gui.player;
import kamkeel.npcs.network.packets.player.AuctionActionPacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.CustomNpcResourceListener;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.config.ConfigMarket;
import noppes.npcs.constants.EnumAuctionCategory;
import noppes.npcs.constants.EnumAuctionSort;
import noppes.npcs.constants.EnumAuctionStatus;
import noppes.npcs.containers.ContainerAuction;
import noppes.npcs.controllers.data.AuctionFilter;
import noppes.npcs.controllers.data.AuctionListing;
@@ -26,13 +22,11 @@ import java.util.List;
/**
* Main auction house browse GUI.
* Displays listings with search, filter, sort, and pagination.
* Displays listings with search, sort, and pagination.
*/
public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
ICustomScrollListener, NoppesUtil.IAuctionData {
private static final ResourceLocation background = new ResourceLocation("customnpcs", "textures/gui/auction.png");
// GUI Components
private GuiNpcTextField searchField;
private GuiCustomScroll listingScroll;
@@ -56,7 +50,7 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
public GuiAuction(EntityNPCInterface npc, ContainerAuction container) {
super(npc, container);
this.title = "Auction House";
this.title = "";
this.xSize = 256;
this.ySize = 222;
this.closeOnEsc = true;
@@ -71,70 +65,50 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
super.initGui();
// Tab buttons at top
addTopButton(new GuiMenuTopButton(0, guiLeft + 4, guiTop - 17, "Browse"));
addTopButton(new GuiMenuTopButton(1, guiLeft + 54, guiTop - 17, "My Listings"));
addTopButton(new GuiMenuTopButton(2, guiLeft + 114, guiTop - 17, "My Bids"));
addTopButton(new GuiMenuTopButton(3, guiLeft + 164, guiTop - 17, "Claims"));
addTopButton(new GuiMenuTopButton(4, guiLeft + 214, guiTop - 17, "Sell"));
addTopButton(new GuiMenuTopButton(0, guiLeft + 4, guiTop - 17, StatCollector.translateToLocal("auction.browse")));
addTopButton(new GuiMenuTopButton(1, guiLeft + 54, guiTop - 17, StatCollector.translateToLocal("auction.myListings")));
addTopButton(new GuiMenuTopButton(2, guiLeft + 114, guiTop - 17, StatCollector.translateToLocal("auction.myBids")));
addTopButton(new GuiMenuTopButton(3, guiLeft + 164, guiTop - 17, StatCollector.translateToLocal("auction.claims")));
addTopButton(new GuiMenuTopButton(4, guiLeft + 214, guiTop - 17, StatCollector.translateToLocal("auction.sell")));
getTopButton(currentTab).setEnabled(false);
// Search field
searchField = new GuiNpcTextField(10, this, guiLeft + 8, guiTop + 6, 120, 14, currentFilter.searchText);
searchField = new GuiNpcTextField(10, this, guiLeft + 8, guiTop + 6, 140, 14, currentFilter.searchText);
searchField.setMaxStringLength(50);
addTextField(searchField);
// Search button
addButton(new GuiNpcButton(11, guiLeft + 130, guiTop + 5, 30, 16, "Search"));
addButton(new GuiNpcButton(11, guiLeft + 150, guiTop + 5, 40, 16, StatCollector.translateToLocal("auction.search")));
// Category buttons (simplified row)
String[] categories = {"All", "Weapons", "Armor", "Tools", "Potions", "Blocks", "Other"};
for (int i = 0; i < categories.length; i++) {
GuiNpcButton btn = new GuiNpcButton(20 + i, guiLeft + 8 + i * 35, guiTop + 24, 33, 14, categories[i]);
btn.setEnabled(currentFilter.category.ordinal() != getCategoryOrdinal(i));
addButton(btn);
}
// Sort dropdown button
addButton(new GuiNpcButton(30, guiLeft + 170, guiTop + 5, 78, 16, currentFilter.sortOrder.getDisplayName()));
// Sort button
addButton(new GuiNpcButton(30, guiLeft + 8, guiTop + 24, 120, 16, currentFilter.sortOrder.getDisplayName()));
// Listing scroll area
listingScroll = new GuiCustomScroll(this, 0);
listingScroll.guiLeft = guiLeft + 8;
listingScroll.guiTop = guiTop + 42;
listingScroll.setSize(160, 130);
listingScroll.guiTop = guiTop + 44;
listingScroll.setSize(160, 128);
addScroll(listingScroll);
updateListingDisplay();
// Pagination buttons
addButton(new GuiNpcButton(40, guiLeft + 8, guiTop + 176, 40, 16, "< Prev"));
addButton(new GuiNpcButton(40, guiLeft + 8, guiTop + 176, 40, 16, StatCollector.translateToLocal("auction.prevPage")));
addLabel(new GuiNpcLabel(41, getPageLabel(), guiLeft + 90, guiTop + 180, CustomNpcResourceListener.DefaultTextColor));
addButton(new GuiNpcButton(42, guiLeft + 128, guiTop + 176, 40, 16, "Next >"));
addButton(new GuiNpcButton(42, guiLeft + 128, guiTop + 176, 40, 16, StatCollector.translateToLocal("auction.nextPage")));
// Action buttons (right side)
addButton(new GuiNpcButton(50, guiLeft + 175, guiTop + 50, 73, 20, "View Details"));
addButton(new GuiNpcButton(51, guiLeft + 175, guiTop + 75, 73, 20, "Place Bid"));
addButton(new GuiNpcButton(52, guiLeft + 175, guiTop + 100, 73, 20, "Buyout"));
addButton(new GuiNpcButton(53, guiLeft + 175, guiTop + 125, 73, 20, "Refresh"));
addButton(new GuiNpcButton(50, guiLeft + 175, guiTop + 50, 73, 20, StatCollector.translateToLocal("auction.viewDetails")));
addButton(new GuiNpcButton(51, guiLeft + 175, guiTop + 75, 73, 20, StatCollector.translateToLocal("auction.placeBid")));
addButton(new GuiNpcButton(52, guiLeft + 175, guiTop + 100, 73, 20, StatCollector.translateToLocal("auction.buyout")));
addButton(new GuiNpcButton(53, guiLeft + 175, guiTop + 125, 73, 20, StatCollector.translateToLocal("auction.refresh")));
// Balance display
addLabel(new GuiNpcLabel(60, "Balance: " + formatCurrency(playerBalance),
addLabel(new GuiNpcLabel(60, String.format(StatCollector.translateToLocal("auction.balance"), formatCurrency(playerBalance)),
guiLeft + 175, guiTop + 155, 0x00AA00));
updateButtonStates();
}
private int getCategoryOrdinal(int buttonIndex) {
switch (buttonIndex) {
case 0: return EnumAuctionCategory.ALL.ordinal();
case 1: return EnumAuctionCategory.WEAPONS.ordinal();
case 2: return EnumAuctionCategory.ARMOR.ordinal();
case 3: return EnumAuctionCategory.TOOLS.ordinal();
case 4: return EnumAuctionCategory.POTIONS.ordinal();
case 5: return EnumAuctionCategory.BLOCKS.ordinal();
default: return EnumAuctionCategory.MISC.ordinal();
}
}
@Override
public void updateScreen() {
super.updateScreen();
@@ -160,10 +134,6 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
else if (id == 11) {
performSearch();
}
// Category buttons
else if (id >= 20 && id <= 26) {
setCategory(getCategoryOrdinal(id - 20));
}
// Sort button
else if (id == 30) {
cycleSortOrder();
@@ -218,14 +188,6 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
AuctionActionPacket.QueryListings(currentFilter);
}
private void setCategory(int categoryOrdinal) {
currentFilter.category = EnumAuctionCategory.values()[categoryOrdinal];
currentFilter.page = 0;
currentPage = 0;
AuctionActionPacket.QueryListings(currentFilter);
initGui();
}
private void cycleSortOrder() {
currentFilter.sortOrder = currentFilter.sortOrder.next();
currentFilter.page = 0;
@@ -321,7 +283,7 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
}
private String formatTimeRemaining(long millis) {
if (millis <= 0) return "Ended";
if (millis <= 0) return StatCollector.translateToLocal("auction.ended");
long seconds = millis / 1000;
long minutes = seconds / 60;
@@ -350,9 +312,9 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
private String getPageLabel() {
if (totalPages == 0) {
return "No results";
return StatCollector.translateToLocal("auction.noResults");
}
return "Page " + (currentPage + 1) + " of " + totalPages;
return String.format(StatCollector.translateToLocal("auction.page"), currentPage + 1, totalPages);
}
private void updateButtonStates() {
@@ -378,7 +340,7 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
drawDefaultBackground();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
// Draw background (using a standard size, can be customized)
// Draw background
mc.renderEngine.bindTexture(new ResourceLocation("customnpcs", "textures/gui/bgfilled.png"));
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
@@ -413,17 +375,18 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
CustomNpcResourceListener.DefaultTextColor);
// Results count
fontRendererObj.drawString(totalResults + " listings", 175, 42, 0x666666);
String listingsLabel = String.format(StatCollector.translateToLocal("auction.listings"), totalResults);
fontRendererObj.drawString(listingsLabel, 175, 42, 0x666666);
}
private String getTabTitle() {
switch (currentTab) {
case 0: return "Browse Auctions";
case 1: return "My Listings";
case 2: return "My Active Bids";
case 3: return "Claim Items";
case 4: return "Create Listing";
default: return "Auction House";
case 0: return StatCollector.translateToLocal("auction.browseTitle");
case 1: return StatCollector.translateToLocal("auction.myListingsTitle");
case 2: return StatCollector.translateToLocal("auction.myBidsTitle");
case 3: return StatCollector.translateToLocal("auction.claimsTitle");
case 4: return StatCollector.translateToLocal("auction.sellTitle");
default: return StatCollector.translateToLocal("auction.title");
}
}
@@ -443,13 +406,13 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
// Handled above
}
// IGuiData - Receive NBT data from server
// IGuiData
@Override
public void setGuiData(NBTTagCompound compound) {
// This can be used for initial setup data
}
// IAuctionData - Receive auction listing data
// IAuctionData
@Override
public void onAuctionDataReceived(int dataType, NBTTagCompound data,
int totalResults, int currentPage, int totalPages,
@@ -478,7 +441,7 @@ public class GuiAuction extends GuiContainerNPCInterface implements IGuiData,
getLabel(41).label = getPageLabel();
}
if (getLabel(60) != null) {
getLabel(60).label = "Balance: " + formatCurrency(playerBalance);
getLabel(60).label = String.format(StatCollector.translateToLocal("auction.balance"), formatCurrency(playerBalance));
}
}
@@ -2,6 +2,7 @@ package noppes.npcs.client.gui.player;
import kamkeel.npcs.network.packets.player.AuctionActionPacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.GuiNpcTextField;
@@ -35,39 +36,39 @@ public class SubGuiAuctionBid extends SubGuiInterface {
int labelColor = 0x404040;
// Title
addLabel(new GuiNpcLabel(0, "Place Bid", guiLeft + 70, y, labelColor));
addLabel(new GuiNpcLabel(0, StatCollector.translateToLocal("auction.placeBid"), guiLeft + 70, y, labelColor));
y += 18;
// Item name
addLabel(new GuiNpcLabel(1, "Item: " + listing.item.getDisplayName(), guiLeft + 15, y, 0x000000));
addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("auction.item") + " " + listing.item.getDisplayName(), guiLeft + 15, y, 0x000000));
y += 14;
// Current price
long currentPrice = listing.currentBid > 0 ? listing.currentBid : listing.startingPrice;
addLabel(new GuiNpcLabel(2, "Current Price:", guiLeft + 15, y, labelColor));
addLabel(new GuiNpcLabel(2, StatCollector.translateToLocal("auction.currentPrice"), guiLeft + 15, y, labelColor));
addLabel(new GuiNpcLabel(3, formatCurrency(currentPrice), guiLeft + 100, y, 0x008800));
y += 14;
// Minimum bid
long minBid = listing.getMinimumBid();
addLabel(new GuiNpcLabel(4, "Minimum Bid:", guiLeft + 15, y, labelColor));
addLabel(new GuiNpcLabel(4, StatCollector.translateToLocal("auction.minimumBid"), guiLeft + 15, y, labelColor));
addLabel(new GuiNpcLabel(5, formatCurrency(minBid), guiLeft + 100, y, 0x0066AA));
y += 14;
// Your balance
addLabel(new GuiNpcLabel(6, "Your Balance:", guiLeft + 15, y, labelColor));
addLabel(new GuiNpcLabel(6, StatCollector.translateToLocal("auction.yourBalance"), guiLeft + 15, y, labelColor));
addLabel(new GuiNpcLabel(7, formatCurrency(playerBalance), guiLeft + 100, y,
playerBalance >= minBid ? 0x008800 : 0xAA0000));
y += 14;
// Time remaining
addLabel(new GuiNpcLabel(8, "Time Left:", guiLeft + 15, y, labelColor));
addLabel(new GuiNpcLabel(8, StatCollector.translateToLocal("auction.timeLeft"), guiLeft + 15, y, labelColor));
addLabel(new GuiNpcLabel(9, formatTimeRemaining(listing.getTimeRemaining()), guiLeft + 100, y,
getTimeColor(listing.getTimeRemaining())));
y += 18;
// Bid input
addLabel(new GuiNpcLabel(10, "Your Bid:", guiLeft + 15, y + 3, labelColor));
addLabel(new GuiNpcLabel(10, StatCollector.translateToLocal("auction.yourBid"), guiLeft + 15, y + 3, labelColor));
bidField = new GuiNpcTextField(11, this, guiLeft + 80, y, 100, 16, String.valueOf(minBid));
bidField.setNumbersOnly();
bidField.setMinMaxDefault(minBid, 999999999, minBid);
@@ -75,24 +76,24 @@ public class SubGuiAuctionBid extends SubGuiInterface {
y += 24;
// Quick bid buttons
addButton(new GuiNpcButton(20, guiLeft + 15, y, 55, 16, "Min Bid"));
addButton(new GuiNpcButton(21, guiLeft + 73, y, 55, 16, "+10%"));
addButton(new GuiNpcButton(22, guiLeft + 131, y, 55, 16, "+25%"));
addButton(new GuiNpcButton(20, guiLeft + 15, y, 55, 16, StatCollector.translateToLocal("auction.minBid")));
addButton(new GuiNpcButton(21, guiLeft + 73, y, 55, 16, StatCollector.translateToLocal("auction.bidPlus10")));
addButton(new GuiNpcButton(22, guiLeft + 131, y, 55, 16, StatCollector.translateToLocal("auction.bidPlus25")));
y += 22;
// Place bid button
GuiNpcButton bidButton = new GuiNpcButton(30, guiLeft + 15, y, 80, 20, "Place Bid");
GuiNpcButton bidButton = new GuiNpcButton(30, guiLeft + 15, y, 80, 20, StatCollector.translateToLocal("auction.placeBid"));
bidButton.setEnabled(playerBalance >= minBid && listing.isActive());
addButton(bidButton);
// Cancel button
addButton(new GuiNpcButton(31, guiLeft + 105, y, 80, 20, "Cancel"));
addButton(new GuiNpcButton(31, guiLeft + 105, y, 80, 20, StatCollector.translateToLocal("gui.cancel")));
// Error message area
if (playerBalance < minBid) {
addLabel(new GuiNpcLabel(40, "Insufficient funds!", guiLeft + 50, guiTop + ySize - 15, 0xAA0000));
addLabel(new GuiNpcLabel(40, StatCollector.translateToLocal("auction.insufficientFunds"), guiLeft + 50, guiTop + ySize - 15, 0xAA0000));
} else if (!listing.isActive()) {
addLabel(new GuiNpcLabel(40, "Auction has ended!", guiLeft + 50, guiTop + ySize - 15, 0xAA0000));
addLabel(new GuiNpcLabel(40, StatCollector.translateToLocal("auction.auctionEnded"), guiLeft + 50, guiTop + ySize - 15, 0xAA0000));
}
}
@@ -101,7 +102,7 @@ public class SubGuiAuctionBid extends SubGuiInterface {
}
private String formatTimeRemaining(long millis) {
if (millis <= 0) return "Ended";
if (millis <= 0) return StatCollector.translateToLocal("auction.ended");
long seconds = millis / 1000;
long minutes = seconds / 60;
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.player;
import kamkeel.npcs.network.packets.player.AuctionActionPacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.GuiNpcTextField;
@@ -21,8 +22,6 @@ public class SubGuiAuctionCreate extends SubGuiInterface {
private GuiNpcTextField buyoutPriceField;
private int selectedDuration = 1; // Default to MEDIUM
private static final String[] DURATION_NAMES = {"Short", "Medium", "Long", "Very Long"};
public SubGuiAuctionCreate(GuiAuction parent, ContainerAuction container) {
this.container = container;
setBackground("menubg.png");
@@ -36,54 +35,54 @@ public class SubGuiAuctionCreate extends SubGuiInterface {
super.initGui();
// Title
addLabel(new GuiNpcLabel(0, "Create Auction Listing", guiLeft + 50, guiTop + 8, 0x404040));
addLabel(new GuiNpcLabel(0, StatCollector.translateToLocal("auction.createListing"), guiLeft + 50, guiTop + 8, 0x404040));
// Item slot instructions
addLabel(new GuiNpcLabel(1, "Place item in slot below:", guiLeft + 20, guiTop + 28, 0x404040));
addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("auction.placeItemBelow"), guiLeft + 20, guiTop + 28, 0x404040));
// Item info (shows when item is in slot)
ItemStack item = container.getListingItem();
if (item != null) {
addLabel(new GuiNpcLabel(2, "Item: " + item.getDisplayName(), guiLeft + 20, guiTop + 50, 0x008800));
addLabel(new GuiNpcLabel(2, StatCollector.translateToLocal("auction.item") + " " + item.getDisplayName(), guiLeft + 20, guiTop + 50, 0x008800));
} else {
addLabel(new GuiNpcLabel(2, "(No item selected)", guiLeft + 20, guiTop + 50, 0x888888));
addLabel(new GuiNpcLabel(2, StatCollector.translateToLocal("auction.noItemSelected"), guiLeft + 20, guiTop + 50, 0x888888));
}
// Starting price
addLabel(new GuiNpcLabel(10, "Starting Price:", guiLeft + 20, guiTop + 70, 0x404040));
addLabel(new GuiNpcLabel(10, StatCollector.translateToLocal("auction.startingPrice"), guiLeft + 20, guiTop + 70, 0x404040));
startingPriceField = new GuiNpcTextField(11, this, guiLeft + 100, guiTop + 68, 80, 14, "100");
startingPriceField.setNumbersOnly();
startingPriceField.setMinMaxDefault(1, 999999999, 100);
addTextField(startingPriceField);
// Buyout price (optional)
addLabel(new GuiNpcLabel(20, "Buyout Price:", guiLeft + 20, guiTop + 90, 0x404040));
addLabel(new GuiNpcLabel(20, StatCollector.translateToLocal("auction.buyoutPrice"), guiLeft + 20, guiTop + 90, 0x404040));
buyoutPriceField = new GuiNpcTextField(21, this, guiLeft + 100, guiTop + 88, 80, 14, "0");
buyoutPriceField.setNumbersOnly();
buyoutPriceField.setMinMaxDefault(0, 999999999, 0);
addTextField(buyoutPriceField);
addLabel(new GuiNpcLabel(22, "(0 = no buyout)", guiLeft + 185, guiTop + 90, 0x888888));
addLabel(new GuiNpcLabel(22, StatCollector.translateToLocal("auction.noBuyoutHint"), guiLeft + 185, guiTop + 90, 0x888888));
// Duration selection
addLabel(new GuiNpcLabel(30, "Duration:", guiLeft + 20, guiTop + 112, 0x404040));
addLabel(new GuiNpcLabel(30, StatCollector.translateToLocal("auction.duration"), guiLeft + 20, guiTop + 112, 0x404040));
addButton(new GuiNpcButton(31, guiLeft + 100, guiTop + 108, 100, 20, getDurationDisplay()));
// Fee display
long fee = getListingFee();
addLabel(new GuiNpcLabel(40, "Listing Fee: " + fee + " " + ConfigMarket.CurrencyName,
addLabel(new GuiNpcLabel(40, StatCollector.translateToLocal("auction.listingFee") + " " + fee + " " + ConfigMarket.CurrencyName,
guiLeft + 20, guiTop + 135, fee > 0 ? 0xAA0000 : 0x008800));
// Create button
addButton(new GuiNpcButton(50, guiLeft + 20, guiTop + 155, 80, 20, "Create Listing"));
addButton(new GuiNpcButton(50, guiLeft + 20, guiTop + 155, 80, 20, StatCollector.translateToLocal("auction.create")));
getButton(50).setEnabled(item != null);
// Cancel button
addButton(new GuiNpcButton(51, guiLeft + 120, guiTop + 155, 80, 20, "Cancel"));
addButton(new GuiNpcButton(51, guiLeft + 120, guiTop + 155, 80, 20, StatCollector.translateToLocal("gui.cancel")));
}
private String getDurationDisplay() {
EnumAuctionDuration duration = EnumAuctionDuration.values()[selectedDuration];
return DURATION_NAMES[selectedDuration] + " (" + duration.getHours() + "h)";
return duration.getDisplayName();
}
private long getListingFee() {
@@ -147,7 +146,7 @@ public class SubGuiAuctionCreate extends SubGuiInterface {
if (item != null) {
if (itemLabel != null) {
itemLabel.label = "Item: " + item.getDisplayName();
itemLabel.label = StatCollector.translateToLocal("auction.item") + " " + item.getDisplayName();
itemLabel.color = 0x008800;
}
if (createButton != null) {
@@ -155,7 +154,7 @@ public class SubGuiAuctionCreate extends SubGuiInterface {
}
} else {
if (itemLabel != null) {
itemLabel.label = "(No item selected)";
itemLabel.label = StatCollector.translateToLocal("auction.noItemSelected");
itemLabel.color = 0x888888;
}
if (createButton != null) {
@@ -2,6 +2,7 @@ package noppes.npcs.client.gui.player;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.SubGuiInterface;
@@ -34,70 +35,70 @@ public class SubGuiAuctionDetails extends SubGuiInterface {
int valueColor = 0x000000;
// Title
addLabel(new GuiNpcLabel(0, "Auction Details", guiLeft + 80, y, labelColor));
addLabel(new GuiNpcLabel(0, StatCollector.translateToLocal("auction.auctionDetails"), guiLeft + 80, y, labelColor));
y += 16;
// Item name
addLabel(new GuiNpcLabel(1, "Item:", guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("auction.item"), guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(2, listing.item.getDisplayName(), guiLeft + 80, y, valueColor));
y += 14;
// Quantity
addLabel(new GuiNpcLabel(3, "Quantity:", guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(3, StatCollector.translateToLocal("auction.quantity"), guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(4, String.valueOf(listing.item.stackSize), guiLeft + 80, y, valueColor));
y += 14;
// Seller
addLabel(new GuiNpcLabel(5, "Seller:", guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(5, StatCollector.translateToLocal("auction.seller"), guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(6, listing.sellerName, guiLeft + 80, y, valueColor));
y += 14;
// Starting price
addLabel(new GuiNpcLabel(10, "Starting Price:", guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(10, StatCollector.translateToLocal("auction.startingPrice"), guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(11, formatCurrency(listing.startingPrice), guiLeft + 100, y, valueColor));
y += 14;
// Current bid
if (listing.currentBid > 0) {
addLabel(new GuiNpcLabel(12, "Current Bid:", guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(12, StatCollector.translateToLocal("auction.currentBid"), guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(13, formatCurrency(listing.currentBid), guiLeft + 100, y, 0x008800));
y += 14;
// High bidder
addLabel(new GuiNpcLabel(14, "High Bidder:", guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(14, StatCollector.translateToLocal("auction.highBidder"), guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(15, listing.highBidderName, guiLeft + 100, y, valueColor));
y += 14;
// Bid count
addLabel(new GuiNpcLabel(16, "Total Bids:", guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(16, StatCollector.translateToLocal("auction.totalBids"), guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(17, String.valueOf(listing.bidCount), guiLeft + 100, y, valueColor));
y += 14;
} else {
addLabel(new GuiNpcLabel(12, "Current Bid:", guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(13, "No bids yet", guiLeft + 100, y, 0x888888));
addLabel(new GuiNpcLabel(12, StatCollector.translateToLocal("auction.currentBid"), guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(13, StatCollector.translateToLocal("auction.noBidsYet"), guiLeft + 100, y, 0x888888));
y += 14;
}
// Buyout price
if (listing.buyoutPrice > 0) {
addLabel(new GuiNpcLabel(20, "Buyout Price:", guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(20, StatCollector.translateToLocal("auction.buyoutPrice"), guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(21, formatCurrency(listing.buyoutPrice), guiLeft + 100, y, 0xAA6600));
y += 14;
}
// Minimum bid
addLabel(new GuiNpcLabel(22, "Minimum Bid:", guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(22, StatCollector.translateToLocal("auction.minimumBid"), guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(23, formatCurrency(listing.getMinimumBid()), guiLeft + 100, y, 0x0066AA));
y += 14;
// Time remaining (will be updated)
addLabel(new GuiNpcLabel(30, "Time Left:", guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(30, StatCollector.translateToLocal("auction.timeLeft"), guiLeft + 20, y, labelColor));
addLabel(new GuiNpcLabel(31, formatTimeRemaining(listing.getTimeRemaining()), guiLeft + 100, y,
getTimeColor(listing.getTimeRemaining())));
y += 20;
// Close button
addButton(new GuiNpcButton(50, guiLeft + 80, guiTop + 175, 80, 20, "Close"));
addButton(new GuiNpcButton(50, guiLeft + 80, guiTop + 175, 80, 20, StatCollector.translateToLocal("gui.close")));
}
private String formatCurrency(long amount) {
@@ -105,7 +106,7 @@ public class SubGuiAuctionDetails extends SubGuiInterface {
}
private String formatTimeRemaining(long millis) {
if (millis <= 0) return "Auction Ended";
if (millis <= 0) return StatCollector.translateToLocal("auction.ended");
long seconds = millis / 1000;
long minutes = seconds / 60;
@@ -1,156 +0,0 @@
package noppes.npcs.constants;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
/**
* Categories for auction house items.
* Used for filtering and browsing.
*/
public enum EnumAuctionCategory {
ALL, // Special: shows all categories
WEAPONS, // Swords, bows, etc.
ARMOR, // Helmets, chestplates, leggings, boots
TOOLS, // Pickaxes, axes, shovels, hoes
FOOD, // Edible items
POTIONS, // Potions and splash potions
BLOCKS, // Placeable blocks
MATERIALS, // Crafting materials (ingots, gems, etc.)
ENCHANTED, // Items with enchantments or enchanted books
MISC; // Everything else
/**
* Get display name for GUI
*/
public String getDisplayName() {
switch (this) {
case ALL: return "All Items";
case WEAPONS: return "Weapons";
case ARMOR: return "Armor";
case TOOLS: return "Tools";
case FOOD: return "Food";
case POTIONS: return "Potions";
case BLOCKS: return "Blocks";
case MATERIALS: return "Materials";
case ENCHANTED: return "Enchanted";
case MISC: return "Miscellaneous";
default: return "Unknown";
}
}
/**
* Auto-categorize an item based on its type
*/
public static EnumAuctionCategory categorize(ItemStack itemStack) {
if (itemStack == null || itemStack.getItem() == null) {
return MISC;
}
Item item = itemStack.getItem();
// Check for enchantments first (higher priority)
if (itemStack.isItemEnchanted() || item instanceof ItemEnchantedBook) {
return ENCHANTED;
}
// Weapons
if (item instanceof ItemSword || item instanceof ItemBow) {
return WEAPONS;
}
// Armor
if (item instanceof ItemArmor) {
return ARMOR;
}
// Tools
if (item instanceof ItemTool || item instanceof ItemPickaxe ||
item instanceof ItemAxe || item instanceof ItemSpade ||
item instanceof ItemHoe) {
return TOOLS;
}
// Food
if (item instanceof ItemFood) {
return FOOD;
}
// Potions
if (item instanceof ItemPotion) {
return POTIONS;
}
// Blocks
if (item instanceof ItemBlock) {
return BLOCKS;
}
// Materials - common crafting items
if (isMaterial(item)) {
return MATERIALS;
}
return MISC;
}
/**
* Check if an item is a common crafting material
*/
private static boolean isMaterial(Item item) {
// Check common material items
return item == Items.iron_ingot ||
item == Items.gold_ingot ||
item == Items.diamond ||
item == Items.emerald ||
item == Items.coal ||
item == Items.redstone ||
item == Items.glowstone_dust ||
item == Items.quartz ||
item == Items.leather ||
item == Items.string ||
item == Items.feather ||
item == Items.bone ||
item == Items.gunpowder ||
item == Items.slime_ball ||
item == Items.ender_pearl ||
item == Items.blaze_rod ||
item == Items.ghast_tear ||
item == Items.gold_nugget ||
item == Items.nether_wart ||
item == Items.spider_eye ||
item == Items.magma_cream ||
item == Items.nether_star;
}
/**
* Get icon item for category display
*/
public ItemStack getIconItem() {
switch (this) {
case ALL: return new ItemStack(Items.compass);
case WEAPONS: return new ItemStack(Items.iron_sword);
case ARMOR: return new ItemStack(Items.iron_chestplate);
case TOOLS: return new ItemStack(Items.iron_pickaxe);
case FOOD: return new ItemStack(Items.bread);
case POTIONS: return new ItemStack(Items.potionitem);
case BLOCKS: return new ItemStack(Item.getItemFromBlock(net.minecraft.init.Blocks.grass));
case MATERIALS: return new ItemStack(Items.iron_ingot);
case ENCHANTED: return new ItemStack(Items.enchanted_book);
case MISC: return new ItemStack(Items.chest_minecart);
default: return new ItemStack(Items.paper);
}
}
}
@@ -1,5 +1,6 @@
package noppes.npcs.constants;
import net.minecraft.util.StatCollector;
import noppes.npcs.config.ConfigMarket;
/**
@@ -7,10 +8,16 @@ import noppes.npcs.config.ConfigMarket;
* Values are configurable via ConfigMarket.
*/
public enum EnumAuctionDuration {
SHORT, // Default: 2 hours
MEDIUM, // Default: 12 hours
LONG, // Default: 24 hours
VERY_LONG; // Default: 48 hours
SHORT("auction.duration.short"),
MEDIUM("auction.duration.medium"),
LONG("auction.duration.long"),
VERY_LONG("auction.duration.veryLong");
private final String langKey;
EnumAuctionDuration(String langKey) {
this.langKey = langKey;
}
/**
* Get duration in milliseconds
@@ -30,22 +37,29 @@ public enum EnumAuctionDuration {
}
}
/**
* Get duration in hours
*/
public int getHours() {
switch (this) {
case SHORT:
return ConfigMarket.AuctionDurationShort;
case MEDIUM:
return ConfigMarket.AuctionDurationMedium;
case LONG:
return ConfigMarket.AuctionDurationLong;
case VERY_LONG:
return ConfigMarket.AuctionDurationVeryLong;
default:
return 24;
}
}
/**
* Get display name for GUI
*/
public String getDisplayName() {
switch (this) {
case SHORT:
return ConfigMarket.AuctionDurationShort + " Hours";
case MEDIUM:
return ConfigMarket.AuctionDurationMedium + " Hours";
case LONG:
return ConfigMarket.AuctionDurationLong + " Hours";
case VERY_LONG:
return ConfigMarket.AuctionDurationVeryLong + " Hours";
default:
return "Unknown";
}
return StatCollector.translateToLocal(langKey);
}
/**
@@ -1,66 +1,37 @@
package noppes.npcs.constants;
import net.minecraft.util.StatCollector;
/**
* Sorting options for auction listings.
*/
public enum EnumAuctionSort {
/** Default - newest listings first */
NEWEST_FIRST("Newest First"),
NEWEST_FIRST("auction.sort.newest"),
OLDEST_FIRST("auction.sort.oldest"),
PRICE_HIGH_TO_LOW("auction.sort.priceHigh"),
PRICE_LOW_TO_HIGH("auction.sort.priceLow"),
ENDING_SOON("auction.sort.endingSoon"),
MOST_TIME_LEFT("auction.sort.mostTime"),
NAME_A_TO_Z("auction.sort.nameAZ"),
NAME_Z_TO_A("auction.sort.nameZA"),
MOST_BIDS("auction.sort.mostBids"),
LEAST_BIDS("auction.sort.leastBids");
/** Oldest listings first */
OLDEST_FIRST("Oldest First"),
private final String langKey;
/** Highest current price first */
PRICE_HIGH_TO_LOW("Most Expensive"),
/** Lowest current price first */
PRICE_LOW_TO_HIGH("Least Expensive"),
/** Buyout price high to low (listings without buyout at end) */
BUYOUT_HIGH_TO_LOW("Buyout: High to Low"),
/** Buyout price low to high (listings without buyout at end) */
BUYOUT_LOW_TO_HIGH("Buyout: Low to High"),
/** Ending soonest first */
ENDING_SOON("Ending Soon"),
/** Most time remaining first */
MOST_TIME_LEFT("Most Time Left"),
/** Alphabetical by item name A-Z */
NAME_A_TO_Z("Name: A to Z"),
/** Alphabetical by item name Z-A */
NAME_Z_TO_A("Name: Z to A"),
/** Most bids first */
MOST_BIDS("Most Bids"),
/** Least bids first */
LEAST_BIDS("Least Bids");
private final String displayName;
EnumAuctionSort(String displayName) {
this.displayName = displayName;
EnumAuctionSort(String langKey) {
this.langKey = langKey;
}
public String getDisplayName() {
return displayName;
return StatCollector.translateToLocal(langKey);
}
/**
* Get next sort option (for cycling through in GUI)
*/
public EnumAuctionSort next() {
EnumAuctionSort[] values = values();
return values[(this.ordinal() + 1) % values.length];
}
/**
* Get previous sort option
*/
public EnumAuctionSort previous() {
EnumAuctionSort[] values = values();
return values[(this.ordinal() - 1 + values.length) % values.length];
@@ -1,20 +1,21 @@
package noppes.npcs.controllers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.config.ConfigMarket;
import noppes.npcs.constants.EnumAuctionCategory;
import noppes.npcs.constants.EnumAuctionDuration;
import noppes.npcs.constants.EnumAuctionSort;
import noppes.npcs.constants.EnumAuctionStatus;
import noppes.npcs.controllers.data.AuctionFilter;
import noppes.npcs.controllers.data.AuctionListing;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.FileInputStream;
@@ -25,10 +26,10 @@ import java.util.stream.Collectors;
/**
* Controller for the global auction house.
* Manages all auction listings, bidding, and claims.
* Manages all auction listings, bidding, claims, notifications, and logging.
*/
public class AuctionController {
private static final Logger logger = LogManager.getLogger(CustomNpcs.class);
private static final String LOG_PREFIX = "[Auction] ";
public static AuctionController Instance;
@@ -42,6 +43,9 @@ public class AuctionController {
private Map<UUID, List<Integer>> listingsBySeller = new ConcurrentHashMap<>();
private Map<UUID, List<Integer>> listingsByBidder = new ConcurrentHashMap<>();
// Pending notifications for offline players
private Map<UUID, List<String>> pendingNotifications = new ConcurrentHashMap<>();
public AuctionController() {
Instance = this;
load();
@@ -59,7 +63,7 @@ public class AuctionController {
// Validate item
String validation = AuctionListing.validateItem(item);
if (validation != null) {
logger.warn("Auction listing validation failed: " + validation);
LogWriter.info(LOG_PREFIX + "Listing validation failed: " + validation);
return null;
}
@@ -67,8 +71,6 @@ public class AuctionController {
int currentListings = getActiveListingsCount(seller.getUniqueID());
int maxListings = getMaxListings(seller);
if (currentListings >= maxListings) {
logger.info("Player {} has reached max listings ({}/{})",
seller.getCommandSenderName(), currentListings, maxListings);
return null;
}
@@ -85,8 +87,6 @@ public class AuctionController {
long listingFee = listing.getListingFee();
if (listingFee > 0) {
if (!CurrencyController.Instance.canAfford(seller, listingFee)) {
logger.info("Player {} cannot afford listing fee of {}",
seller.getCommandSenderName(), listingFee);
return null;
}
CurrencyController.Instance.withdraw(seller, listingFee);
@@ -100,12 +100,11 @@ public class AuctionController {
addToSellerIndex(seller.getUniqueID(), listing.id);
save();
logger.info("Created auction listing {} by {} for {}",
listing.id, seller.getCommandSenderName(),
item.getDisplayName());
// Log to CNPC+ auction history
AuctionLogger.logListingCreated(listing);
// Log to CNPC+
logEvent("LISTING_CREATED", String.format("ID=%d, Seller=%s, Item=%s x%d, StartPrice=%d, Buyout=%s",
listing.id, listing.sellerName, item.getDisplayName(), item.stackSize,
listing.startingPrice, listing.buyoutPrice > 0 ? listing.buyoutPrice : "None"));
return listing;
}
@@ -127,18 +126,6 @@ public class AuctionController {
.collect(Collectors.toList());
}
/**
* Get active listings by category
*/
public List<AuctionListing> getActiveListings(EnumAuctionCategory category) {
if (category == EnumAuctionCategory.ALL) {
return getActiveListings();
}
return getActiveListings().stream()
.filter(l -> l.category == category)
.collect(Collectors.toList());
}
/**
* Search listings by item name
*/
@@ -153,7 +140,6 @@ public class AuctionController {
/**
* Get filtered and sorted auction listings.
* This is the main method for GUI queries.
* @param filter The filter criteria
* @return FilterResult containing matching listings and metadata
*/
@@ -171,7 +157,7 @@ public class AuctionController {
// Calculate pagination
int totalResults = results.size();
int totalPages = (int) Math.ceil((double) totalResults / filter.pageSize);
int totalPages = Math.max(1, (int) Math.ceil((double) totalResults / filter.pageSize));
int startIndex = filter.page * filter.pageSize;
int endIndex = Math.min(startIndex + filter.pageSize, totalResults);
@@ -180,7 +166,7 @@ public class AuctionController {
if (startIndex >= totalResults) {
pageResults = new ArrayList<>();
} else {
pageResults = results.subList(startIndex, endIndex);
pageResults = new ArrayList<>(results.subList(startIndex, endIndex));
}
return new FilterResult(pageResults, totalResults, filter.page, totalPages);
@@ -200,61 +186,36 @@ public class AuctionController {
case NEWEST_FIRST:
comparator = Comparator.comparingLong(l -> -l.listingTime);
break;
case OLDEST_FIRST:
comparator = Comparator.comparingLong(l -> l.listingTime);
break;
case PRICE_HIGH_TO_LOW:
comparator = Comparator.comparingLong((AuctionListing l) ->
-(l.currentBid > 0 ? l.currentBid : l.startingPrice));
break;
case PRICE_LOW_TO_HIGH:
comparator = Comparator.comparingLong(l ->
l.currentBid > 0 ? l.currentBid : l.startingPrice);
break;
case BUYOUT_HIGH_TO_LOW:
// Listings with buyout first, sorted high to low
comparator = Comparator
.comparingInt((AuctionListing l) -> l.buyoutPrice > 0 ? 0 : 1)
.thenComparingLong(l -> -l.buyoutPrice);
break;
case BUYOUT_LOW_TO_HIGH:
// Listings with buyout first, sorted low to high
comparator = Comparator
.comparingInt((AuctionListing l) -> l.buyoutPrice > 0 ? 0 : 1)
.thenComparingLong(l -> l.buyoutPrice);
break;
case ENDING_SOON:
comparator = Comparator.comparingLong(l -> l.expirationTime);
break;
case MOST_TIME_LEFT:
comparator = Comparator.comparingLong(l -> -l.expirationTime);
break;
case NAME_A_TO_Z:
comparator = Comparator.comparing(l ->
l.item.getDisplayName().toLowerCase());
comparator = Comparator.comparing(l -> l.item.getDisplayName().toLowerCase());
break;
case NAME_Z_TO_A:
comparator = Comparator.comparing((AuctionListing l) ->
l.item.getDisplayName().toLowerCase()).reversed();
break;
case MOST_BIDS:
comparator = Comparator.comparingInt(l -> -l.bidCount);
break;
case LEAST_BIDS:
comparator = Comparator.comparingInt(l -> l.bidCount);
break;
default:
comparator = Comparator.comparingLong(l -> l.expirationTime);
}
@@ -262,28 +223,6 @@ public class AuctionController {
listings.sort(comparator);
}
/**
* Quick search with default sorting (ending soon)
*/
public List<AuctionListing> quickSearch(String searchText, EnumAuctionCategory category, int limit) {
AuctionFilter filter = new AuctionFilter()
.withSearch(searchText)
.withCategory(category)
.withSort(EnumAuctionSort.ENDING_SOON)
.withPage(0, limit);
return getFilteredListings(filter).listings;
}
/**
* Get listings sorted by a specific order
*/
public List<AuctionListing> getListingsSorted(EnumAuctionSort sortOrder) {
List<AuctionListing> results = new ArrayList<>(getActiveListings());
sortListings(results, sortOrder);
return results;
}
/**
* Result container for filtered queries
*/
@@ -315,7 +254,7 @@ public class AuctionController {
}
/**
* Get all listings by a seller (all statuses)
* Get all listings by a seller
*/
public List<AuctionListing> getListingsBySeller(UUID sellerUUID) {
List<Integer> ids = listingsBySeller.get(sellerUUID);
@@ -354,7 +293,6 @@ public class AuctionController {
/**
* Get listings that need claiming by a player
* (items won, sales proceeds, cancelled/expired items)
*/
public List<AuctionListing> getClaimableListings(UUID playerUUID) {
List<AuctionListing> claimable = new ArrayList<>();
@@ -391,7 +329,6 @@ public class AuctionController {
/**
* Place a bid on an auction
* @return true if bid was successful
*/
public boolean placeBid(int listingId, EntityPlayer bidder, long amount) {
AuctionListing listing = listings.get(listingId);
@@ -399,61 +336,51 @@ public class AuctionController {
return false;
}
// Check if bidder can afford
if (!CurrencyController.Instance.canAfford(bidder, amount)) {
return false;
}
// Store previous bidder for refund and notification
// Store previous bidder for refund
UUID previousBidder = listing.highBidderUUID;
String previousBidderName = listing.highBidderName;
long previousBidAmount = listing.currentBid;
// Try to place bid
if (!listing.placeBid(bidder.getUniqueID(), bidder.getCommandSenderName(), amount)) {
return false;
}
// Withdraw bid amount from new bidder
CurrencyController.Instance.withdraw(bidder, amount);
// Refund previous bidder via claims system and notify
// Refund previous bidder
if (previousBidder != null) {
CurrencyController.Instance.addClaim(
previousBidder,
previousBidAmount,
"Auction Outbid",
String.valueOf(listingId)
);
CurrencyController.Instance.addClaim(previousBidder, previousBidAmount,
"Auction Outbid", String.valueOf(listingId));
// Notify previous bidder they were outbid
if (AuctionNotificationController.Instance != null) {
AuctionNotificationController.Instance.notifyOutbid(
listing, previousBidder, previousBidderName, previousBidAmount, amount);
}
// Notify outbid player
notifyPlayer(previousBidder, EnumChatFormatting.RED +
"You have been outbid on " + EnumChatFormatting.WHITE + listing.item.getDisplayName() +
EnumChatFormatting.RED + "! New bid: " + formatCurrency(amount));
// Log refund
AuctionLogger.logBidRefunded(listing, previousBidderName, previousBidAmount);
logEvent("OUTBID", String.format("ID=%d, OutbidPlayer=%s, PrevBid=%d, NewBid=%d",
listingId, previousBidderName, previousBidAmount, amount));
}
// Notify seller of new bid
if (AuctionNotificationController.Instance != null) {
AuctionNotificationController.Instance.notifyNewBid(listing, bidder.getCommandSenderName(), amount);
}
// Notify seller
notifyPlayer(listing.sellerUUID, EnumChatFormatting.AQUA +
bidder.getCommandSenderName() + " placed a bid of " + formatCurrency(amount) +
" on your " + listing.item.getDisplayName() + "!");
// Update bidder index
addToBidderIndex(bidder.getUniqueID(), listingId);
save();
logger.info("Bid placed on listing {} by {} for {}",
listingId, bidder.getCommandSenderName(), amount);
logEvent("BID_PLACED", String.format("ID=%d, Bidder=%s, Amount=%d",
listingId, bidder.getCommandSenderName(), amount));
return true;
}
/**
* Execute buyout on an auction
* @return true if buyout was successful
*/
public boolean buyout(int listingId, EntityPlayer buyer) {
AuctionListing listing = listings.get(listingId);
@@ -461,66 +388,50 @@ public class AuctionController {
return false;
}
// Check if buyer can afford
if (!CurrencyController.Instance.canAfford(buyer, listing.buyoutPrice)) {
return false;
}
// Store previous bidder for refund and notification
UUID previousBidder = listing.highBidderUUID;
String previousBidderName = listing.highBidderName;
long previousBidAmount = listing.currentBid;
// Execute buyout
if (!listing.buyout(buyer.getUniqueID(), buyer.getCommandSenderName())) {
return false;
}
// Withdraw buyout amount from buyer
CurrencyController.Instance.withdraw(buyer, listing.buyoutPrice);
// Refund previous bidder via claims system and notify
// Refund previous bidder
if (previousBidder != null) {
CurrencyController.Instance.addClaim(
previousBidder,
previousBidAmount,
"Auction Outbid (Buyout)",
String.valueOf(listingId)
);
CurrencyController.Instance.addClaim(previousBidder, previousBidAmount,
"Auction Outbid (Buyout)", String.valueOf(listingId));
// Notify previous bidder they were outbid
if (AuctionNotificationController.Instance != null) {
AuctionNotificationController.Instance.notifyOutbid(
listing, previousBidder, previousBidderName, previousBidAmount, listing.buyoutPrice);
}
// Log refund
AuctionLogger.logBidRefunded(listing, previousBidderName, previousBidAmount);
notifyPlayer(previousBidder, EnumChatFormatting.RED +
"Your bid on " + EnumChatFormatting.WHITE + listing.item.getDisplayName() +
EnumChatFormatting.RED + " was outbid by a buyout. Your " +
formatCurrency(previousBidAmount) + " has been refunded.");
}
// Update bidder index
addToBidderIndex(buyer.getUniqueID(), listingId);
save();
logger.info("Buyout executed on listing {} by {} for {}",
listingId, buyer.getCommandSenderName(), listing.buyoutPrice);
// Log buyout and send notifications
AuctionLogger.logBuyout(listing, buyer.getCommandSenderName());
// Notify buyer and seller
notifyPlayer(buyer.getUniqueID(), EnumChatFormatting.GREEN +
"Buyout successful! Claim your " + listing.item.getDisplayName() + " from an Auctioneer.");
if (AuctionNotificationController.Instance != null) {
// Notify buyer they won
AuctionNotificationController.Instance.notifyAuctionWon(listing);
// Notify seller their item sold
AuctionNotificationController.Instance.notifyAuctionSold(listing);
}
notifyPlayer(listing.sellerUUID, EnumChatFormatting.GREEN +
"Your " + listing.item.getDisplayName() + " was bought out for " +
formatCurrency(listing.buyoutPrice) + "! Claim your proceeds.");
logEvent("BUYOUT", String.format("ID=%d, Buyer=%s, Price=%d, Seller=%s",
listingId, buyer.getCommandSenderName(), listing.buyoutPrice, listing.sellerName));
return true;
}
/**
* Cancel an auction listing
* @return true if cancellation was successful
*/
public boolean cancelListing(int listingId, EntityPlayer requester) {
AuctionListing listing = listings.get(listingId);
@@ -535,15 +446,16 @@ public class AuctionController {
}
save();
logger.info("Listing {} cancelled by {}",
listingId, requester.getCommandSenderName());
// Log and notify
AuctionLogger.logAuctionCancelled(listing, byAdmin);
if (AuctionNotificationController.Instance != null) {
AuctionNotificationController.Instance.notifyAuctionCancelled(listing, byAdmin);
if (byAdmin) {
notifyPlayer(listing.sellerUUID, EnumChatFormatting.RED +
"Your auction for " + listing.item.getDisplayName() +
" was cancelled by an administrator.");
}
logEvent("CANCELLED", String.format("ID=%d, CancelledBy=%s, ByAdmin=%b",
listingId, requester.getCommandSenderName(), byAdmin));
return true;
}
@@ -551,27 +463,14 @@ public class AuctionController {
/**
* Claim seller proceeds from a sold auction
* @return true if claim was successful
*/
public boolean claimSellerProceeds(int listingId, EntityPlayer seller) {
AuctionListing listing = listings.get(listingId);
if (listing == null) {
if (listing == null || !listing.sellerUUID.equals(seller.getUniqueID()) ||
listing.status != EnumAuctionStatus.SOLD || listing.sellerClaimed) {
return false;
}
if (!listing.sellerUUID.equals(seller.getUniqueID())) {
return false; // Not the seller
}
if (listing.status != EnumAuctionStatus.SOLD) {
return false; // Not sold
}
if (listing.sellerClaimed) {
return false; // Already claimed
}
// Deposit proceeds to seller
long proceeds = listing.getSellerProceeds();
CurrencyController.Instance.deposit(seller, proceeds);
@@ -579,95 +478,58 @@ public class AuctionController {
checkAndMarkClaimed(listing);
save();
logger.info("Seller {} claimed {} from listing {}",
seller.getCommandSenderName(), proceeds, listingId);
// Log the currency claim
AuctionLogger.logCurrencyClaimed(listing, seller.getCommandSenderName(), proceeds);
logEvent("PROCEEDS_CLAIMED", String.format("ID=%d, Seller=%s, Amount=%d",
listingId, seller.getCommandSenderName(), proceeds));
return true;
}
/**
* Claim item from won auction
* @return The item if successful, null otherwise
*/
public ItemStack claimBuyerItem(int listingId, EntityPlayer buyer) {
AuctionListing listing = listings.get(listingId);
if (listing == null) {
if (listing == null || listing.highBidderUUID == null ||
!listing.highBidderUUID.equals(buyer.getUniqueID()) ||
listing.status != EnumAuctionStatus.SOLD || listing.buyerClaimed) {
return null;
}
if (listing.highBidderUUID == null ||
!listing.highBidderUUID.equals(buyer.getUniqueID())) {
return null; // Not the buyer
}
if (listing.status != EnumAuctionStatus.SOLD) {
return null; // Not sold
}
if (listing.buyerClaimed) {
return null; // Already claimed
}
listing.buyerClaimed = true;
checkAndMarkClaimed(listing);
save();
logger.info("Buyer {} claimed item from listing {}",
buyer.getCommandSenderName(), listingId);
// Log the item claim
AuctionLogger.logItemClaimed(listing, buyer.getCommandSenderName(), false);
logEvent("ITEM_CLAIMED", String.format("ID=%d, Buyer=%s, Item=%s",
listingId, buyer.getCommandSenderName(), listing.item.getDisplayName()));
return listing.item.copy();
}
/**
* Claim item from cancelled or expired auction (seller reclaiming)
* @return The item if successful, null otherwise
* Claim item from cancelled or expired auction
*/
public ItemStack claimExpiredItem(int listingId, EntityPlayer seller) {
AuctionListing listing = listings.get(listingId);
if (listing == null) {
if (listing == null || !listing.sellerUUID.equals(seller.getUniqueID()) ||
(listing.status != EnumAuctionStatus.CANCELLED && listing.status != EnumAuctionStatus.EXPIRED) ||
listing.sellerClaimed) {
return null;
}
if (!listing.sellerUUID.equals(seller.getUniqueID())) {
return null; // Not the seller
}
if (listing.status != EnumAuctionStatus.CANCELLED &&
listing.status != EnumAuctionStatus.EXPIRED) {
return null; // Not claimable
}
if (listing.sellerClaimed) {
return null; // Already claimed
}
listing.sellerClaimed = true;
listing.status = EnumAuctionStatus.CLAIMED;
save();
logger.info("Seller {} reclaimed item from listing {}",
seller.getCommandSenderName(), listingId);
// Log the item reclaim
AuctionLogger.logItemClaimed(listing, seller.getCommandSenderName(), true);
logEvent("ITEM_RECLAIMED", String.format("ID=%d, Seller=%s, Item=%s",
listingId, seller.getCommandSenderName(), listing.item.getDisplayName()));
return listing.item.copy();
}
/**
* Mark listing as fully claimed if both parties have claimed
*/
private void checkAndMarkClaimed(AuctionListing listing) {
if (listing.status == EnumAuctionStatus.SOLD) {
if (listing.sellerClaimed && listing.buyerClaimed) {
listing.status = EnumAuctionStatus.CLAIMED;
}
if (listing.status == EnumAuctionStatus.SOLD &&
listing.sellerClaimed && listing.buyerClaimed) {
listing.status = EnumAuctionStatus.CLAIMED;
}
}
@@ -675,58 +537,49 @@ public class AuctionController {
/**
* Process all expired auctions
* Call this periodically (e.g., every minute)
*/
public void processExpiredAuctions() {
boolean changed = false;
int expiredCount = 0;
int soldCount = 0;
for (AuctionListing listing : listings.values()) {
if (listing.status == EnumAuctionStatus.ACTIVE && listing.isExpired()) {
listing.finalize();
changed = true;
// If sold, add proceeds to seller's claims
if (listing.status == EnumAuctionStatus.SOLD) {
soldCount++;
// Proceeds will be claimed manually, no automatic deposit
logger.info("Auction {} ended with sale to {} for {}",
listing.id, listing.highBidderName, listing.currentBid);
// Notify winner and seller
notifyPlayer(listing.highBidderUUID, EnumChatFormatting.GREEN +
"You won the auction for " + listing.item.getDisplayName() +
" for " + formatCurrency(listing.currentBid) + "! Claim your item.");
// Send notifications
if (AuctionNotificationController.Instance != null) {
AuctionNotificationController.Instance.notifyAuctionWon(listing);
AuctionNotificationController.Instance.notifyAuctionSold(listing);
}
notifyPlayer(listing.sellerUUID, EnumChatFormatting.GREEN +
"Your " + listing.item.getDisplayName() + " sold for " +
formatCurrency(listing.currentBid) + "! Claim your proceeds.");
logEvent("AUCTION_SOLD", String.format("ID=%d, Winner=%s, Price=%d, Seller=%s",
listing.id, listing.highBidderName, listing.currentBid, listing.sellerName));
} else {
expiredCount++;
logger.info("Auction {} expired without bids", listing.id);
notifyPlayer(listing.sellerUUID, EnumChatFormatting.GRAY +
"Your auction for " + listing.item.getDisplayName() +
" has expired with no bids. Claim your item.");
// Notify seller about expiration
if (AuctionNotificationController.Instance != null) {
AuctionNotificationController.Instance.notifyAuctionExpired(listing);
}
logEvent("AUCTION_EXPIRED", String.format("ID=%d, Item=%s, Seller=%s",
listing.id, listing.item.getDisplayName(), listing.sellerName));
}
}
}
if (changed) {
save();
// Log processing tick if anything happened
AuctionLogger.logProcessingTick(expiredCount, soldCount);
}
}
/**
* Clean up old claimed listings
* Call this periodically (e.g., daily)
*/
public void cleanupOldListings() {
long claimExpirationMs = ConfigMarket.ClaimExpirationDays * 24L * 60L * 60L * 1000L;
if (claimExpirationMs <= 0) {
return; // No expiration
}
if (claimExpirationMs <= 0) return;
long cutoffTime = System.currentTimeMillis() - claimExpirationMs;
List<Integer> toRemove = new ArrayList<>();
@@ -750,10 +603,71 @@ public class AuctionController {
if (!toRemove.isEmpty()) {
save();
logger.info("Cleaned up {} old auction listings", toRemove.size());
logEvent("CLEANUP", "Removed " + toRemove.size() + " old listings");
}
}
// ==================== Notifications ====================
/**
* Send notification to player (or queue if offline)
*/
private void notifyPlayer(UUID playerUUID, String message) {
if (playerUUID == null) return;
EntityPlayerMP player = getOnlinePlayer(playerUUID);
String fullMessage = EnumChatFormatting.YELLOW + "[Auction] " + message;
if (player != null) {
player.addChatMessage(new ChatComponentText(fullMessage));
} else {
pendingNotifications.computeIfAbsent(playerUUID, k -> new ArrayList<>()).add(fullMessage);
// Limit queue size
List<String> queue = pendingNotifications.get(playerUUID);
while (queue.size() > 50) {
queue.remove(0);
}
}
}
/**
* Send pending notifications on player login
*/
public void onPlayerLogin(EntityPlayerMP player) {
UUID uuid = player.getUniqueID();
List<String> notifications = pendingNotifications.remove(uuid);
if (notifications != null && !notifications.isEmpty()) {
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.YELLOW + "[Auction] " + EnumChatFormatting.WHITE +
"You have " + notifications.size() + " auction notification(s):"));
for (String msg : notifications) {
player.addChatMessage(new ChatComponentText(msg));
}
}
// Check claimable items
int claimableCount = getClaimableListings(uuid).size();
if (claimableCount > 0) {
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.YELLOW + "[Auction] " + EnumChatFormatting.GREEN +
"You have " + claimableCount + " item(s) waiting to be claimed!"));
}
}
private EntityPlayerMP getOnlinePlayer(UUID uuid) {
if (CustomNpcs.getServer() == null) return null;
for (Object obj : CustomNpcs.getServer().getConfigurationManager().playerEntityList) {
EntityPlayerMP player = (EntityPlayerMP) obj;
if (player.getUniqueID().equals(uuid)) {
return player;
}
}
return null;
}
// ==================== Index Management ====================
private void addToSellerIndex(UUID seller, int listingId) {
@@ -790,24 +704,25 @@ public class AuctionController {
}
}
// ==================== Permission Helpers ====================
// ==================== Helpers ====================
/**
* Get maximum listings allowed for a player
*/
public int getMaxListings(EntityPlayer player) {
// TODO: Check for permission-based overrides
// e.g., CustomNpcsPermissions.hasCustomPermission(player, "cnpc.auction.slots.10")
return ConfigMarket.DefaultMaxListings;
}
private String formatCurrency(long amount) {
return String.format("%,d %s", amount, ConfigMarket.CurrencyName);
}
private void logEvent(String event, String details) {
LogWriter.info(LOG_PREFIX + event + ": " + details);
}
// ==================== Persistence ====================
public void save() {
File saveDir = CustomNpcs.getWorldSaveDirectory();
if (saveDir == null) {
return;
}
if (saveDir == null) return;
try {
NBTTagCompound compound = new NBTTagCompound();
@@ -823,9 +738,7 @@ public class AuctionController {
File backup = new File(saveDir, "auctions.dat_old");
if (file.exists()) {
if (backup.exists()) {
backup.delete();
}
if (backup.exists()) backup.delete();
file.renameTo(backup);
}
@@ -835,15 +748,13 @@ public class AuctionController {
fos.close();
} catch (Exception e) {
logger.error("Error saving auctions", e);
LogWriter.error(LOG_PREFIX + "Error saving auctions", e);
}
}
public void load() {
File saveDir = CustomNpcs.getWorldSaveDirectory();
if (saveDir == null) {
return;
}
if (saveDir == null) return;
listings.clear();
@@ -851,9 +762,7 @@ public class AuctionController {
File file = new File(saveDir, "auctions.dat");
if (!file.exists()) {
file = new File(saveDir, "auctions.dat_old");
if (!file.exists()) {
return;
}
if (!file.exists()) return;
}
FileInputStream fis = new FileInputStream(file);
@@ -861,9 +770,7 @@ public class AuctionController {
fis.close();
nextId = compound.getInteger("NextId");
if (nextId < 1) {
nextId = 1;
}
if (nextId < 1) nextId = 1;
NBTTagList listingList = compound.getTagList("Listings", 10);
for (int i = 0; i < listingList.tagCount(); i++) {
@@ -874,42 +781,22 @@ public class AuctionController {
rebuildIndices();
logger.info("Loaded {} auction listings", listings.size());
// Log system startup
int activeCount = getActiveListingCount();
int pendingClaims = 0;
for (AuctionListing listing : listings.values()) {
if (!listing.sellerClaimed || !listing.buyerClaimed) {
if (listing.status == EnumAuctionStatus.SOLD ||
listing.status == EnumAuctionStatus.EXPIRED ||
listing.status == EnumAuctionStatus.CANCELLED) {
pendingClaims++;
}
}
}
AuctionLogger.logSystemStartup(activeCount, pendingClaims);
logEvent("SYSTEM_STARTUP", String.format("Loaded %d listings, %d active",
listings.size(), getActiveListingCount()));
} catch (Exception e) {
logger.error("Error loading auctions", e);
AuctionLogger.logError("Loading auctions", e);
LogWriter.error(LOG_PREFIX + "Error loading auctions", e);
}
}
// ==================== Statistics ====================
/**
* Get total number of active listings
*/
public int getActiveListingCount() {
return (int) listings.values().stream()
.filter(l -> l.status == EnumAuctionStatus.ACTIVE)
.count();
}
/**
* Get total number of all listings
*/
public int getTotalListingCount() {
return listings.size();
}
@@ -1,269 +0,0 @@
package noppes.npcs.controllers;
import noppes.npcs.LogWriter;
import noppes.npcs.config.ConfigMarket;
import noppes.npcs.constants.EnumAuctionStatus;
import noppes.npcs.controllers.data.AuctionListing;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Handles auction history logging to the CNPC+ logging system.
* All auction events are recorded for administrative review.
*/
public class AuctionLogger {
private static final String PREFIX = "[Auction] ";
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* Log when a new auction listing is created
*/
public static void logListingCreated(AuctionListing listing) {
String msg = String.format("%sLISTING_CREATED: ID=%d, Seller=%s (%s), Item=%s x%d, StartPrice=%d, Buyout=%s, Duration=%s",
PREFIX,
listing.id,
listing.sellerName,
listing.sellerUUID.toString(),
listing.item.getDisplayName(),
listing.item.stackSize,
listing.startingPrice,
listing.buyoutPrice > 0 ? String.valueOf(listing.buyoutPrice) : "None",
formatDuration(listing.expirationTime - listing.listingTime)
);
LogWriter.info(msg);
}
/**
* Log when a bid is placed
*/
public static void logBidPlaced(AuctionListing listing, String bidderName, long bidAmount) {
String msg = String.format("%sBID_PLACED: ID=%d, Item=%s, Bidder=%s, Amount=%d %s, Previous=%d %s",
PREFIX,
listing.id,
listing.item.getDisplayName(),
bidderName,
bidAmount,
ConfigMarket.CurrencyName,
listing.currentBid,
ConfigMarket.CurrencyName
);
LogWriter.info(msg);
}
/**
* Log when a player is outbid
*/
public static void logOutbid(AuctionListing listing, String outbidPlayerName, long previousBid,
String newBidderName, long newBid) {
String msg = String.format("%sOUTBID: ID=%d, Item=%s, OutbidPlayer=%s (had %d), NewBidder=%s (bid %d)",
PREFIX,
listing.id,
listing.item.getDisplayName(),
outbidPlayerName,
previousBid,
newBidderName,
newBid
);
LogWriter.info(msg);
}
/**
* Log when a buyout occurs
*/
public static void logBuyout(AuctionListing listing, String buyerName) {
String msg = String.format("%sBUYOUT: ID=%d, Item=%s, Buyer=%s, Price=%d %s, Seller=%s",
PREFIX,
listing.id,
listing.item.getDisplayName(),
buyerName,
listing.buyoutPrice,
ConfigMarket.CurrencyName,
listing.sellerName
);
LogWriter.info(msg);
}
/**
* Log when an auction is won (ended with bids)
*/
public static void logAuctionWon(AuctionListing listing) {
String msg = String.format("%sAUCTION_WON: ID=%d, Item=%s, Winner=%s (%s), FinalPrice=%d %s, Seller=%s, SellerProceeds=%d %s",
PREFIX,
listing.id,
listing.item.getDisplayName(),
listing.highBidderName,
listing.highBidderUUID != null ? listing.highBidderUUID.toString() : "N/A",
listing.currentBid,
ConfigMarket.CurrencyName,
listing.sellerName,
listing.getSellerProceeds(),
ConfigMarket.CurrencyName
);
LogWriter.info(msg);
}
/**
* Log when an auction sells (same as won, for notification controller compatibility)
*/
public static void logAuctionSold(AuctionListing listing) {
String msg = String.format("%sAUCTION_SOLD: ID=%d, Item=%s, Buyer=%s, SalePrice=%d %s, Seller=%s (%s), Proceeds=%d %s",
PREFIX,
listing.id,
listing.item.getDisplayName(),
listing.highBidderName,
listing.currentBid,
ConfigMarket.CurrencyName,
listing.sellerName,
listing.sellerUUID.toString(),
listing.getSellerProceeds(),
ConfigMarket.CurrencyName
);
LogWriter.info(msg);
}
/**
* Log when an auction expires with no bids
*/
public static void logAuctionExpired(AuctionListing listing) {
String msg = String.format("%sAUCTION_EXPIRED: ID=%d, Item=%s, Seller=%s (%s), StartPrice=%d %s, Duration=%s",
PREFIX,
listing.id,
listing.item.getDisplayName(),
listing.sellerName,
listing.sellerUUID.toString(),
listing.startingPrice,
ConfigMarket.CurrencyName,
formatDuration(listing.expirationTime - listing.listingTime)
);
LogWriter.info(msg);
}
/**
* Log when an auction is cancelled
*/
public static void logAuctionCancelled(AuctionListing listing, boolean byAdmin) {
String msg = String.format("%sAUCTION_CANCELLED: ID=%d, Item=%s, Seller=%s, CancelledBy=%s, HadBids=%b",
PREFIX,
listing.id,
listing.item.getDisplayName(),
listing.sellerName,
byAdmin ? "ADMIN" : "SELLER",
listing.currentBid > 0
);
LogWriter.info(msg);
}
/**
* Log when an item is claimed
*/
public static void logItemClaimed(AuctionListing listing, String claimerName, boolean isSeller) {
String claimType = isSeller ?
(listing.status == EnumAuctionStatus.EXPIRED ? "RECLAIMED_EXPIRED" : "CLAIMED_PROCEEDS") :
"CLAIMED_WON_ITEM";
String msg = String.format("%s%s: ID=%d, Item=%s, Claimer=%s, Status=%s",
PREFIX,
claimType,
listing.id,
listing.item.getDisplayName(),
claimerName,
listing.status.name()
);
LogWriter.info(msg);
}
/**
* Log currency claimed from auction
*/
public static void logCurrencyClaimed(AuctionListing listing, String claimerName, long amount) {
String msg = String.format("%sCURRENCY_CLAIMED: ID=%d, Claimer=%s, Amount=%d %s",
PREFIX,
listing.id,
claimerName,
amount,
ConfigMarket.CurrencyName
);
LogWriter.info(msg);
}
/**
* Log refund of bid to outbid player
*/
public static void logBidRefunded(AuctionListing listing, String playerName, long amount) {
String msg = String.format("%sBID_REFUNDED: ID=%d, Player=%s, Amount=%d %s",
PREFIX,
listing.id,
playerName,
amount,
ConfigMarket.CurrencyName
);
LogWriter.info(msg);
}
/**
* Log admin actions on auctions
*/
public static void logAdminAction(String adminName, String action, AuctionListing listing) {
String msg = String.format("%sADMIN_ACTION: Admin=%s, Action=%s, ListingID=%d, Item=%s, Seller=%s",
PREFIX,
adminName,
action,
listing.id,
listing.item.getDisplayName(),
listing.sellerName
);
LogWriter.info(msg);
}
/**
* Log auction system startup
*/
public static void logSystemStartup(int activeListings, int pendingClaims) {
String msg = String.format("%sSYSTEM_STARTUP: ActiveListings=%d, PendingClaims=%d, Timestamp=%s",
PREFIX,
activeListings,
pendingClaims,
dateFormat.format(new Date())
);
LogWriter.info(msg);
}
/**
* Log auction processing tick
*/
public static void logProcessingTick(int expired, int completed) {
if (expired > 0 || completed > 0) {
String msg = String.format("%sPROCESSING_TICK: ExpiredListings=%d, CompletedAuctions=%d",
PREFIX,
expired,
completed
);
LogWriter.info(msg);
}
}
/**
* Log errors in the auction system
*/
public static void logError(String context, Exception e) {
String msg = String.format("%sERROR: Context=%s, Message=%s",
PREFIX,
context,
e.getMessage()
);
LogWriter.error(msg, e);
}
/**
* Format duration in a human-readable format
*/
private static String formatDuration(long millis) {
long hours = millis / (1000 * 60 * 60);
if (hours >= 24) {
long days = hours / 24;
return days + "d " + (hours % 24) + "h";
}
return hours + "h";
}
}
@@ -1,226 +0,0 @@
package noppes.npcs.controllers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import noppes.npcs.LogWriter;
import noppes.npcs.config.ConfigMarket;
import noppes.npcs.controllers.data.AuctionListing;
import java.util.*;
/**
* Handles auction notifications for players.
* Sends messages for outbid, won, sold, expired events.
*/
public class AuctionNotificationController {
public static AuctionNotificationController Instance;
// Pending notifications for offline players (UUID -> List of notifications)
private Map<UUID, List<AuctionNotification>> pendingNotifications = new HashMap<>();
public AuctionNotificationController() {
Instance = this;
}
/**
* Notify a player they have been outbid
*/
public void notifyOutbid(AuctionListing listing, UUID outbidPlayerUUID,
String outbidPlayerName, long previousBid, long newBid) {
String message = EnumChatFormatting.YELLOW + "[Auction] " + EnumChatFormatting.RED +
"You have been outbid on " + EnumChatFormatting.WHITE +
listing.item.getDisplayName() + EnumChatFormatting.RED +
"! New bid: " + formatCurrency(newBid) +
" (Your bid: " + formatCurrency(previousBid) + " has been refunded to claims)";
sendOrQueueNotification(outbidPlayerUUID, NotificationType.OUTBID, message, listing.id);
// Log the outbid event
AuctionLogger.logOutbid(listing, outbidPlayerName, previousBid, listing.highBidderName, newBid);
}
/**
* Notify a player they won an auction
*/
public void notifyAuctionWon(AuctionListing listing) {
if (listing.highBidderUUID == null) return;
String message = EnumChatFormatting.YELLOW + "[Auction] " + EnumChatFormatting.GREEN +
"Congratulations! You won the auction for " + EnumChatFormatting.WHITE +
listing.item.getDisplayName() + EnumChatFormatting.GREEN +
" for " + formatCurrency(listing.currentBid) + "! Visit an Auctioneer to claim your item.";
sendOrQueueNotification(listing.highBidderUUID, NotificationType.WON, message, listing.id);
// Log the win
AuctionLogger.logAuctionWon(listing);
}
/**
* Notify seller their auction sold
*/
public void notifyAuctionSold(AuctionListing listing) {
String message = EnumChatFormatting.YELLOW + "[Auction] " + EnumChatFormatting.GREEN +
"Your " + EnumChatFormatting.WHITE + listing.item.getDisplayName() +
EnumChatFormatting.GREEN + " sold for " + formatCurrency(listing.currentBid) +
"! Visit an Auctioneer to claim " + formatCurrency(listing.getSellerProceeds()) + ".";
sendOrQueueNotification(listing.sellerUUID, NotificationType.SOLD, message, listing.id);
// Log the sale
AuctionLogger.logAuctionSold(listing);
}
/**
* Notify seller their auction expired with no bids
*/
public void notifyAuctionExpired(AuctionListing listing) {
String message = EnumChatFormatting.YELLOW + "[Auction] " + EnumChatFormatting.GRAY +
"Your auction for " + EnumChatFormatting.WHITE + listing.item.getDisplayName() +
EnumChatFormatting.GRAY + " has expired with no bids. Visit an Auctioneer to reclaim your item.";
sendOrQueueNotification(listing.sellerUUID, NotificationType.EXPIRED, message, listing.id);
// Log the expiration
AuctionLogger.logAuctionExpired(listing);
}
/**
* Notify player their auction was cancelled
*/
public void notifyAuctionCancelled(AuctionListing listing, boolean byAdmin) {
String message;
if (byAdmin) {
message = EnumChatFormatting.YELLOW + "[Auction] " + EnumChatFormatting.RED +
"Your auction for " + EnumChatFormatting.WHITE + listing.item.getDisplayName() +
EnumChatFormatting.RED + " was cancelled by an administrator.";
} else {
message = EnumChatFormatting.YELLOW + "[Auction] " + EnumChatFormatting.GRAY +
"You cancelled your auction for " + EnumChatFormatting.WHITE +
listing.item.getDisplayName() + EnumChatFormatting.GRAY + ".";
}
sendOrQueueNotification(listing.sellerUUID, NotificationType.CANCELLED, message, listing.id);
// Log the cancellation
AuctionLogger.logAuctionCancelled(listing, byAdmin);
}
/**
* Notify about a new bid placed
*/
public void notifyNewBid(AuctionListing listing, String bidderName, long bidAmount) {
// Notify seller about new bid
String sellerMessage = EnumChatFormatting.YELLOW + "[Auction] " + EnumChatFormatting.AQUA +
bidderName + " placed a bid of " + formatCurrency(bidAmount) +
" on your " + listing.item.getDisplayName() + "!";
sendOrQueueNotification(listing.sellerUUID, NotificationType.NEW_BID, sellerMessage, listing.id);
// Log the bid
AuctionLogger.logBidPlaced(listing, bidderName, bidAmount);
}
/**
* Send notification immediately if player online, otherwise queue for later
*/
private void sendOrQueueNotification(UUID playerUUID, NotificationType type, String message, int listingId) {
EntityPlayerMP player = getOnlinePlayer(playerUUID);
if (player != null) {
player.addChatMessage(new ChatComponentText(message));
} else {
// Queue for when player logs in
AuctionNotification notification = new AuctionNotification(type, message, listingId);
if (!pendingNotifications.containsKey(playerUUID)) {
pendingNotifications.put(playerUUID, new ArrayList<>());
}
pendingNotifications.get(playerUUID).add(notification);
// Limit queue size per player
List<AuctionNotification> queue = pendingNotifications.get(playerUUID);
while (queue.size() > 50) {
queue.remove(0);
}
}
}
/**
* Called when a player logs in - send any pending notifications
*/
public void onPlayerLogin(EntityPlayerMP player) {
UUID uuid = player.getUniqueID();
if (pendingNotifications.containsKey(uuid)) {
List<AuctionNotification> notifications = pendingNotifications.remove(uuid);
if (!notifications.isEmpty()) {
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.YELLOW + "[Auction] " + EnumChatFormatting.WHITE +
"You have " + notifications.size() + " auction notification(s):"));
for (AuctionNotification notification : notifications) {
player.addChatMessage(new ChatComponentText(notification.message));
}
}
}
// Also check for claimable items
if (AuctionController.Instance != null) {
int claimableCount = AuctionController.Instance.getClaimableListings(uuid).size();
if (claimableCount > 0) {
player.addChatMessage(new ChatComponentText(
EnumChatFormatting.YELLOW + "[Auction] " + EnumChatFormatting.GREEN +
"You have " + claimableCount + " item(s) waiting to be claimed!"));
}
}
}
private EntityPlayerMP getOnlinePlayer(UUID uuid) {
if (noppes.npcs.CustomNpcs.getServer() == null) return null;
for (Object obj : noppes.npcs.CustomNpcs.getServer().getConfigurationManager().playerEntityList) {
EntityPlayerMP player = (EntityPlayerMP) obj;
if (player.getUniqueID().equals(uuid)) {
return player;
}
}
return null;
}
private String formatCurrency(long amount) {
return String.format("%,d %s", amount, ConfigMarket.CurrencyName);
}
/**
* Notification types for categorization
*/
public enum NotificationType {
OUTBID,
WON,
SOLD,
EXPIRED,
CANCELLED,
NEW_BID
}
/**
* Stored notification for offline players
*/
private static class AuctionNotification {
public final NotificationType type;
public final String message;
public final int listingId;
public final long timestamp;
public AuctionNotification(NotificationType type, String message, int listingId) {
this.type = type;
this.message = message;
this.listingId = listingId;
this.timestamp = System.currentTimeMillis();
}
}
}
@@ -1,7 +1,6 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.constants.EnumAuctionCategory;
import noppes.npcs.constants.EnumAuctionSort;
/**
@@ -13,9 +12,6 @@ public class AuctionFilter {
/** Search text to match against item names */
public String searchText = "";
/** Category to filter by (ALL for no category filter) */
public EnumAuctionCategory category = EnumAuctionCategory.ALL;
/** How to sort results */
public EnumAuctionSort sortOrder = EnumAuctionSort.ENDING_SOON;
@@ -55,15 +51,6 @@ public class AuctionFilter {
return filter;
}
/**
* Create a filter with category
*/
public static AuctionFilter category(EnumAuctionCategory category) {
AuctionFilter filter = new AuctionFilter();
filter.category = category;
return filter;
}
/**
* Create a filter for a specific seller
*/
@@ -80,11 +67,6 @@ public class AuctionFilter {
return this;
}
public AuctionFilter withCategory(EnumAuctionCategory category) {
this.category = category;
return this;
}
public AuctionFilter withSort(EnumAuctionSort sort) {
this.sortOrder = sort;
return this;
@@ -135,11 +117,6 @@ public class AuctionFilter {
}
}
// Category filter
if (category != EnumAuctionCategory.ALL && listing.category != category) {
return false;
}
// Price range filter (uses current bid or starting price)
long price = listing.currentBid > 0 ? listing.currentBid : listing.startingPrice;
if (minPrice > 0 && price < minPrice) {
@@ -180,7 +157,6 @@ public class AuctionFilter {
*/
public void reset() {
searchText = "";
category = EnumAuctionCategory.ALL;
sortOrder = EnumAuctionSort.ENDING_SOON;
minPrice = 0;
maxPrice = 0;
@@ -196,7 +172,6 @@ public class AuctionFilter {
*/
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setString("SearchText", searchText);
compound.setInteger("Category", category.ordinal());
compound.setInteger("SortOrder", sortOrder.ordinal());
compound.setLong("MinPrice", minPrice);
compound.setLong("MaxPrice", maxPrice);
@@ -215,11 +190,6 @@ public class AuctionFilter {
public void readFromNBT(NBTTagCompound compound) {
searchText = compound.getString("SearchText");
int catOrdinal = compound.getInteger("Category");
if (catOrdinal >= 0 && catOrdinal < EnumAuctionCategory.values().length) {
category = EnumAuctionCategory.values()[catOrdinal];
}
int sortOrdinal = compound.getInteger("SortOrder");
if (sortOrdinal >= 0 && sortOrdinal < EnumAuctionSort.values().length) {
sortOrder = EnumAuctionSort.values()[sortOrdinal];
@@ -240,7 +210,6 @@ public class AuctionFilter {
public String toString() {
return "AuctionFilter{" +
"search='" + searchText + '\'' +
", category=" + category +
", sort=" + sortOrder +
", price=" + minPrice + "-" + maxPrice +
", buyoutOnly=" + buyoutOnly +
@@ -4,7 +4,6 @@ import kamkeel.npcs.controllers.data.attribute.ItemTradeAttribute;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.config.ConfigMarket;
import noppes.npcs.constants.EnumAuctionCategory;
import noppes.npcs.constants.EnumAuctionDuration;
import noppes.npcs.constants.EnumAuctionStatus;
import noppes.npcs.controllers.AuctionBlacklist;
@@ -48,9 +47,6 @@ public class AuctionListing {
// Status
public EnumAuctionStatus status = EnumAuctionStatus.ACTIVE;
// Category for filtering
public EnumAuctionCategory category = EnumAuctionCategory.MISC;
// Claim tracking
public boolean sellerClaimed = false; // Has seller claimed their proceeds?
public boolean buyerClaimed = false; // Has buyer claimed their item?
@@ -87,7 +83,6 @@ public class AuctionListing {
this.duration = duration;
this.listingTime = System.currentTimeMillis();
this.expirationTime = listingTime + duration.getMillis();
this.category = EnumAuctionCategory.categorize(item);
this.status = EnumAuctionStatus.ACTIVE;
}
@@ -351,7 +346,6 @@ public class AuctionListing {
compound.setLong("ExpirationTime", expirationTime);
compound.setInteger("Duration", duration.ordinal());
compound.setInteger("Status", status.ordinal());
compound.setInteger("Category", category.ordinal());
compound.setBoolean("SellerClaimed", sellerClaimed);
compound.setBoolean("BuyerClaimed", buyerClaimed);
compound.setInteger("BidCount", bidCount);
@@ -396,13 +390,6 @@ public class AuctionListing {
status = EnumAuctionStatus.ACTIVE;
}
int categoryOrdinal = compound.getInteger("Category");
if (categoryOrdinal >= 0 && categoryOrdinal < EnumAuctionCategory.values().length) {
category = EnumAuctionCategory.values()[categoryOrdinal];
} else {
category = EnumAuctionCategory.MISC;
}
sellerClaimed = compound.getBoolean("SellerClaimed");
buyerClaimed = compound.getBoolean("BuyerClaimed");
bidCount = compound.getInteger("BidCount");