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

@@ -12,6 +12,7 @@ import net.minecraft.util.StatCollector;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import noppes.npcs.client.AuctionClientConfig;
import noppes.npcs.constants.EnumClaimType;
import noppes.npcs.util.AuctionFormatUtil;
import noppes.npcs.containers.ContainerAuctionListing;
import noppes.npcs.containers.ContainerAuctionSell;
import noppes.npcs.containers.ContainerAuctionTrades;
@@ -88,25 +89,25 @@ public class AuctionTooltipHandler {
// Current bid or starting price
if (listing.hasBids()) {
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.currentBid")
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(listing.currentBid)));
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(listing.currentBid)));
tooltip.add(EnumChatFormatting.GRAY + String.format(StatCollector.translateToLocal("auction.bids"), listing.bidCount));
} else {
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.startingPrice")
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(listing.startingPrice)));
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(listing.startingPrice)));
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.noBids"));
}
// Buyout price
if (listing.hasBuyout()) {
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.buyout")
.replace("%s", EnumChatFormatting.GREEN + formatCurrency(listing.buyoutPrice)));
.replace("%s", EnumChatFormatting.GREEN + AuctionFormatUtil.formatCurrencyWithName(listing.buyoutPrice)));
}
// Time remaining
long timeRemaining = listing.getTimeRemaining();
String timeText = StatCollector.translateToLocal("auction.timeLeft")
.replace("%s", formatTimeRemaining(timeRemaining));
tooltip.add((timeRemaining < 3600000 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
.replace("%s", AuctionFormatUtil.formatTimeRemaining(timeRemaining));
tooltip.add((AuctionFormatUtil.isTimeUrgent(timeRemaining) ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
}
// ========== Trades Page ==========
@@ -144,7 +145,7 @@ public class AuctionTooltipHandler {
if (listing.hasBids()) {
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.currentBid")
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(listing.currentBid)));
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(listing.currentBid)));
tooltip.add(EnumChatFormatting.GRAY + String.format(StatCollector.translateToLocal("auction.bids"), listing.bidCount));
} else {
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.noBids"));
@@ -152,8 +153,8 @@ public class AuctionTooltipHandler {
long timeRemaining = listing.getTimeRemaining();
String timeText = StatCollector.translateToLocal("auction.timeLeft")
.replace("%s", formatTimeRemaining(timeRemaining));
tooltip.add((timeRemaining < 3600000 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
.replace("%s", AuctionFormatUtil.formatTimeRemaining(timeRemaining));
tooltip.add((AuctionFormatUtil.isTimeUrgent(timeRemaining) ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
tooltip.add("");
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.trades.rightClickToCancel"));
@@ -164,13 +165,13 @@ public class AuctionTooltipHandler {
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.trades.bidding"));
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.currentBid")
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(listing.currentBid)));
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(listing.currentBid)));
tooltip.add(EnumChatFormatting.GRAY + String.format(StatCollector.translateToLocal("auction.bids"), listing.bidCount));
long timeRemaining = listing.getTimeRemaining();
String timeText = StatCollector.translateToLocal("auction.timeLeft")
.replace("%s", formatTimeRemaining(timeRemaining));
tooltip.add((timeRemaining < 3600000 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
.replace("%s", AuctionFormatUtil.formatTimeRemaining(timeRemaining));
tooltip.add((AuctionFormatUtil.isTimeUrgent(timeRemaining) ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
tooltip.add("");
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.trades.clickToRebid"));
@@ -210,7 +211,7 @@ public class AuctionTooltipHandler {
// Amount for currency claims
if (claim.type.isCurrency()) {
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.claim.amount")
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(claim.currency)));
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(claim.currency)));
}
// Expiration
@@ -254,48 +255,4 @@ public class AuctionTooltipHandler {
}
}
// ========== Formatting Utilities ==========
private static String formatCurrency(long amount) {
if (amount < 1000) {
return amount + " " + AuctionClientConfig.getCurrencyName();
}
StringBuilder sb = new StringBuilder();
String str = "" + amount;
int count = 0;
for (int i = str.length() - 1; i >= 0; i--) {
if (count > 0 && count % 3 == 0) {
sb.insert(0, ',');
}
sb.insert(0, str.charAt(i));
count++;
}
return sb.toString() + " " + AuctionClientConfig.getCurrencyName();
}
private static String formatTimeRemaining(long milliseconds) {
if (milliseconds <= 0) {
return StatCollector.translateToLocal("auction.ended");
}
long seconds = (milliseconds / 1000) % 60;
long minutes = (milliseconds / 60000) % 60;
long hours = (milliseconds / 3600000) % 24;
long days = milliseconds / 86400000;
StringBuilder sb = new StringBuilder();
if (days > 0) {
sb.append(days).append("d ");
}
if (hours > 0 || days > 0) {
sb.append(hours).append("h ");
}
if (minutes > 0 || hours > 0 || days > 0) {
sb.append(minutes).append("m");
} else {
sb.append(seconds).append("s");
}
return sb.toString();
}
}
@@ -15,6 +15,7 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.containers.ContainerAuctionBidding;
import noppes.npcs.controllers.data.AuctionListing;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.util.AuctionFormatUtil;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
@@ -36,7 +37,7 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
private int btnBidY = 110;
private int btnBuyoutX = 82;
private int btnBuyoutY = 110;
private int infoX = 110;
private int infoX = 105;
private int infoY = 50;
// Button IDs
@@ -186,7 +187,7 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
/** Draw auction listing information on the right side */
private void drawAuctionInfo() {
int x = guiLeft + 105;
int x = guiLeft + infoX;
int y = guiTop + infoY;
int xRight = guiLeft + 215;
@@ -206,7 +207,7 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
String bidLabel = StatCollector.translateToLocal("auction.info.currentBid") + ":";
fontRendererObj.drawString(EnumChatFormatting.YELLOW + bidLabel, x, y, 0xFFFFFF);
label = formatCurrency(listing.currentBid);
label = AuctionFormatUtil.formatCurrency(listing.currentBid);
length = fontRendererObj.getStringWidth(label);
fontRendererObj.drawString(EnumChatFormatting.GOLD + label, xRight - length, y, 0xFFFFFF);
y += lineHeight + 4;
@@ -223,7 +224,7 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
String startLabel = StatCollector.translateToLocal("auction.info.startingPrice");
fontRendererObj.drawString(EnumChatFormatting.YELLOW + startLabel, x, y, 0xFFFFFF);
label = formatCurrency(listing.startingPrice);
label = AuctionFormatUtil.formatCurrency(listing.startingPrice);
length = fontRendererObj.getStringWidth(label);
fontRendererObj.drawString(EnumChatFormatting.GOLD + label, xRight - length, y, 0xFFFFFF);
y += lineHeight + 4;
@@ -234,7 +235,7 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
String buyoutLabel = StatCollector.translateToLocal("auction.info.buyoutPrice");
fontRendererObj.drawString(EnumChatFormatting.GREEN + buyoutLabel, x, y, 0xFFFFFF);
label = formatCurrency(listing.buyoutPrice);
label = AuctionFormatUtil.formatCurrency(listing.buyoutPrice);
length = fontRendererObj.getStringWidth(label);
fontRendererObj.drawString(EnumChatFormatting.GREEN + label, xRight - length, y, 0xFFFFFF);
y += lineHeight + 4;
@@ -244,9 +245,9 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
String timeLabel = StatCollector.translateToLocal("auction.info.timeLeft");
fontRendererObj.drawString(EnumChatFormatting.GRAY + timeLabel, x, y, 0xFFFFFF);
long timeRemaining = listing.getTimeRemaining();
EnumChatFormatting timeColor = timeRemaining < 3600000 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE;
EnumChatFormatting timeColor = AuctionFormatUtil.isTimeUrgent(timeRemaining) ? EnumChatFormatting.RED : EnumChatFormatting.WHITE;
label = timeColor + formatTimeRemaining(timeRemaining);
label = timeColor + AuctionFormatUtil.formatTimeRemaining(timeRemaining);
length = fontRendererObj.getStringWidth(label);
fontRendererObj.drawString(label, xRight - length, y, 0xFFFFFF);
y += lineHeight + 4;
@@ -278,14 +279,14 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
if (listing != null) {
long minBid = listing.getMinimumBid(AuctionClientConfig.getMinBidIncrement());
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.bid.minimum")
.replace("%s", EnumChatFormatting.WHITE + formatCurrency(minBid) + " " + AuctionClientConfig.getCurrencyName()));
.replace("%s", EnumChatFormatting.WHITE + AuctionFormatUtil.formatCurrency(minBid) + " " + AuctionClientConfig.getCurrencyName()));
}
} else if (btnBuyout != null && btnBuyout.visible && btnBuyout.isHovered()) {
tooltip = new ArrayList<>();
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.bid.buyout"));
if (listing != null && listing.hasBuyout()) {
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.info.buyoutPrice") + ":");
tooltip.add(EnumChatFormatting.GREEN + formatCurrency(listing.buyoutPrice) + " " + AuctionClientConfig.getCurrencyName());
tooltip.add(EnumChatFormatting.GREEN + AuctionFormatUtil.formatCurrency(listing.buyoutPrice) + " " + AuctionClientConfig.getCurrencyName());
}
}
@@ -34,6 +34,9 @@ public abstract class GuiAuctionInterface extends GuiContainerNPCInterface {
public static final int PAGE_SELL = 1;
public static final int PAGE_CLAIMS = 2;
// Overlay color
protected static final int OVERLAY_DARK = 0xC0000000;
// Navigation button IDs
protected static final int BTN_NAV_LISTINGS = 100;
protected static final int BTN_NAV_SELL = 101;
@@ -172,7 +175,7 @@ public abstract class GuiAuctionInterface extends GuiContainerNPCInterface {
/** Draw dark overlay for unavailable slots */
protected void drawDarkenedOverlay(int x, int y) {
drawColoredOverlay(x, y, 0xC0000000);
drawColoredOverlay(x, y, OVERLAY_DARK);
}
/** Draw icon texture on slot (16x16) */
@@ -192,39 +195,6 @@ public abstract class GuiAuctionInterface extends GuiContainerNPCInterface {
/** Subclasses implement this to draw specific content */
protected abstract void drawAuctionContent(float partialTicks, int mouseX, int mouseY);
// ========== Formatting Utilities ==========
/** Format currency with commas (e.g., 1000 -> "1,000") */
protected String formatCurrency(long amount) {
if (amount < 1000) return "" + amount;
StringBuilder sb = new StringBuilder();
String str = "" + amount;
int count = 0;
for (int i = str.length() - 1; i >= 0; i--) {
if (count > 0 && count % 3 == 0) sb.insert(0, ',');
sb.insert(0, str.charAt(i));
count++;
}
return sb.toString();
}
/** Format time remaining (e.g., "2d 5h 30m") */
protected String formatTimeRemaining(long ms) {
if (ms <= 0) return "Ended";
long seconds = (ms / 1000) % 60;
long minutes = (ms / 60000) % 60;
long hours = (ms / 3600000) % 24;
long days = ms / 86400000;
StringBuilder sb = new StringBuilder();
if (days > 0) sb.append(days).append("d ");
if (hours > 0 || days > 0) sb.append(hours).append("h ");
if (minutes > 0 || hours > 0 || days > 0) sb.append(minutes).append("m");
else sb.append(seconds).append("s");
return sb.toString();
}
@Override
public void save() {
// Override in subclasses if needed
@@ -58,8 +58,6 @@ public class GuiAuctionListing extends GuiAuctionInterface implements ISubGuiLis
private AuctionFilter filter;
private int currentPage = 0;
private int totalPages = 1;
private int totalListings = 0;
private boolean dataLoaded = false;
// Buttons defined on this page
private GuiAuctionNavButton btnFilter;
@@ -204,7 +202,6 @@ public class GuiAuctionListing extends GuiAuctionInterface implements ISubGuiLis
if (compound.hasKey("ListingsData")) {
currentPage = compound.getInteger("Page");
totalPages = compound.getInteger("TotalPages");
totalListings = compound.getInteger("TotalListings");
// Load listings
listingContainer.displayInventory.clear();
@@ -213,7 +210,7 @@ public class GuiAuctionListing extends GuiAuctionInterface implements ISubGuiLis
AuctionListing listing = AuctionListing.fromNBT(list.getCompoundTagAt(i));
listingContainer.displayInventory.setListing(i, listing);
}
dataLoaded = true;
updatePaginationVisibility();
} else if (compound.hasKey("ListingsRefresh")) {
requestListings();
}
@@ -15,7 +15,9 @@ import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.ITextfieldListener;
import noppes.npcs.client.AuctionClientConfig;
import noppes.npcs.containers.ContainerAuctionSell;
import noppes.npcs.util.AuctionFormatUtil;
import noppes.npcs.entity.EntityNPCInterface;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.List;
@@ -239,7 +241,7 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
// Draw listing fee info (uses cached config from server)
String feeText = StatCollector.translateToLocal("auction.sell.fee")
.replace("%s", formatCurrency(AuctionClientConfig.getListingFee()) + " " + AuctionClientConfig.getCurrencyName());
.replace("%s", AuctionFormatUtil.formatCurrency(AuctionClientConfig.getListingFee()) + " " + AuctionClientConfig.getCurrencyName());
fontRendererObj.drawString(EnumChatFormatting.GRAY + feeText, guiLeft + contentX, guiTop + contentY + 77, 0xFFFFFF);
// Draw error message if any
@@ -326,7 +328,11 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
}
if (tooltip != null && !tooltip.isEmpty()) {
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
drawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj);
GL11.glPopAttrib();
GL11.glPopMatrix();
}
}
}
@@ -10,6 +10,7 @@ import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.ITextfieldListener;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.util.AuctionFormatUtil;
/**
* Sub GUI for placing a bid on an auction.
@@ -49,13 +50,13 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
// Minimum bid info
String minText = StatCollector.translateToLocal("auction.bid.minimum")
.replace("%s", EnumChatFormatting.DARK_RED + formatCurrency(minimumBid) + " " + currencyName);
.replace("%s", EnumChatFormatting.DARK_RED + AuctionFormatUtil.formatCurrency(minimumBid) + " " + currencyName);
addLabel(new GuiNpcLabel(1, minText, guiLeft + 15, y));
y += 14;
// Your balance
String balanceText = StatCollector.translateToLocal("auction.bid.yourBalance")
.replace("%s", EnumChatFormatting.DARK_GREEN + formatCurrency(playerBalance) + " " + currencyName);
.replace("%s", EnumChatFormatting.DARK_GREEN + AuctionFormatUtil.formatCurrency(playerBalance) + " " + currencyName);
addLabel(new GuiNpcLabel(2, balanceText, guiLeft + 15, y));
y += 18;
@@ -117,7 +118,7 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
// Validate
if (bidAmount < minimumBid) {
errorMessage = StatCollector.translateToLocal("auction.error.bidTooLow")
.replace("%s", formatCurrency(minimumBid));
.replace("%s", AuctionFormatUtil.formatCurrency(minimumBid));
updateErrorLabel();
return;
}
@@ -144,17 +145,4 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
public boolean wasSuccessful() {
return successful;
}
private String formatCurrency(long amount) {
if (amount < 1000) return "" + amount;
StringBuilder sb = new StringBuilder();
String str = "" + amount;
int count = 0;
for (int i = str.length() - 1; i >= 0; i--) {
if (count > 0 && count % 3 == 0) sb.insert(0, ',');
sb.insert(0, str.charAt(i));
count++;
}
return sb.toString();
}
}
@@ -8,6 +8,7 @@ import noppes.npcs.client.AuctionClientConfig;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.util.AuctionFormatUtil;
/**
* Sub GUI for confirming a buyout purchase.
@@ -54,14 +55,14 @@ public class SubGuiAuctionBuyNow extends SubGuiInterface {
y += 16;
// Buyout price
String priceText = EnumChatFormatting.DARK_RED + formatCurrency(buyoutPrice) + " " + currencyName;
String priceText = EnumChatFormatting.DARK_RED + AuctionFormatUtil.formatCurrency(buyoutPrice) + " " + currencyName;
int priceWidth = fontRendererObj.getStringWidth(priceText);
addLabel(new GuiNpcLabel(2, priceText, centerX - priceWidth / 2, y));
y += 20;
// Your balance
String balanceLabel = StatCollector.translateToLocal("auction.bid.yourBalance");
String balanceText = balanceLabel.replace("%s", EnumChatFormatting.DARK_GREEN + formatCurrency(playerBalance) + " " + currencyName);
String balanceText = balanceLabel.replace("%s", EnumChatFormatting.DARK_GREEN + AuctionFormatUtil.formatCurrency(playerBalance) + " " + currencyName);
addLabel(new GuiNpcLabel(3, balanceText, guiLeft + 20, y));
y += 14;
@@ -105,17 +106,4 @@ public class SubGuiAuctionBuyNow extends SubGuiInterface {
public boolean wasSuccessful() {
return successful;
}
private String formatCurrency(long amount) {
if (amount < 1000) return "" + amount;
StringBuilder sb = new StringBuilder();
String str = "" + amount;
int count = 0;
for (int i = str.length() - 1; i >= 0; i--) {
if (count > 0 && count % 3 == 0) sb.insert(0, ',');
sb.insert(0, str.charAt(i));
count++;
}
return sb.toString();
}
}