mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 18:49:39 +00:00
Implement Phase 6: GUI components, notifications, and logging system
Add auction GUI components: - GuiAuction: Main auction browse interface with search, categories, sorting, pagination, and live countdown timers - SubGuiAuctionBid: Bid placement dialog with quick bid buttons - SubGuiAuctionCreate: Listing creation form with duration options - SubGuiAuctionDetails: Item details view with 2x scaled rendering - ContainerAuction: Container class for auction GUI inventory Add notification system: - AuctionNotificationController: Handles real-time notifications - Supports outbid, won, sold, expired, cancelled events - Queues notifications for offline players - Sends pending notifications on player login Add auction logging: - AuctionLogger: Comprehensive logging to CNPC+ log system - Logs all auction events (create, bid, buyout, expire, claim) - Includes system startup and processing tick logs - Admin action tracking Integrate with existing systems: - Initialize AuctionNotificationController on server start - Hook player login for notification delivery - Add logging calls to all AuctionController methods
This commit is contained in:
10 files changed
+1845
-4
No files matched your search
@@ -62,6 +62,7 @@ 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;
|
||||
@@ -312,6 +313,7 @@ public class CustomNpcs {
|
||||
new CurrencyController();
|
||||
new AuctionBlacklist();
|
||||
new AuctionController();
|
||||
new AuctionNotificationController();
|
||||
RecipeController.Instance.load();
|
||||
new BankController();
|
||||
DialogController.Instance.load();
|
||||
|
||||
@@ -10,6 +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.data.PlayerData;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.controllers.data.action.ActionManager;
|
||||
@@ -65,6 +66,11 @@ public class ServerTickHandler {
|
||||
ProfileController.Instance.login(player);
|
||||
SyncController.beginLogin(player);
|
||||
SyncController.syncEffects(player);
|
||||
|
||||
// Send pending auction notifications
|
||||
if (AuctionNotificationController.Instance != null) {
|
||||
AuctionNotificationController.Instance.onPlayerLogin(player);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -0,0 +1,489 @@
|
||||
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 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;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Main auction house browse GUI.
|
||||
* Displays listings with search, filter, 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;
|
||||
|
||||
// Current state
|
||||
private AuctionFilter currentFilter = new AuctionFilter();
|
||||
private List<AuctionListing> listings = new ArrayList<>();
|
||||
private int totalResults = 0;
|
||||
private int currentPage = 0;
|
||||
private int totalPages = 0;
|
||||
private long playerBalance = 0;
|
||||
|
||||
// Tab state (0=Browse, 1=My Listings, 2=My Bids, 3=Claims, 4=Create)
|
||||
private int currentTab = 0;
|
||||
|
||||
// Selected listing for details
|
||||
private int selectedListingIndex = -1;
|
||||
|
||||
// Countdown update timer
|
||||
private long lastCountdownUpdate = 0;
|
||||
|
||||
public GuiAuction(EntityNPCInterface npc, ContainerAuction container) {
|
||||
super(npc, container);
|
||||
this.title = "Auction House";
|
||||
this.xSize = 256;
|
||||
this.ySize = 222;
|
||||
this.closeOnEsc = true;
|
||||
this.drawDefaultBackground = true;
|
||||
|
||||
// Request initial data
|
||||
AuctionActionPacket.QueryListings(currentFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
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"));
|
||||
getTopButton(currentTab).setEnabled(false);
|
||||
|
||||
// Search field
|
||||
searchField = new GuiNpcTextField(10, this, guiLeft + 8, guiTop + 6, 120, 14, currentFilter.searchText);
|
||||
searchField.setMaxStringLength(50);
|
||||
addTextField(searchField);
|
||||
|
||||
// Search button
|
||||
addButton(new GuiNpcButton(11, guiLeft + 130, guiTop + 5, 30, 16, "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()));
|
||||
|
||||
// Listing scroll area
|
||||
listingScroll = new GuiCustomScroll(this, 0);
|
||||
listingScroll.guiLeft = guiLeft + 8;
|
||||
listingScroll.guiTop = guiTop + 42;
|
||||
listingScroll.setSize(160, 130);
|
||||
addScroll(listingScroll);
|
||||
updateListingDisplay();
|
||||
|
||||
// Pagination buttons
|
||||
addButton(new GuiNpcButton(40, guiLeft + 8, guiTop + 176, 40, 16, "< Prev"));
|
||||
addLabel(new GuiNpcLabel(41, getPageLabel(), guiLeft + 90, guiTop + 180, CustomNpcResourceListener.DefaultTextColor));
|
||||
addButton(new GuiNpcButton(42, guiLeft + 128, guiTop + 176, 40, 16, "Next >"));
|
||||
|
||||
// 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"));
|
||||
|
||||
// Balance display
|
||||
addLabel(new GuiNpcLabel(60, "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();
|
||||
|
||||
// Update countdowns every second
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastCountdownUpdate >= 1000) {
|
||||
lastCountdownUpdate = now;
|
||||
updateListingDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
super.actionPerformed(button);
|
||||
int id = button.id;
|
||||
|
||||
// Tab buttons
|
||||
if (id >= 0 && id <= 4) {
|
||||
switchTab(id);
|
||||
}
|
||||
// Search button
|
||||
else if (id == 11) {
|
||||
performSearch();
|
||||
}
|
||||
// Category buttons
|
||||
else if (id >= 20 && id <= 26) {
|
||||
setCategory(getCategoryOrdinal(id - 20));
|
||||
}
|
||||
// Sort button
|
||||
else if (id == 30) {
|
||||
cycleSortOrder();
|
||||
}
|
||||
// Pagination
|
||||
else if (id == 40) {
|
||||
previousPage();
|
||||
} else if (id == 42) {
|
||||
nextPage();
|
||||
}
|
||||
// Actions
|
||||
else if (id == 50) {
|
||||
viewDetails();
|
||||
} else if (id == 51) {
|
||||
placeBid();
|
||||
} else if (id == 52) {
|
||||
buyout();
|
||||
} else if (id == 53) {
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void switchTab(int tab) {
|
||||
currentTab = tab;
|
||||
currentPage = 0;
|
||||
|
||||
switch (tab) {
|
||||
case 0: // Browse
|
||||
AuctionActionPacket.QueryListings(currentFilter);
|
||||
break;
|
||||
case 1: // My Listings
|
||||
AuctionActionPacket.QueryMyListings();
|
||||
break;
|
||||
case 2: // My Bids
|
||||
AuctionActionPacket.QueryMyBids();
|
||||
break;
|
||||
case 3: // Claims
|
||||
AuctionActionPacket.QueryClaimable();
|
||||
break;
|
||||
case 4: // Create - open sub GUI
|
||||
setSubGui(new SubGuiAuctionCreate(this, (ContainerAuction) inventorySlots));
|
||||
break;
|
||||
}
|
||||
|
||||
initGui();
|
||||
}
|
||||
|
||||
private void performSearch() {
|
||||
currentFilter.searchText = searchField.getText();
|
||||
currentFilter.page = 0;
|
||||
currentPage = 0;
|
||||
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;
|
||||
currentPage = 0;
|
||||
AuctionActionPacket.QueryListings(currentFilter);
|
||||
initGui();
|
||||
}
|
||||
|
||||
private void previousPage() {
|
||||
if (currentPage > 0) {
|
||||
currentPage--;
|
||||
currentFilter.page = currentPage;
|
||||
AuctionActionPacket.QueryListings(currentFilter);
|
||||
}
|
||||
}
|
||||
|
||||
private void nextPage() {
|
||||
if (currentPage < totalPages - 1) {
|
||||
currentPage++;
|
||||
currentFilter.page = currentPage;
|
||||
AuctionActionPacket.QueryListings(currentFilter);
|
||||
}
|
||||
}
|
||||
|
||||
private void viewDetails() {
|
||||
if (selectedListingIndex >= 0 && selectedListingIndex < listings.size()) {
|
||||
AuctionListing listing = listings.get(selectedListingIndex);
|
||||
setSubGui(new SubGuiAuctionDetails(this, listing));
|
||||
}
|
||||
}
|
||||
|
||||
private void placeBid() {
|
||||
if (selectedListingIndex >= 0 && selectedListingIndex < listings.size()) {
|
||||
AuctionListing listing = listings.get(selectedListingIndex);
|
||||
setSubGui(new SubGuiAuctionBid(this, listing, playerBalance));
|
||||
}
|
||||
}
|
||||
|
||||
private void buyout() {
|
||||
if (selectedListingIndex >= 0 && selectedListingIndex < listings.size()) {
|
||||
AuctionListing listing = listings.get(selectedListingIndex);
|
||||
if (listing.buyoutPrice > 0 && playerBalance >= listing.buyoutPrice) {
|
||||
AuctionActionPacket.Buyout(listing.id);
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
switch (currentTab) {
|
||||
case 0:
|
||||
AuctionActionPacket.QueryListings(currentFilter);
|
||||
break;
|
||||
case 1:
|
||||
AuctionActionPacket.QueryMyListings();
|
||||
break;
|
||||
case 2:
|
||||
AuctionActionPacket.QueryMyBids();
|
||||
break;
|
||||
case 3:
|
||||
AuctionActionPacket.QueryClaimable();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateListingDisplay() {
|
||||
if (listingScroll == null) return;
|
||||
|
||||
List<String> displayList = new ArrayList<>();
|
||||
for (AuctionListing listing : listings) {
|
||||
String line = formatListingLine(listing);
|
||||
displayList.add(line);
|
||||
}
|
||||
listingScroll.setList(displayList);
|
||||
|
||||
if (selectedListingIndex >= 0 && selectedListingIndex < displayList.size()) {
|
||||
listingScroll.selected = selectedListingIndex;
|
||||
}
|
||||
}
|
||||
|
||||
private String formatListingLine(AuctionListing listing) {
|
||||
String itemName = listing.item.getDisplayName();
|
||||
if (itemName.length() > 15) {
|
||||
itemName = itemName.substring(0, 12) + "...";
|
||||
}
|
||||
|
||||
long price = listing.currentBid > 0 ? listing.currentBid : listing.startingPrice;
|
||||
String priceStr = formatCurrency(price);
|
||||
|
||||
String timeStr = formatTimeRemaining(listing.getTimeRemaining());
|
||||
|
||||
return String.format("%s - %s (%s)", itemName, priceStr, timeStr);
|
||||
}
|
||||
|
||||
private String formatTimeRemaining(long millis) {
|
||||
if (millis <= 0) return "Ended";
|
||||
|
||||
long seconds = millis / 1000;
|
||||
long minutes = seconds / 60;
|
||||
long hours = minutes / 60;
|
||||
long days = hours / 24;
|
||||
|
||||
if (days > 0) {
|
||||
return days + "d " + (hours % 24) + "h";
|
||||
} else if (hours > 0) {
|
||||
return hours + "h " + (minutes % 60) + "m";
|
||||
} else if (minutes > 0) {
|
||||
return minutes + "m " + (seconds % 60) + "s";
|
||||
} else {
|
||||
return seconds + "s";
|
||||
}
|
||||
}
|
||||
|
||||
private String formatCurrency(long amount) {
|
||||
if (amount >= 1000000) {
|
||||
return String.format("%.1fM", amount / 1000000.0);
|
||||
} else if (amount >= 1000) {
|
||||
return String.format("%.1fK", amount / 1000.0);
|
||||
}
|
||||
return String.valueOf(amount);
|
||||
}
|
||||
|
||||
private String getPageLabel() {
|
||||
if (totalPages == 0) {
|
||||
return "No results";
|
||||
}
|
||||
return "Page " + (currentPage + 1) + " of " + totalPages;
|
||||
}
|
||||
|
||||
private void updateButtonStates() {
|
||||
// Pagination buttons
|
||||
if (getButton(40) != null) getButton(40).setEnabled(currentPage > 0);
|
||||
if (getButton(42) != null) getButton(42).setEnabled(currentPage < totalPages - 1);
|
||||
|
||||
// Action buttons based on selection
|
||||
boolean hasSelection = selectedListingIndex >= 0 && selectedListingIndex < listings.size();
|
||||
if (getButton(50) != null) getButton(50).setEnabled(hasSelection);
|
||||
if (getButton(51) != null) getButton(51).setEnabled(hasSelection);
|
||||
|
||||
if (hasSelection && getButton(52) != null) {
|
||||
AuctionListing listing = listings.get(selectedListingIndex);
|
||||
getButton(52).setEnabled(listing.buyoutPrice > 0 && playerBalance >= listing.buyoutPrice);
|
||||
} else if (getButton(52) != null) {
|
||||
getButton(52).setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
drawDefaultBackground();
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
// Draw background (using a standard size, can be customized)
|
||||
mc.renderEngine.bindTexture(new ResourceLocation("customnpcs", "textures/gui/bgfilled.png"));
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
// Draw selected item preview
|
||||
if (selectedListingIndex >= 0 && selectedListingIndex < listings.size()) {
|
||||
AuctionListing listing = listings.get(selectedListingIndex);
|
||||
drawItemPreview(listing, guiLeft + 180, guiTop + 160);
|
||||
}
|
||||
|
||||
super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
|
||||
}
|
||||
|
||||
private void drawItemPreview(AuctionListing listing, int x, int y) {
|
||||
if (listing == null || listing.item == null) return;
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, listing.item, x, y);
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, listing.item, x, y);
|
||||
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
// Title
|
||||
String titleText = getTabTitle();
|
||||
fontRendererObj.drawString(titleText, (xSize - fontRendererObj.getStringWidth(titleText)) / 2, -8,
|
||||
CustomNpcResourceListener.DefaultTextColor);
|
||||
|
||||
// Results count
|
||||
fontRendererObj.drawString(totalResults + " listings", 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";
|
||||
}
|
||||
}
|
||||
|
||||
// ICustomScrollListener
|
||||
@Override
|
||||
public void scrollClicked(int scrollId, int index, boolean doubleClick, String selection) {
|
||||
selectedListingIndex = index;
|
||||
updateButtonStates();
|
||||
|
||||
if (doubleClick && selectedListingIndex >= 0 && selectedListingIndex < listings.size()) {
|
||||
viewDetails();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
// Handled above
|
||||
}
|
||||
|
||||
// IGuiData - Receive NBT data from server
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
// This can be used for initial setup data
|
||||
}
|
||||
|
||||
// IAuctionData - Receive auction listing data
|
||||
@Override
|
||||
public void onAuctionDataReceived(int dataType, NBTTagCompound data,
|
||||
int totalResults, int currentPage, int totalPages,
|
||||
long playerBalance) {
|
||||
this.totalResults = totalResults;
|
||||
this.currentPage = currentPage;
|
||||
this.totalPages = totalPages;
|
||||
this.playerBalance = playerBalance;
|
||||
|
||||
// Parse listings from NBT
|
||||
listings.clear();
|
||||
NBTTagList listingList = data.getTagList("Listings", 10);
|
||||
for (int i = 0; i < listingList.tagCount(); i++) {
|
||||
NBTTagCompound listingNBT = listingList.getCompoundTagAt(i);
|
||||
AuctionListing listing = new AuctionListing();
|
||||
listing.readFromNBT(listingNBT);
|
||||
listings.add(listing);
|
||||
}
|
||||
|
||||
selectedListingIndex = -1;
|
||||
updateListingDisplay();
|
||||
updateButtonStates();
|
||||
|
||||
// Update labels
|
||||
if (getLabel(41) != null) {
|
||||
getLabel(41).label = getPageLabel();
|
||||
}
|
||||
if (getLabel(60) != null) {
|
||||
getLabel(60).label = "Balance: " + formatCurrency(playerBalance);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Nothing to save
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
package noppes.npcs.client.gui.player;
|
||||
|
||||
import kamkeel.npcs.network.packets.player.AuctionActionPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
|
||||
/**
|
||||
* Sub GUI for placing a bid on an auction.
|
||||
*/
|
||||
public class SubGuiAuctionBid extends SubGuiInterface {
|
||||
private AuctionListing listing;
|
||||
private long playerBalance;
|
||||
private GuiNpcTextField bidField;
|
||||
private long lastUpdate = 0;
|
||||
|
||||
public SubGuiAuctionBid(GuiAuction parent, AuctionListing listing, long playerBalance) {
|
||||
this.listing = listing;
|
||||
this.playerBalance = playerBalance;
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
ySize = 150;
|
||||
closeOnEsc = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 10;
|
||||
int labelColor = 0x404040;
|
||||
|
||||
// Title
|
||||
addLabel(new GuiNpcLabel(0, "Place Bid", guiLeft + 70, y, labelColor));
|
||||
y += 18;
|
||||
|
||||
// Item name
|
||||
addLabel(new GuiNpcLabel(1, "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(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(5, formatCurrency(minBid), guiLeft + 100, y, 0x0066AA));
|
||||
y += 14;
|
||||
|
||||
// Your balance
|
||||
addLabel(new GuiNpcLabel(6, "Your Balance:", 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(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));
|
||||
bidField = new GuiNpcTextField(11, this, guiLeft + 80, y, 100, 16, String.valueOf(minBid));
|
||||
bidField.setNumbersOnly();
|
||||
bidField.setMinMaxDefault(minBid, 999999999, minBid);
|
||||
addTextField(bidField);
|
||||
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%"));
|
||||
y += 22;
|
||||
|
||||
// Place bid button
|
||||
GuiNpcButton bidButton = new GuiNpcButton(30, guiLeft + 15, y, 80, 20, "Place Bid");
|
||||
bidButton.setEnabled(playerBalance >= minBid && listing.isActive());
|
||||
addButton(bidButton);
|
||||
|
||||
// Cancel button
|
||||
addButton(new GuiNpcButton(31, guiLeft + 105, y, 80, 20, "Cancel"));
|
||||
|
||||
// Error message area
|
||||
if (playerBalance < minBid) {
|
||||
addLabel(new GuiNpcLabel(40, "Insufficient funds!", guiLeft + 50, guiTop + ySize - 15, 0xAA0000));
|
||||
} else if (!listing.isActive()) {
|
||||
addLabel(new GuiNpcLabel(40, "Auction has ended!", guiLeft + 50, guiTop + ySize - 15, 0xAA0000));
|
||||
}
|
||||
}
|
||||
|
||||
private String formatCurrency(long amount) {
|
||||
return String.format("%,d %s", amount, ConfigMarket.CurrencyName);
|
||||
}
|
||||
|
||||
private String formatTimeRemaining(long millis) {
|
||||
if (millis <= 0) return "Ended";
|
||||
|
||||
long seconds = millis / 1000;
|
||||
long minutes = seconds / 60;
|
||||
long hours = minutes / 60;
|
||||
|
||||
if (hours > 0) {
|
||||
return String.format("%dh %dm", hours, minutes % 60);
|
||||
} else if (minutes > 0) {
|
||||
return String.format("%dm %ds", minutes, seconds % 60);
|
||||
} else {
|
||||
return String.format("%ds", seconds);
|
||||
}
|
||||
}
|
||||
|
||||
private int getTimeColor(long millis) {
|
||||
if (millis <= 0) return 0xAA0000;
|
||||
if (millis < 5 * 60 * 1000) return 0xFF0000;
|
||||
if (millis < 30 * 60 * 1000) return 0xFF6600;
|
||||
return 0x008800;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
// Update time remaining every second
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastUpdate >= 1000) {
|
||||
lastUpdate = now;
|
||||
|
||||
GuiNpcLabel timeLabel = getLabel(9);
|
||||
if (timeLabel != null) {
|
||||
long remaining = listing.getTimeRemaining();
|
||||
timeLabel.label = formatTimeRemaining(remaining);
|
||||
timeLabel.color = getTimeColor(remaining);
|
||||
}
|
||||
|
||||
// Disable bid button if auction ended
|
||||
GuiNpcButton bidButton = getButton(30);
|
||||
if (bidButton != null && !listing.isActive()) {
|
||||
bidButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
int id = button.id;
|
||||
|
||||
long minBid = listing.getMinimumBid();
|
||||
|
||||
if (id == 20) {
|
||||
// Min bid
|
||||
bidField.setText(String.valueOf(minBid));
|
||||
} else if (id == 21) {
|
||||
// +10%
|
||||
long newBid = (long) (minBid * 1.10);
|
||||
if (newBid <= playerBalance) {
|
||||
bidField.setText(String.valueOf(newBid));
|
||||
}
|
||||
} else if (id == 22) {
|
||||
// +25%
|
||||
long newBid = (long) (minBid * 1.25);
|
||||
if (newBid <= playerBalance) {
|
||||
bidField.setText(String.valueOf(newBid));
|
||||
}
|
||||
} else if (id == 30) {
|
||||
// Place bid
|
||||
placeBid();
|
||||
} else if (id == 31) {
|
||||
// Cancel
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
private void placeBid() {
|
||||
long bidAmount = bidField.getInteger();
|
||||
long minBid = listing.getMinimumBid();
|
||||
|
||||
if (bidAmount < minBid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (bidAmount > playerBalance) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!listing.isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send bid to server
|
||||
AuctionActionPacket.PlaceBid(listing.id, bidAmount);
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Nothing to save
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
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 noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
import noppes.npcs.constants.EnumAuctionDuration;
|
||||
import noppes.npcs.containers.ContainerAuction;
|
||||
|
||||
/**
|
||||
* Sub GUI for creating a new auction listing.
|
||||
*/
|
||||
public class SubGuiAuctionCreate extends SubGuiInterface {
|
||||
private ContainerAuction container;
|
||||
|
||||
private GuiNpcTextField startingPriceField;
|
||||
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");
|
||||
xSize = 220;
|
||||
ySize = 180;
|
||||
closeOnEsc = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
// Title
|
||||
addLabel(new GuiNpcLabel(0, "Create Auction Listing", guiLeft + 50, guiTop + 8, 0x404040));
|
||||
|
||||
// Item slot instructions
|
||||
addLabel(new GuiNpcLabel(1, "Place item in slot below:", 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));
|
||||
} else {
|
||||
addLabel(new GuiNpcLabel(2, "(No item selected)", guiLeft + 20, guiTop + 50, 0x888888));
|
||||
}
|
||||
|
||||
// Starting price
|
||||
addLabel(new GuiNpcLabel(10, "Starting Price:", 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));
|
||||
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));
|
||||
|
||||
// Duration selection
|
||||
addLabel(new GuiNpcLabel(30, "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,
|
||||
guiLeft + 20, guiTop + 135, fee > 0 ? 0xAA0000 : 0x008800));
|
||||
|
||||
// Create button
|
||||
addButton(new GuiNpcButton(50, guiLeft + 20, guiTop + 155, 80, 20, "Create Listing"));
|
||||
getButton(50).setEnabled(item != null);
|
||||
|
||||
// Cancel button
|
||||
addButton(new GuiNpcButton(51, guiLeft + 120, guiTop + 155, 80, 20, "Cancel"));
|
||||
}
|
||||
|
||||
private String getDurationDisplay() {
|
||||
EnumAuctionDuration duration = EnumAuctionDuration.values()[selectedDuration];
|
||||
return DURATION_NAMES[selectedDuration] + " (" + duration.getHours() + "h)";
|
||||
}
|
||||
|
||||
private long getListingFee() {
|
||||
EnumAuctionDuration duration = EnumAuctionDuration.values()[selectedDuration];
|
||||
return duration.getFee();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
int id = button.id;
|
||||
|
||||
if (id == 31) {
|
||||
// Cycle duration
|
||||
selectedDuration = (selectedDuration + 1) % EnumAuctionDuration.values().length;
|
||||
initGui();
|
||||
} else if (id == 50) {
|
||||
// Create listing
|
||||
createListing();
|
||||
} else if (id == 51) {
|
||||
// Cancel
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
private void createListing() {
|
||||
ItemStack item = container.getListingItem();
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
long startingPrice = startingPriceField.getInteger();
|
||||
long buyoutPrice = buyoutPriceField.getInteger();
|
||||
|
||||
if (startingPrice < 1) {
|
||||
startingPrice = 1;
|
||||
}
|
||||
|
||||
if (buyoutPrice > 0 && buyoutPrice < startingPrice) {
|
||||
// Show error - buyout must be higher than starting
|
||||
return;
|
||||
}
|
||||
|
||||
EnumAuctionDuration duration = EnumAuctionDuration.values()[selectedDuration];
|
||||
|
||||
// Send to server
|
||||
AuctionActionPacket.CreateListing(item, startingPrice, buyoutPrice, duration);
|
||||
|
||||
// Clear slot and close
|
||||
container.clearListingSlot();
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
// Update item display if it changed
|
||||
ItemStack item = container.getListingItem();
|
||||
GuiNpcLabel itemLabel = getLabel(2);
|
||||
GuiNpcButton createButton = getButton(50);
|
||||
|
||||
if (item != null) {
|
||||
if (itemLabel != null) {
|
||||
itemLabel.label = "Item: " + item.getDisplayName();
|
||||
itemLabel.color = 0x008800;
|
||||
}
|
||||
if (createButton != null) {
|
||||
createButton.setEnabled(true);
|
||||
}
|
||||
} else {
|
||||
if (itemLabel != null) {
|
||||
itemLabel.label = "(No item selected)";
|
||||
itemLabel.color = 0x888888;
|
||||
}
|
||||
if (createButton != null) {
|
||||
createButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Nothing to save
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package noppes.npcs.client.gui.player;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
/**
|
||||
* Sub GUI for viewing auction listing details.
|
||||
*/
|
||||
public class SubGuiAuctionDetails extends SubGuiInterface {
|
||||
private AuctionListing listing;
|
||||
private long lastUpdate = 0;
|
||||
|
||||
public SubGuiAuctionDetails(GuiAuction parent, AuctionListing listing) {
|
||||
this.listing = listing;
|
||||
setBackground("menubg.png");
|
||||
xSize = 240;
|
||||
ySize = 200;
|
||||
closeOnEsc = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 8;
|
||||
int labelColor = 0x404040;
|
||||
int valueColor = 0x000000;
|
||||
|
||||
// Title
|
||||
addLabel(new GuiNpcLabel(0, "Auction Details", guiLeft + 80, y, labelColor));
|
||||
y += 16;
|
||||
|
||||
// Item name
|
||||
addLabel(new GuiNpcLabel(1, "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(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(6, listing.sellerName, guiLeft + 80, y, valueColor));
|
||||
y += 14;
|
||||
|
||||
// Starting price
|
||||
addLabel(new GuiNpcLabel(10, "Starting Price:", 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(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(15, listing.highBidderName, guiLeft + 100, y, valueColor));
|
||||
y += 14;
|
||||
|
||||
// Bid count
|
||||
addLabel(new GuiNpcLabel(16, "Total Bids:", 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));
|
||||
y += 14;
|
||||
}
|
||||
|
||||
// Buyout price
|
||||
if (listing.buyoutPrice > 0) {
|
||||
addLabel(new GuiNpcLabel(20, "Buyout Price:", 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(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(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"));
|
||||
}
|
||||
|
||||
private String formatCurrency(long amount) {
|
||||
return String.format("%,d %s", amount, ConfigMarket.CurrencyName);
|
||||
}
|
||||
|
||||
private String formatTimeRemaining(long millis) {
|
||||
if (millis <= 0) return "Auction Ended";
|
||||
|
||||
long seconds = millis / 1000;
|
||||
long minutes = seconds / 60;
|
||||
long hours = minutes / 60;
|
||||
long days = hours / 24;
|
||||
|
||||
if (days > 0) {
|
||||
return String.format("%dd %dh %dm", days, hours % 24, minutes % 60);
|
||||
} else if (hours > 0) {
|
||||
return String.format("%dh %dm %ds", hours, minutes % 60, seconds % 60);
|
||||
} else if (minutes > 0) {
|
||||
return String.format("%dm %ds", minutes, seconds % 60);
|
||||
} else {
|
||||
return String.format("%ds", seconds);
|
||||
}
|
||||
}
|
||||
|
||||
private int getTimeColor(long millis) {
|
||||
if (millis <= 0) return 0xAA0000;
|
||||
if (millis < 5 * 60 * 1000) return 0xFF0000; // < 5 minutes - red
|
||||
if (millis < 30 * 60 * 1000) return 0xFF6600; // < 30 minutes - orange
|
||||
if (millis < 60 * 60 * 1000) return 0xAAAA00; // < 1 hour - yellow
|
||||
return 0x008800; // green
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
// Update time remaining every second
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastUpdate >= 1000) {
|
||||
lastUpdate = now;
|
||||
|
||||
GuiNpcLabel timeLabel = getLabel(31);
|
||||
if (timeLabel != null) {
|
||||
long remaining = listing.getTimeRemaining();
|
||||
timeLabel.label = formatTimeRemaining(remaining);
|
||||
timeLabel.color = getTimeColor(remaining);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
// Draw item icon
|
||||
if (listing.item != null) {
|
||||
int itemX = guiLeft + 200;
|
||||
int itemY = guiTop + 30;
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glScalef(2.0f, 2.0f, 2.0f);
|
||||
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine,
|
||||
listing.item, itemX / 2, itemY / 2);
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine,
|
||||
listing.item, itemX / 2, itemY / 2);
|
||||
|
||||
GL11.glScalef(0.5f, 0.5f, 0.5f);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
|
||||
// Tooltip on hover
|
||||
if (mouseX >= itemX && mouseX < itemX + 32 && mouseY >= itemY && mouseY < itemY + 32) {
|
||||
renderToolTip(listing.item, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
if (button.id == 50) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Nothing to save
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package noppes.npcs.containers;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
/**
|
||||
* Container for auction house GUI.
|
||||
* Handles player inventory and item slot for creating listings.
|
||||
*/
|
||||
public class ContainerAuction extends Container {
|
||||
public EntityNPCInterface npc;
|
||||
public EntityPlayer player;
|
||||
|
||||
// Slot for item being listed
|
||||
public SlotAuctionItem listingSlot;
|
||||
private IInventory listingInventory;
|
||||
|
||||
public ContainerAuction(EntityNPCInterface npc, EntityPlayer player) {
|
||||
this.npc = npc;
|
||||
this.player = player;
|
||||
|
||||
// Create a single-slot inventory for the item being listed
|
||||
listingInventory = new InventoryAuctionListing();
|
||||
listingSlot = new SlotAuctionItem(listingInventory, 0, 80, 35);
|
||||
addSlotToContainer(listingSlot);
|
||||
|
||||
// Player inventory slots (standard positioning)
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int col = 0; col < 9; col++) {
|
||||
addSlotToContainer(new Slot(player.inventory, col + row * 9 + 9,
|
||||
8 + col * 18, 140 + row * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Player hotbar
|
||||
for (int col = 0; col < 9; col++) {
|
||||
addSlotToContainer(new Slot(player.inventory, col, 8 + col * 18, 198));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return npc != null && npc.isEntityAlive() &&
|
||||
player.getDistanceSqToEntity(npc) < 64.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
itemstack = stackInSlot.copy();
|
||||
|
||||
// If from listing slot, move to player inventory
|
||||
if (slotIndex == 0) {
|
||||
if (!mergeItemStack(stackInSlot, 1, 37, true)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// If from player inventory, move to listing slot
|
||||
else {
|
||||
if (!mergeItemStack(stackInSlot, 0, 1, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (stackInSlot.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer player) {
|
||||
super.onContainerClosed(player);
|
||||
|
||||
// Return any item in the listing slot to player
|
||||
ItemStack stack = listingInventory.getStackInSlot(0);
|
||||
if (stack != null) {
|
||||
if (!player.inventory.addItemStackToInventory(stack)) {
|
||||
player.entityDropItem(stack, 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item currently in the listing slot
|
||||
*/
|
||||
public ItemStack getListingItem() {
|
||||
return listingInventory.getStackInSlot(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the listing slot (after successful listing creation)
|
||||
*/
|
||||
public void clearListingSlot() {
|
||||
listingInventory.setInventorySlotContents(0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple inventory for the listing slot
|
||||
*/
|
||||
private class InventoryAuctionListing implements IInventory {
|
||||
private ItemStack item;
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() { return 1; }
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) { return item; }
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
if (item != null) {
|
||||
ItemStack result;
|
||||
if (item.stackSize <= amount) {
|
||||
result = item;
|
||||
item = null;
|
||||
return result;
|
||||
} else {
|
||||
result = item.splitStack(amount);
|
||||
if (item.stackSize == 0) {
|
||||
item = null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
ItemStack result = item;
|
||||
item = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
item = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() { return "AuctionListing"; }
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() { return false; }
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() { return 64; }
|
||||
|
||||
@Override
|
||||
public void markDirty() {}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) { return true; }
|
||||
|
||||
@Override
|
||||
public void openInventory() {}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) { return true; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom slot for auction listings
|
||||
*/
|
||||
public class SlotAuctionItem extends Slot {
|
||||
public SlotAuctionItem(IInventory inv, int index, int x, int y) {
|
||||
super(inv, index, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
// Check if item can be traded (not untradeable, soulbound, etc.)
|
||||
return kamkeel.npcs.controllers.data.attribute.ItemTradeAttribute.canTrade(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,9 @@ public class AuctionController {
|
||||
listing.id, seller.getCommandSenderName(),
|
||||
item.getDisplayName());
|
||||
|
||||
// Log to CNPC+ auction history
|
||||
AuctionLogger.logListingCreated(listing);
|
||||
|
||||
return listing;
|
||||
}
|
||||
|
||||
@@ -401,8 +404,9 @@ public class AuctionController {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store previous bidder for refund
|
||||
// Store previous bidder for refund and notification
|
||||
UUID previousBidder = listing.highBidderUUID;
|
||||
String previousBidderName = listing.highBidderName;
|
||||
long previousBidAmount = listing.currentBid;
|
||||
|
||||
// Try to place bid
|
||||
@@ -413,7 +417,7 @@ public class AuctionController {
|
||||
// Withdraw bid amount from new bidder
|
||||
CurrencyController.Instance.withdraw(bidder, amount);
|
||||
|
||||
// Refund previous bidder via claims system
|
||||
// Refund previous bidder via claims system and notify
|
||||
if (previousBidder != null) {
|
||||
CurrencyController.Instance.addClaim(
|
||||
previousBidder,
|
||||
@@ -421,6 +425,20 @@ public class AuctionController {
|
||||
"Auction Outbid",
|
||||
String.valueOf(listingId)
|
||||
);
|
||||
|
||||
// Notify previous bidder they were outbid
|
||||
if (AuctionNotificationController.Instance != null) {
|
||||
AuctionNotificationController.Instance.notifyOutbid(
|
||||
listing, previousBidder, previousBidderName, previousBidAmount, amount);
|
||||
}
|
||||
|
||||
// Log refund
|
||||
AuctionLogger.logBidRefunded(listing, previousBidderName, previousBidAmount);
|
||||
}
|
||||
|
||||
// Notify seller of new bid
|
||||
if (AuctionNotificationController.Instance != null) {
|
||||
AuctionNotificationController.Instance.notifyNewBid(listing, bidder.getCommandSenderName(), amount);
|
||||
}
|
||||
|
||||
// Update bidder index
|
||||
@@ -448,8 +466,9 @@ public class AuctionController {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store previous bidder for refund
|
||||
// Store previous bidder for refund and notification
|
||||
UUID previousBidder = listing.highBidderUUID;
|
||||
String previousBidderName = listing.highBidderName;
|
||||
long previousBidAmount = listing.currentBid;
|
||||
|
||||
// Execute buyout
|
||||
@@ -460,7 +479,7 @@ public class AuctionController {
|
||||
// Withdraw buyout amount from buyer
|
||||
CurrencyController.Instance.withdraw(buyer, listing.buyoutPrice);
|
||||
|
||||
// Refund previous bidder via claims system
|
||||
// Refund previous bidder via claims system and notify
|
||||
if (previousBidder != null) {
|
||||
CurrencyController.Instance.addClaim(
|
||||
previousBidder,
|
||||
@@ -468,6 +487,15 @@ public class AuctionController {
|
||||
"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);
|
||||
}
|
||||
|
||||
// Update bidder index
|
||||
@@ -477,6 +505,16 @@ public class AuctionController {
|
||||
logger.info("Buyout executed on listing {} by {} for {}",
|
||||
listingId, buyer.getCommandSenderName(), listing.buyoutPrice);
|
||||
|
||||
// Log buyout and send notifications
|
||||
AuctionLogger.logBuyout(listing, buyer.getCommandSenderName());
|
||||
|
||||
if (AuctionNotificationController.Instance != null) {
|
||||
// Notify buyer they won
|
||||
AuctionNotificationController.Instance.notifyAuctionWon(listing);
|
||||
// Notify seller their item sold
|
||||
AuctionNotificationController.Instance.notifyAuctionSold(listing);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -490,6 +528,8 @@ public class AuctionController {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean byAdmin = !listing.sellerUUID.equals(requester.getUniqueID());
|
||||
|
||||
if (!listing.cancel(requester.getUniqueID())) {
|
||||
return false;
|
||||
}
|
||||
@@ -498,6 +538,12 @@ public class AuctionController {
|
||||
logger.info("Listing {} cancelled by {}",
|
||||
listingId, requester.getCommandSenderName());
|
||||
|
||||
// Log and notify
|
||||
AuctionLogger.logAuctionCancelled(listing, byAdmin);
|
||||
if (AuctionNotificationController.Instance != null) {
|
||||
AuctionNotificationController.Instance.notifyAuctionCancelled(listing, byAdmin);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -536,6 +582,9 @@ public class AuctionController {
|
||||
logger.info("Seller {} claimed {} from listing {}",
|
||||
seller.getCommandSenderName(), proceeds, listingId);
|
||||
|
||||
// Log the currency claim
|
||||
AuctionLogger.logCurrencyClaimed(listing, seller.getCommandSenderName(), proceeds);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -569,6 +618,9 @@ public class AuctionController {
|
||||
logger.info("Buyer {} claimed item from listing {}",
|
||||
buyer.getCommandSenderName(), listingId);
|
||||
|
||||
// Log the item claim
|
||||
AuctionLogger.logItemClaimed(listing, buyer.getCommandSenderName(), false);
|
||||
|
||||
return listing.item.copy();
|
||||
}
|
||||
|
||||
@@ -602,6 +654,9 @@ public class AuctionController {
|
||||
logger.info("Seller {} reclaimed item from listing {}",
|
||||
seller.getCommandSenderName(), listingId);
|
||||
|
||||
// Log the item reclaim
|
||||
AuctionLogger.logItemClaimed(listing, seller.getCommandSenderName(), true);
|
||||
|
||||
return listing.item.copy();
|
||||
}
|
||||
|
||||
@@ -624,6 +679,8 @@ public class AuctionController {
|
||||
*/
|
||||
public void processExpiredAuctions() {
|
||||
boolean changed = false;
|
||||
int expiredCount = 0;
|
||||
int soldCount = 0;
|
||||
|
||||
for (AuctionListing listing : listings.values()) {
|
||||
if (listing.status == EnumAuctionStatus.ACTIVE && listing.isExpired()) {
|
||||
@@ -632,17 +689,32 @@ public class AuctionController {
|
||||
|
||||
// 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);
|
||||
|
||||
// Send notifications
|
||||
if (AuctionNotificationController.Instance != null) {
|
||||
AuctionNotificationController.Instance.notifyAuctionWon(listing);
|
||||
AuctionNotificationController.Instance.notifyAuctionSold(listing);
|
||||
}
|
||||
} else {
|
||||
expiredCount++;
|
||||
logger.info("Auction {} expired without bids", listing.id);
|
||||
|
||||
// Notify seller about expiration
|
||||
if (AuctionNotificationController.Instance != null) {
|
||||
AuctionNotificationController.Instance.notifyAuctionExpired(listing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
save();
|
||||
// Log processing tick if anything happened
|
||||
AuctionLogger.logProcessingTick(expiredCount, soldCount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -804,8 +876,23 @@ public class AuctionController {
|
||||
|
||||
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);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error loading auctions", e);
|
||||
AuctionLogger.logError("Loading auctions", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user