mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 06:53:20 +00:00
Add auction filtering and sorting system
New files: - EnumAuctionSort: Sorting options (price, time, name, bids, etc.) - AuctionFilter: Search/filter criteria with builder pattern - AuctionDataPacket: Large packet for server->client listing data AuctionController changes: - getFilteredListings(): Main filtering/pagination method - sortListings(): Comprehensive sorting by various criteria - quickSearch(): Convenience method for simple searches - FilterResult: Pagination result container AuctionListing changes: - Added bidCount field with NBT persistence - Added creationTime alias methods AuctionActionPacket changes: - QueryListings: Filter-based search - QueryMyListings: Player's own listings - QueryMyBids: Player's active bids - QueryClaimable: Items ready to claim NoppesUtil changes: - Auction data storage and IAuctionData interface - Client-side data handling for GUI integration
This commit is contained in:
9 files changed
+913
-1
No files matched your search
@@ -36,6 +36,7 @@ import kamkeel.npcs.network.packets.data.gui.GuiWaypointPacket;
|
||||
import kamkeel.npcs.network.packets.data.gui.IsGuiOpenPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.PartyDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.AuctionDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.ScrollDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.ScrollListPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.SyncEffectPacket;
|
||||
@@ -551,6 +552,7 @@ public class PacketHandler {
|
||||
DATA_PACKET.registerPacket(new SyncEffectPacket());
|
||||
DATA_PACKET.registerPacket(new GuiDataPacket());
|
||||
DATA_PACKET.registerPacket(new PartyDataPacket());
|
||||
DATA_PACKET.registerPacket(new AuctionDataPacket());
|
||||
}
|
||||
|
||||
public void registerPlayerPackets() {
|
||||
|
||||
@@ -58,4 +58,7 @@ public enum EnumDataPacket {
|
||||
SWING_PLAYER_ARM,
|
||||
DISABLE_MOUSE_INPUT,
|
||||
LOGIN,
|
||||
|
||||
// Auction
|
||||
AUCTION_DATA,
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
package kamkeel.npcs.network.packets.data.large;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import kamkeel.npcs.network.LargeAbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
import noppes.npcs.controllers.data.AuctionFilter;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Large packet for sending auction listing data from server to client.
|
||||
* Used for initial load and search/filter queries.
|
||||
*/
|
||||
public final class AuctionDataPacket extends LargeAbstractPacket {
|
||||
public static final String packetName = "Large|AuctionData";
|
||||
|
||||
private DataType dataType;
|
||||
private List<AuctionListing> listings;
|
||||
private int totalResults;
|
||||
private int currentPage;
|
||||
private int totalPages;
|
||||
private long playerBalance;
|
||||
|
||||
public AuctionDataPacket() {
|
||||
}
|
||||
|
||||
private AuctionDataPacket(DataType type, List<AuctionListing> listings,
|
||||
int totalResults, int currentPage, int totalPages,
|
||||
long playerBalance) {
|
||||
this.dataType = type;
|
||||
this.listings = listings;
|
||||
this.totalResults = totalResults;
|
||||
this.currentPage = currentPage;
|
||||
this.totalPages = totalPages;
|
||||
this.playerBalance = playerBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send filtered listing results to client
|
||||
*/
|
||||
public static void sendFilteredListings(EntityPlayerMP player, AuctionFilter filter) {
|
||||
if (AuctionController.Instance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionController.FilterResult result = AuctionController.Instance.getFilteredListings(filter);
|
||||
long balance = 0;
|
||||
if (noppes.npcs.controllers.CurrencyController.Instance != null) {
|
||||
balance = noppes.npcs.controllers.CurrencyController.Instance.getBalance(player);
|
||||
}
|
||||
|
||||
AuctionDataPacket packet = new AuctionDataPacket(
|
||||
DataType.FILTERED_LISTINGS,
|
||||
result.listings,
|
||||
result.totalResults,
|
||||
result.currentPage,
|
||||
result.totalPages,
|
||||
balance
|
||||
);
|
||||
PacketHandler.Instance.sendToPlayer(packet, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send player's own listings
|
||||
*/
|
||||
public static void sendMyListings(EntityPlayerMP player) {
|
||||
if (AuctionController.Instance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<AuctionListing> myListings = AuctionController.Instance
|
||||
.getListingsBySeller(player.getUniqueID());
|
||||
|
||||
long balance = 0;
|
||||
if (noppes.npcs.controllers.CurrencyController.Instance != null) {
|
||||
balance = noppes.npcs.controllers.CurrencyController.Instance.getBalance(player);
|
||||
}
|
||||
|
||||
AuctionDataPacket packet = new AuctionDataPacket(
|
||||
DataType.MY_LISTINGS,
|
||||
myListings,
|
||||
myListings.size(),
|
||||
0,
|
||||
1,
|
||||
balance
|
||||
);
|
||||
PacketHandler.Instance.sendToPlayer(packet, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send player's active bids
|
||||
*/
|
||||
public static void sendMyBids(EntityPlayerMP player) {
|
||||
if (AuctionController.Instance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<AuctionListing> myBids = AuctionController.Instance
|
||||
.getListingsAsBidder(player.getUniqueID());
|
||||
|
||||
long balance = 0;
|
||||
if (noppes.npcs.controllers.CurrencyController.Instance != null) {
|
||||
balance = noppes.npcs.controllers.CurrencyController.Instance.getBalance(player);
|
||||
}
|
||||
|
||||
AuctionDataPacket packet = new AuctionDataPacket(
|
||||
DataType.MY_BIDS,
|
||||
myBids,
|
||||
myBids.size(),
|
||||
0,
|
||||
1,
|
||||
balance
|
||||
);
|
||||
PacketHandler.Instance.sendToPlayer(packet, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send player's claimable items
|
||||
*/
|
||||
public static void sendClaimable(EntityPlayerMP player) {
|
||||
if (AuctionController.Instance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<AuctionListing> claimable = AuctionController.Instance
|
||||
.getClaimableListings(player.getUniqueID());
|
||||
|
||||
long balance = 0;
|
||||
if (noppes.npcs.controllers.CurrencyController.Instance != null) {
|
||||
balance = noppes.npcs.controllers.CurrencyController.Instance.getBalance(player);
|
||||
}
|
||||
|
||||
AuctionDataPacket packet = new AuctionDataPacket(
|
||||
DataType.CLAIMABLE,
|
||||
claimable,
|
||||
claimable.size(),
|
||||
0,
|
||||
1,
|
||||
balance
|
||||
);
|
||||
PacketHandler.Instance.sendToPlayer(packet, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumDataPacket.AUCTION_DATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.DATA_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] getData() throws IOException {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
|
||||
buffer.writeInt(dataType.ordinal());
|
||||
buffer.writeInt(totalResults);
|
||||
buffer.writeInt(currentPage);
|
||||
buffer.writeInt(totalPages);
|
||||
buffer.writeLong(playerBalance);
|
||||
|
||||
// Write listings as NBT
|
||||
NBTTagList listingList = new NBTTagList();
|
||||
if (listings != null) {
|
||||
for (AuctionListing listing : listings) {
|
||||
listingList.appendTag(listing.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setTag("Listings", listingList);
|
||||
ByteBufUtils.writeNBT(buffer, compound);
|
||||
|
||||
byte[] bytes = new byte[buffer.readableBytes()];
|
||||
buffer.readBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
|
||||
// Client-side handling will be done in a client util class
|
||||
// Similar to NoppesUtil.setScrollData()
|
||||
int typeOrdinal = data.readInt();
|
||||
int totalResults = data.readInt();
|
||||
int currentPage = data.readInt();
|
||||
int totalPages = data.readInt();
|
||||
long playerBalance = data.readLong();
|
||||
|
||||
NBTTagCompound compound = ByteBufUtils.readNBT(data);
|
||||
|
||||
DataType type = DataType.values()[typeOrdinal];
|
||||
|
||||
// Store data for client GUI to access
|
||||
// This will be implemented in the client-side GUI handler
|
||||
noppes.npcs.client.NoppesUtil.setAuctionData(type.ordinal(), compound,
|
||||
totalResults, currentPage, totalPages, playerBalance);
|
||||
}
|
||||
|
||||
public enum DataType {
|
||||
FILTERED_LISTINGS,
|
||||
MY_LISTINGS,
|
||||
MY_BIDS,
|
||||
CLAIMABLE
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,10 @@ import noppes.npcs.constants.EnumAuctionDuration;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
import noppes.npcs.controllers.CurrencyController;
|
||||
import noppes.npcs.controllers.data.AuctionFilter;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
import kamkeel.npcs.network.packets.data.large.AuctionDataPacket;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -37,6 +39,7 @@ public class AuctionActionPacket extends AbstractPacket {
|
||||
private long buyoutPrice;
|
||||
private int durationOrdinal;
|
||||
private NBTTagCompound itemData;
|
||||
private NBTTagCompound filterData; // For query operations
|
||||
private String responseMessage;
|
||||
private boolean success;
|
||||
|
||||
@@ -118,6 +121,43 @@ public class AuctionActionPacket extends AbstractPacket {
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query filtered listings
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void QueryListings(AuctionFilter filter) {
|
||||
AuctionActionPacket packet = new AuctionActionPacket(Action.QueryListings);
|
||||
packet.filterData = filter.writeToNBT(new NBTTagCompound());
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request player's own listings
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void QueryMyListings() {
|
||||
AuctionActionPacket packet = new AuctionActionPacket(Action.QueryMyListings);
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request player's active bids
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void QueryMyBids() {
|
||||
AuctionActionPacket packet = new AuctionActionPacket(Action.QueryMyBids);
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request player's claimable items
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void QueryClaimable() {
|
||||
AuctionActionPacket packet = new AuctionActionPacket(Action.QueryClaimable);
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumPlayerPacket.AuctionAction;
|
||||
@@ -155,6 +195,19 @@ public class AuctionActionPacket extends AbstractPacket {
|
||||
case ClaimProceeds:
|
||||
out.writeInt(listingId);
|
||||
break;
|
||||
|
||||
case QueryListings:
|
||||
String filterJson = NBTJsonUtil.Convert(filterData);
|
||||
byte[] filterBytes = filterJson.getBytes("UTF-8");
|
||||
out.writeInt(filterBytes.length);
|
||||
out.writeBytes(filterBytes);
|
||||
break;
|
||||
|
||||
case QueryMyListings:
|
||||
case QueryMyBids:
|
||||
case QueryClaimable:
|
||||
// No additional data needed
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,6 +257,18 @@ public class AuctionActionPacket extends AbstractPacket {
|
||||
case ClaimProceeds:
|
||||
handleClaimProceeds(in, playerMP);
|
||||
break;
|
||||
case QueryListings:
|
||||
handleQueryListings(in, playerMP);
|
||||
break;
|
||||
case QueryMyListings:
|
||||
handleQueryMyListings(playerMP);
|
||||
break;
|
||||
case QueryMyBids:
|
||||
handleQueryMyBids(playerMP);
|
||||
break;
|
||||
case QueryClaimable:
|
||||
handleQueryClaimable(playerMP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,6 +485,62 @@ public class AuctionActionPacket extends AbstractPacket {
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Query Handlers ====================
|
||||
|
||||
private void handleQueryListings(ByteBuf in, EntityPlayerMP player) throws IOException {
|
||||
// Check permission
|
||||
if (!CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.AUCTION_USE)) {
|
||||
sendResponse(player, false, "You don't have permission to view auctions");
|
||||
return;
|
||||
}
|
||||
|
||||
int filterBytesLength = in.readInt();
|
||||
byte[] filterBytes = new byte[filterBytesLength];
|
||||
in.readBytes(filterBytes);
|
||||
String filterJson = new String(filterBytes, "UTF-8");
|
||||
|
||||
try {
|
||||
NBTTagCompound filterNBT = NBTJsonUtil.Convert(filterJson);
|
||||
AuctionFilter filter = new AuctionFilter();
|
||||
filter.readFromNBT(filterNBT);
|
||||
|
||||
// Send filtered listings to client
|
||||
AuctionDataPacket.sendFilteredListings(player, filter);
|
||||
} catch (Exception e) {
|
||||
sendResponse(player, false, "Error parsing filter");
|
||||
}
|
||||
}
|
||||
|
||||
private void handleQueryMyListings(EntityPlayerMP player) {
|
||||
// Check permission
|
||||
if (!CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.AUCTION_USE)) {
|
||||
sendResponse(player, false, "You don't have permission to view auctions");
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionDataPacket.sendMyListings(player);
|
||||
}
|
||||
|
||||
private void handleQueryMyBids(EntityPlayerMP player) {
|
||||
// Check permission
|
||||
if (!CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.AUCTION_USE)) {
|
||||
sendResponse(player, false, "You don't have permission to view auctions");
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionDataPacket.sendMyBids(player);
|
||||
}
|
||||
|
||||
private void handleQueryClaimable(EntityPlayerMP player) {
|
||||
// Check permission
|
||||
if (!CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.AUCTION_USE)) {
|
||||
sendResponse(player, false, "You don't have permission to view auctions");
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionDataPacket.sendClaimable(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a response message to the player
|
||||
*/
|
||||
@@ -436,6 +557,10 @@ public class AuctionActionPacket extends AbstractPacket {
|
||||
Buyout,
|
||||
CancelListing,
|
||||
ClaimItem,
|
||||
ClaimProceeds
|
||||
ClaimProceeds,
|
||||
QueryListings,
|
||||
QueryMyListings,
|
||||
QueryMyBids,
|
||||
QueryClaimable
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user