mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 01:45:07 +00:00
Auction Global Manage System
This commit is contained in:
1 parent
03bea7461d
commit
b082ccfbd7
16 files changed
+2523
-22
No files matched your search
@@ -99,6 +99,7 @@ import kamkeel.npcs.network.packets.request.animation.AnimationRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationsGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.animation.BuiltInAnimationGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.auction.ManageAuctionPacket;
|
||||
import kamkeel.npcs.network.packets.request.bank.BankGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.bank.BankRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.bank.BankSavePacket;
|
||||
@@ -470,6 +471,7 @@ public class PacketHandler {
|
||||
|
||||
// Trader Packets
|
||||
REQUEST_PACKET.registerPacket(new TraderMarketSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new ManageAuctionPacket());
|
||||
|
||||
// Party Packets moved to player channel
|
||||
|
||||
|
||||
@@ -213,4 +213,5 @@ public enum EnumRequestPacket {
|
||||
Hammer,
|
||||
|
||||
RecipeScript,
|
||||
ManageAuctionAction,
|
||||
}
|
||||
@@ -11,6 +11,9 @@ import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
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.CustomNpcsPermissions;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
|
||||
|
||||
@@ -0,0 +1,522 @@
|
||||
package kamkeel.npcs.network.packets.request.auction;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.constants.EnumClaimType;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
import noppes.npcs.controllers.data.AuctionClaim;
|
||||
import noppes.npcs.controllers.data.AuctionFilter;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Admin-only global auction management packet.
|
||||
*/
|
||||
public class ManageAuctionPacket extends AbstractPacket {
|
||||
private static final int PAGE_SIZE = 45;
|
||||
|
||||
private Action action;
|
||||
private int page;
|
||||
private boolean flag;
|
||||
private String text;
|
||||
private long amount;
|
||||
private long amount2;
|
||||
private int amountInt;
|
||||
private NBTTagCompound data;
|
||||
|
||||
public ManageAuctionPacket() {
|
||||
}
|
||||
|
||||
private ManageAuctionPacket(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.ManageAuctionAction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.GLOBAL_AUCTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsNPC() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Client Send Helpers
|
||||
// =========================================
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void requestListings(AuctionFilter filter, int page) {
|
||||
ManageAuctionPacket packet = new ManageAuctionPacket(Action.REQUEST_LISTINGS);
|
||||
packet.page = page;
|
||||
packet.data = filter != null ? filter.writeToNBT(new NBTTagCompound()) : new NBTTagCompound();
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void requestGlobalClaims(int page) {
|
||||
ManageAuctionPacket packet = new ManageAuctionPacket(Action.REQUEST_CLAIMS);
|
||||
packet.page = page;
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void createFakeListing(ItemStack item, String sellerName, long startingPrice, long buyoutPrice, int durationHours) {
|
||||
if (item == null) return;
|
||||
|
||||
ManageAuctionPacket packet = new ManageAuctionPacket(Action.CREATE_FAKE);
|
||||
packet.text = sellerName != null ? sellerName : "";
|
||||
packet.amount = startingPrice;
|
||||
packet.amount2 = buyoutPrice;
|
||||
packet.amountInt = durationHours;
|
||||
packet.data = new NBTTagCompound();
|
||||
item.writeToNBT(packet.data);
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void manageListing(String listingId, boolean cancelCompletely) {
|
||||
ManageAuctionPacket packet = new ManageAuctionPacket(Action.MANAGE_LISTING);
|
||||
packet.text = listingId;
|
||||
packet.flag = cancelCompletely;
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void claimGlobalItem(String claimId) {
|
||||
ManageAuctionPacket packet = new ManageAuctionPacket(Action.CLAIM_ITEM);
|
||||
packet.text = claimId;
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void claimGlobalCurrency(String claimId) {
|
||||
ManageAuctionPacket packet = new ManageAuctionPacket(Action.CLAIM_CURRENCY);
|
||||
packet.text = claimId;
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void openBidding(String listingId) {
|
||||
ManageAuctionPacket packet = new ManageAuctionPacket(Action.OPEN_BIDDING);
|
||||
packet.text = listingId;
|
||||
PacketClient.sendClient(packet);
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Serialization
|
||||
// =========================================
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(action.ordinal());
|
||||
|
||||
switch (action) {
|
||||
case REQUEST_LISTINGS:
|
||||
out.writeInt(page);
|
||||
ByteBufUtils.writeNBT(out, data);
|
||||
break;
|
||||
case REQUEST_CLAIMS:
|
||||
out.writeInt(page);
|
||||
break;
|
||||
case CREATE_FAKE:
|
||||
ByteBufUtils.writeString(out, text);
|
||||
out.writeLong(amount);
|
||||
out.writeLong(amount2);
|
||||
out.writeInt(amountInt);
|
||||
ByteBufUtils.writeNBT(out, data);
|
||||
break;
|
||||
case MANAGE_LISTING:
|
||||
ByteBufUtils.writeString(out, text);
|
||||
out.writeBoolean(flag);
|
||||
break;
|
||||
case CLAIM_ITEM:
|
||||
case CLAIM_CURRENCY:
|
||||
case OPEN_BIDDING:
|
||||
ByteBufUtils.writeString(out, text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP)) return;
|
||||
EntityPlayerMP playerMP = (EntityPlayerMP) player;
|
||||
|
||||
if (!CustomNpcsPermissions.hasCustomPermission(playerMP, "customnpcs.global.auction")) {
|
||||
sendError(playerMP, "Missing permission: customnpcs.global.auction");
|
||||
return;
|
||||
}
|
||||
|
||||
int actionOrdinal = in.readInt();
|
||||
if (actionOrdinal < 0 || actionOrdinal >= Action.values().length) return;
|
||||
Action requestedAction = Action.values()[actionOrdinal];
|
||||
|
||||
AuctionController controller = AuctionController.getInstance();
|
||||
if (controller == null) {
|
||||
sendError(playerMP, "Auction system is not available.");
|
||||
return;
|
||||
}
|
||||
|
||||
String result = null;
|
||||
switch (requestedAction) {
|
||||
case REQUEST_LISTINGS:
|
||||
handleRequestListings(in, playerMP, controller);
|
||||
break;
|
||||
case REQUEST_CLAIMS:
|
||||
handleRequestClaims(in, playerMP, controller);
|
||||
break;
|
||||
case CREATE_FAKE:
|
||||
result = handleCreateFake(in, playerMP, controller);
|
||||
break;
|
||||
case MANAGE_LISTING:
|
||||
result = handleManageListing(in, playerMP, controller);
|
||||
break;
|
||||
case CLAIM_ITEM:
|
||||
result = handleClaimItem(in, playerMP, controller);
|
||||
break;
|
||||
case CLAIM_CURRENCY:
|
||||
result = handleClaimCurrency(in, playerMP, controller);
|
||||
break;
|
||||
case OPEN_BIDDING:
|
||||
handleOpenBidding(in, playerMP, controller);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
sendError(playerMP, result);
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Handlers
|
||||
// =========================================
|
||||
|
||||
private void handleRequestListings(ByteBuf in, EntityPlayerMP player, AuctionController controller) throws IOException {
|
||||
int requestPage = Math.max(0, in.readInt());
|
||||
NBTTagCompound filterNbt = ByteBufUtils.readNBT(in);
|
||||
|
||||
AuctionFilter filter = new AuctionFilter();
|
||||
if (filterNbt != null) {
|
||||
filter.readFromNBT(filterNbt);
|
||||
}
|
||||
|
||||
int totalListings = controller.getTotalActiveListings(filter);
|
||||
int totalPages = Math.max(1, (int) Math.ceil((double) totalListings / PAGE_SIZE));
|
||||
int safePage = Math.min(requestPage, totalPages - 1);
|
||||
List<AuctionListing> listings = controller.getActiveListings(filter, safePage, PAGE_SIZE);
|
||||
|
||||
NBTTagCompound response = new NBTTagCompound();
|
||||
response.setBoolean("ManageAuctionListingsData", true);
|
||||
response.setInteger("Page", safePage);
|
||||
response.setInteger("TotalPages", totalPages);
|
||||
response.setInteger("TotalListings", totalListings);
|
||||
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (AuctionListing listing : listings) {
|
||||
list.appendTag(listing.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
response.setTag("Listings", list);
|
||||
GuiDataPacket.sendGuiData(player, response);
|
||||
}
|
||||
|
||||
private void handleRequestClaims(ByteBuf in, EntityPlayerMP player, AuctionController controller) {
|
||||
int requestPage = Math.max(0, in.readInt());
|
||||
|
||||
// Global "trades" page contains global claims + active global listings,
|
||||
// ordered like My Trades: sold claims, outbid claims, won claims, active listings, expired claims.
|
||||
List<AuctionClaim> allClaims = controller.getAllGlobalClaims();
|
||||
List<AuctionListing> allListings = controller.getActiveGlobalListings();
|
||||
int totalClaims = allClaims.size();
|
||||
int totalListings = allListings.size();
|
||||
|
||||
List<AuctionClaim> soldClaims = new ArrayList<AuctionClaim>();
|
||||
List<AuctionClaim> outbidClaims = new ArrayList<AuctionClaim>();
|
||||
List<AuctionClaim> wonClaims = new ArrayList<AuctionClaim>();
|
||||
List<AuctionClaim> expiredClaims = new ArrayList<AuctionClaim>();
|
||||
for (AuctionClaim claim : allClaims) {
|
||||
if (claim == null) continue;
|
||||
if (claim.type == EnumClaimType.CURRENCY) {
|
||||
soldClaims.add(claim);
|
||||
} else if (claim.type == EnumClaimType.REFUND) {
|
||||
outbidClaims.add(claim);
|
||||
} else if (claim.type == EnumClaimType.ITEM) {
|
||||
if (claim.isReturned) {
|
||||
expiredClaims.add(claim);
|
||||
} else {
|
||||
wonClaims.add(claim);
|
||||
}
|
||||
} else {
|
||||
wonClaims.add(claim);
|
||||
}
|
||||
}
|
||||
|
||||
List<Entry> ordered = new ArrayList<Entry>();
|
||||
appendClaims(ordered, soldClaims);
|
||||
appendClaims(ordered, outbidClaims);
|
||||
appendClaims(ordered, wonClaims);
|
||||
for (AuctionListing listing : allListings) {
|
||||
ordered.add(Entry.forListing(listing));
|
||||
}
|
||||
appendClaims(ordered, expiredClaims);
|
||||
|
||||
int totalEntries = ordered.size();
|
||||
|
||||
int totalPages = Math.max(1, (int) Math.ceil((double) totalEntries / PAGE_SIZE));
|
||||
int safePage = Math.min(requestPage, totalPages - 1);
|
||||
|
||||
int start = safePage * PAGE_SIZE;
|
||||
int end = Math.min(totalEntries, start + PAGE_SIZE);
|
||||
List<AuctionClaim> pageClaims = new ArrayList<AuctionClaim>();
|
||||
List<AuctionListing> pageListings = new ArrayList<AuctionListing>();
|
||||
|
||||
for (int i = start; i < end; i++) {
|
||||
Entry entry = ordered.get(i);
|
||||
if (entry.claim != null) {
|
||||
pageClaims.add(entry.claim);
|
||||
} else if (entry.listing != null) {
|
||||
pageListings.add(entry.listing);
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound response = new NBTTagCompound();
|
||||
response.setBoolean("ManageAuctionClaimsData", true);
|
||||
response.setInteger("Page", safePage);
|
||||
response.setInteger("TotalPages", totalPages);
|
||||
response.setInteger("TotalClaims", totalClaims);
|
||||
response.setInteger("TotalListings", totalListings);
|
||||
response.setInteger("TotalEntries", totalEntries);
|
||||
|
||||
NBTTagList claimList = new NBTTagList();
|
||||
for (AuctionClaim claim : pageClaims) {
|
||||
claimList.appendTag(claim.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
response.setTag("Claims", claimList);
|
||||
|
||||
NBTTagList listingList = new NBTTagList();
|
||||
for (AuctionListing listing : pageListings) {
|
||||
listingList.appendTag(listing.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
response.setTag("Listings", listingList);
|
||||
GuiDataPacket.sendGuiData(player, response);
|
||||
}
|
||||
|
||||
private static void appendClaims(List<Entry> out, List<AuctionClaim> claims) {
|
||||
if (claims == null || claims.isEmpty()) return;
|
||||
for (AuctionClaim claim : claims) {
|
||||
out.add(Entry.forClaim(claim));
|
||||
}
|
||||
}
|
||||
|
||||
private String handleCreateFake(ByteBuf in, EntityPlayerMP player, AuctionController controller) throws IOException {
|
||||
if (!ConfigMarket.AuctionEnabled) {
|
||||
return "Auction is disabled.";
|
||||
}
|
||||
|
||||
String sellerName = ByteBufUtils.readString(in);
|
||||
long startingPrice = in.readLong();
|
||||
long buyoutPrice = in.readLong();
|
||||
int durationHours = in.readInt();
|
||||
NBTTagCompound itemNbt = ByteBufUtils.readNBT(in);
|
||||
|
||||
if (itemNbt == null) {
|
||||
return "No item data received.";
|
||||
}
|
||||
ItemStack item = ItemStack.loadItemStackFromNBT(itemNbt);
|
||||
if (item == null) {
|
||||
return "Invalid item data.";
|
||||
}
|
||||
|
||||
// Consume staged item from admin inventory like normal auction sell flow.
|
||||
if (!removeItemFromInventory(player, item)) {
|
||||
return "Item not found in inventory.";
|
||||
}
|
||||
|
||||
String result = controller.createGlobalListing(player, sellerName, item, startingPrice, buyoutPrice, durationHours);
|
||||
if (result != null) {
|
||||
// Failed create, return item (or drop to avoid loss).
|
||||
if (!player.inventory.addItemStackToInventory(item.copy())) {
|
||||
player.entityDropItem(item.copy(), 0.5f);
|
||||
}
|
||||
}
|
||||
if (result == null) {
|
||||
sendRefresh(player, true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String handleManageListing(ByteBuf in, EntityPlayerMP player, AuctionController controller) throws IOException {
|
||||
String listingId = ByteBufUtils.readString(in);
|
||||
boolean cancelCompletely = in.readBoolean();
|
||||
String result = controller.adminStopListingToGlobal(listingId, player, cancelCompletely);
|
||||
if (result == null) {
|
||||
sendRefresh(player, false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String handleClaimItem(ByteBuf in, EntityPlayerMP player, AuctionController controller) throws IOException {
|
||||
String claimId = ByteBufUtils.readString(in);
|
||||
String result = controller.claimGlobalItem(claimId, player);
|
||||
if (result == null) {
|
||||
sendRefresh(player, false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String handleClaimCurrency(ByteBuf in, EntityPlayerMP player, AuctionController controller) throws IOException {
|
||||
String claimId = ByteBufUtils.readString(in);
|
||||
String result = controller.claimGlobalCurrency(claimId, player);
|
||||
if (result == null) {
|
||||
sendRefresh(player, false);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void handleOpenBidding(ByteBuf in, EntityPlayerMP player, AuctionController controller) throws IOException {
|
||||
String listingId = ByteBufUtils.readString(in);
|
||||
AuctionListing listing = controller.getListing(listingId);
|
||||
if (listing == null || !listing.isActive()) {
|
||||
sendError(player, "Listing not found or has ended.");
|
||||
return;
|
||||
}
|
||||
|
||||
NoppesUtilServer.sendOpenGui(player, EnumGuiType.PlayerAuctionBidding, npc);
|
||||
|
||||
NBTTagCompound response = new NBTTagCompound();
|
||||
response.setBoolean("BiddingData", true);
|
||||
response.setTag("Listing", listing.writeToNBT(new NBTTagCompound()));
|
||||
response.setLong("Balance", controller.getPlayerBalance(player));
|
||||
response.setBoolean("IsOwnListing", listing.isSeller(player.getUniqueID()));
|
||||
GuiDataPacket.sendGuiData(player, response);
|
||||
}
|
||||
|
||||
private void sendError(EntityPlayerMP player, String message) {
|
||||
player.addChatMessage(new net.minecraft.util.ChatComponentText(
|
||||
net.minecraft.util.EnumChatFormatting.RED + "[Global Auction] " + message));
|
||||
}
|
||||
|
||||
private void sendRefresh(EntityPlayerMP player, boolean created) {
|
||||
NBTTagCompound response = new NBTTagCompound();
|
||||
response.setBoolean("ManageAuctionRefresh", true);
|
||||
response.setBoolean("ManageAuctionCreateSuccess", created);
|
||||
GuiDataPacket.sendGuiData(player, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if two ItemStacks are the same type (item, damage, NBT) ignoring stack size.
|
||||
*/
|
||||
private boolean areItemsSameType(ItemStack item1, ItemStack item2) {
|
||||
if (item1 == null || item2 == null)
|
||||
return item1 == item2;
|
||||
if (item1.getItem() != item2.getItem())
|
||||
return false;
|
||||
if (item1.getItemDamage() != item2.getItemDamage())
|
||||
return false;
|
||||
return ItemStack.areItemStackTagsEqual(item1, item2);
|
||||
}
|
||||
|
||||
private int countItemsInInventory(EntityPlayerMP player, ItemStack target) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < player.inventory.mainInventory.length; i++) {
|
||||
ItemStack stack = player.inventory.mainInventory[i];
|
||||
if (stack != null && areItemsSameType(stack, target)) {
|
||||
count += stack.stackSize;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes items from inventory, consuming from multiple stacks if needed.
|
||||
* Returns true if successful, false if not enough items.
|
||||
*/
|
||||
private boolean removeItemFromInventory(EntityPlayerMP player, ItemStack target) {
|
||||
if (target == null) return false;
|
||||
|
||||
int needed = target.stackSize;
|
||||
int available = countItemsInInventory(player, target);
|
||||
if (available < needed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < player.inventory.mainInventory.length && needed > 0; i++) {
|
||||
ItemStack stack = player.inventory.mainInventory[i];
|
||||
if (stack == null || !areItemsSameType(stack, target))
|
||||
continue;
|
||||
|
||||
if (needed >= stack.stackSize) {
|
||||
needed -= stack.stackSize;
|
||||
player.inventory.mainInventory[i] = null;
|
||||
} else {
|
||||
stack.splitStack(needed);
|
||||
if (stack.stackSize <= 0) {
|
||||
player.inventory.setInventorySlotContents(i, null);
|
||||
}
|
||||
needed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
player.inventory.markDirty();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static class Entry {
|
||||
final AuctionClaim claim;
|
||||
final AuctionListing listing;
|
||||
|
||||
private Entry(AuctionClaim claim, AuctionListing listing) {
|
||||
this.claim = claim;
|
||||
this.listing = listing;
|
||||
}
|
||||
|
||||
static Entry forClaim(AuctionClaim claim) {
|
||||
return new Entry(claim, null);
|
||||
}
|
||||
|
||||
static Entry forListing(AuctionListing listing) {
|
||||
return new Entry(null, listing);
|
||||
}
|
||||
}
|
||||
|
||||
private enum Action {
|
||||
REQUEST_LISTINGS,
|
||||
REQUEST_CLAIMS,
|
||||
CREATE_FAKE,
|
||||
MANAGE_LISTING,
|
||||
CLAIM_ITEM,
|
||||
CLAIM_CURRENCY,
|
||||
OPEN_BIDDING
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import noppes.npcs.containers.ContainerCrate;
|
||||
import noppes.npcs.containers.ContainerCustomGui;
|
||||
import noppes.npcs.containers.ContainerMail;
|
||||
import noppes.npcs.containers.ContainerManageBanks;
|
||||
import noppes.npcs.containers.ContainerManageAuction;
|
||||
import noppes.npcs.containers.ContainerManageRecipes;
|
||||
import noppes.npcs.containers.ContainerMerchantAdd;
|
||||
import noppes.npcs.containers.ContainerNPCBankLarge;
|
||||
@@ -136,6 +137,9 @@ public class CommonProxy implements IGuiHandler {
|
||||
if (gui == EnumGuiType.ManageBanks)
|
||||
return new ContainerManageBanks(player);
|
||||
|
||||
if (gui == EnumGuiType.ManageAuction)
|
||||
return new ContainerManageAuction(player);
|
||||
|
||||
if (gui == EnumGuiType.MerchantAdd)
|
||||
return new ContainerMerchantAdd(player, ServerEventsHandler.Merchant, player.worldObj);
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ public class CustomNpcsPermissions {
|
||||
public static final Permission GLOBAL_MAGIC = new Permission("customnpcs.global.magic");
|
||||
public static final Permission GLOBAL_ABILITY = new Permission("customnpcs.global.ability");
|
||||
public static final Permission GLOBAL_EFFECT = new Permission("customnpcs.global.effect");
|
||||
public static final Permission GLOBAL_AUCTION = new Permission("customnpcs.global.auction");
|
||||
|
||||
public static final Permission SPAWNER_MOB = new Permission("customnpcs.spawner.mob");
|
||||
public static final Permission SPAWNER_CREATE = new Permission("customnpcs.spawner.create");
|
||||
|
||||
@@ -117,6 +117,7 @@ import noppes.npcs.client.gui.global.GuiNPCManageQuest;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageTags;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageTransporters;
|
||||
import noppes.npcs.client.gui.global.GuiNpcManageAbilities;
|
||||
import noppes.npcs.client.gui.global.GuiNpcManageAuction;
|
||||
import noppes.npcs.client.gui.global.GuiNpcManageMagic;
|
||||
import noppes.npcs.client.gui.global.GuiNpcManageRecipes;
|
||||
import noppes.npcs.client.gui.global.GuiNpcQuestReward;
|
||||
@@ -219,6 +220,7 @@ import noppes.npcs.containers.ContainerCrate;
|
||||
import noppes.npcs.containers.ContainerCustomGui;
|
||||
import noppes.npcs.containers.ContainerMail;
|
||||
import noppes.npcs.containers.ContainerManageBanks;
|
||||
import noppes.npcs.containers.ContainerManageAuction;
|
||||
import noppes.npcs.containers.ContainerManageRecipes;
|
||||
import noppes.npcs.containers.ContainerNPCBankInterface;
|
||||
import noppes.npcs.containers.ContainerNPCCompanion;
|
||||
@@ -510,6 +512,9 @@ public class ClientProxy extends CommonProxy {
|
||||
else if (gui == EnumGuiType.ManageRecipes)
|
||||
return new GuiNpcManageRecipes(npc, (ContainerManageRecipes) container);
|
||||
|
||||
else if (gui == EnumGuiType.ManageAuction)
|
||||
return new GuiNpcManageAuction(npc, (ContainerManageAuction) container);
|
||||
|
||||
else if (gui == EnumGuiType.ManageDialogs)
|
||||
return new GuiNPCManageDialogs(npc);
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -247,7 +247,7 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
|
||||
NoppesUtil.requestOpenGUI(EnumGuiType.ManageAbilities);
|
||||
}
|
||||
if (id == 22) {
|
||||
// NoppesUtil.requestOpenGUI(EnumGuiType.ManageAuction);
|
||||
NoppesUtil.requestOpenGUI(EnumGuiType.ManageAuction);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,12 @@ import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import noppes.npcs.client.AuctionClientConfig;
|
||||
import noppes.npcs.client.gui.global.GuiNpcManageAuction;
|
||||
import noppes.npcs.constants.EnumClaimType;
|
||||
import noppes.npcs.containers.ContainerAuctionListing;
|
||||
import noppes.npcs.containers.ContainerAuctionSell;
|
||||
import noppes.npcs.containers.ContainerAuctionTrades;
|
||||
import noppes.npcs.containers.ContainerManageAuction;
|
||||
import noppes.npcs.containers.SlotAuctionDisplay;
|
||||
import noppes.npcs.controllers.data.AuctionClaim;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
@@ -49,6 +51,8 @@ public class AuctionTooltipHandler {
|
||||
addTradesTooltip((GuiAuctionTrades) screen, event.itemStack, event.toolTip);
|
||||
} else if (screen instanceof GuiAuctionSell) {
|
||||
addSellTooltip((GuiAuctionSell) screen, event.itemStack, event.toolTip);
|
||||
} else if (screen instanceof GuiNpcManageAuction) {
|
||||
addManageAuctionTooltip((GuiNpcManageAuction) screen, event.itemStack, event.toolTip);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,4 +259,125 @@ public class AuctionTooltipHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// ========== Global Manage Auction ==========
|
||||
|
||||
private static void addManageAuctionTooltip(GuiNpcManageAuction gui, ItemStack stack, List<String> tooltip) {
|
||||
Slot slot = findHoveredSlot(gui, stack);
|
||||
if (slot == null) return;
|
||||
|
||||
ContainerManageAuction container = gui.getManageContainer();
|
||||
if (container == null) return;
|
||||
|
||||
GuiNpcManageAuction.Tab tab = gui.getActiveTab();
|
||||
|
||||
if (tab == GuiNpcManageAuction.Tab.LISTINGS && container.isDisplaySlot(slot.slotNumber)) {
|
||||
int displayIndex = container.toDisplayIndex(slot.slotNumber);
|
||||
AuctionListing listing = container.getListingAtDisplay(displayIndex);
|
||||
if (listing == null) return;
|
||||
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.seller")
|
||||
.replace("%s", EnumChatFormatting.WHITE + listing.sellerName));
|
||||
|
||||
if (listing.hasBids()) {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.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 + AuctionFormatUtil.formatCurrencyWithName(listing.startingPrice)));
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.noBids"));
|
||||
}
|
||||
|
||||
if (listing.hasBuyout()) {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.buyout")
|
||||
.replace("%s", EnumChatFormatting.GREEN + AuctionFormatUtil.formatCurrencyWithName(listing.buyoutPrice)));
|
||||
}
|
||||
|
||||
long timeRemaining = listing.getTimeRemaining();
|
||||
String timeText = StatCollector.translateToLocal("auction.timeLeft")
|
||||
.replace("%s", AuctionFormatUtil.formatTimeRemaining(timeRemaining));
|
||||
tooltip.add((AuctionFormatUtil.isTimeUrgent(timeRemaining) ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
|
||||
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.AQUA + "Left-click: View details");
|
||||
tooltip.add(EnumChatFormatting.GOLD + "Right-click: Stop player");
|
||||
tooltip.add(EnumChatFormatting.LIGHT_PURPLE + "Shift+Right-click: Cancel to global");
|
||||
return;
|
||||
}
|
||||
|
||||
if (tab == GuiNpcManageAuction.Tab.CLAIMS && container.isDisplaySlot(slot.slotNumber)) {
|
||||
int displayIndex = container.toDisplayIndex(slot.slotNumber);
|
||||
AuctionClaim claim = container.getClaimAtDisplay(displayIndex);
|
||||
if (claim != null) {
|
||||
addGlobalClaimTooltip(claim, tooltip);
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionListing listing = container.getListingAtDisplay(displayIndex);
|
||||
if (listing != null) {
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.seller")
|
||||
.replace("%s", EnumChatFormatting.WHITE + listing.sellerName));
|
||||
if (listing.hasBids()) {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.currentBid")
|
||||
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(listing.currentBid)));
|
||||
} else {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.startingPrice")
|
||||
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(listing.startingPrice)));
|
||||
}
|
||||
if (listing.hasBuyout()) {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.buyout")
|
||||
.replace("%s", EnumChatFormatting.GREEN + AuctionFormatUtil.formatCurrencyWithName(listing.buyoutPrice)));
|
||||
}
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.GOLD + "Right-click: Stop player");
|
||||
tooltip.add(EnumChatFormatting.LIGHT_PURPLE + "Shift+Right-click: Cancel to global");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (tab == GuiNpcManageAuction.Tab.CREATE) {
|
||||
if (container.isCreateSlot(slot.slotNumber)) {
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.sell.leftClear"));
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.sell.rightRemove"));
|
||||
} else if (container.isPlayerSlot(slot.slotNumber)) {
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.sell.leftAdd"));
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.sell.rightAddOne"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addGlobalClaimTooltip(AuctionClaim claim, List<String> tooltip) {
|
||||
tooltip.add("");
|
||||
if (claim.type == EnumClaimType.ITEM) {
|
||||
tooltip.add(EnumChatFormatting.AQUA + "Global Item Claim");
|
||||
} else if (claim.type == EnumClaimType.CURRENCY) {
|
||||
tooltip.add(EnumChatFormatting.GOLD + "Global Currency Claim");
|
||||
if (claim.itemName != null && !claim.itemName.isEmpty()) {
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.claim.soldItem")
|
||||
.replace("%s", EnumChatFormatting.WHITE + claim.itemName));
|
||||
}
|
||||
if (claim.otherPlayerName != null && !claim.otherPlayerName.isEmpty()) {
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.claim.buyer")
|
||||
.replace("%s", EnumChatFormatting.WHITE + claim.otherPlayerName));
|
||||
}
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.claim.amount")
|
||||
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(claim.currency)));
|
||||
tooltip.add(EnumChatFormatting.GRAY + "Claiming this does not change your balance.");
|
||||
} else if (claim.type == EnumClaimType.REFUND) {
|
||||
tooltip.add(EnumChatFormatting.RED + "Global Refund Claim");
|
||||
if (claim.otherPlayerName != null && !claim.otherPlayerName.isEmpty()) {
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.claim.outbidBy")
|
||||
.replace("%s", EnumChatFormatting.WHITE + claim.otherPlayerName));
|
||||
}
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.claim.amount")
|
||||
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(claim.currency)));
|
||||
}
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.claim.clickToClaim"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
package noppes.npcs.containers;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.constants.EnumClaimType;
|
||||
import noppes.npcs.controllers.data.AuctionClaim;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Global auction management container.
|
||||
* Uses a 9x5 display grid plus staged/detail slots on the right panel and player inventory below the grid.
|
||||
*/
|
||||
public class ContainerManageAuction extends ContainerNpcInterface {
|
||||
public enum DisplayMode {
|
||||
LISTINGS,
|
||||
CLAIMS
|
||||
}
|
||||
|
||||
public static final int DISPLAY_COLS = 9;
|
||||
public static final int DISPLAY_ROWS = 5;
|
||||
public static final int DISPLAY_SLOT_COUNT = DISPLAY_COLS * DISPLAY_ROWS;
|
||||
|
||||
public static final int DISPLAY_X = 8;
|
||||
public static final int DISPLAY_Y = 16;
|
||||
|
||||
public static final int PLAYER_INV_X = 8;
|
||||
public static final int PLAYER_INV_Y = 113;
|
||||
public static final int HOTBAR_Y = 171;
|
||||
public static final int PLAYER_SLOT_COUNT = 36;
|
||||
|
||||
public static final int CREATE_SLOT_X = 188;
|
||||
public static final int CREATE_SLOT_Y = 156;
|
||||
public static final int DETAIL_SLOT_X = 194;
|
||||
public static final int DETAIL_SLOT_Y = 56;
|
||||
private static final int MAX_STACK = 64;
|
||||
|
||||
public static final int DISPLAY_SLOT_START = 0;
|
||||
public static final int PLAYER_SLOT_START = DISPLAY_SLOT_START + DISPLAY_SLOT_COUNT;
|
||||
public static final int DETAIL_SLOT_INDEX = PLAYER_SLOT_START + PLAYER_SLOT_COUNT;
|
||||
public static final int CREATE_SLOT_INDEX = DETAIL_SLOT_INDEX + 1;
|
||||
|
||||
private static final int HIDDEN_SLOT_X = -1000;
|
||||
private static final int HIDDEN_SLOT_Y = -1000;
|
||||
|
||||
public final InventoryAuctionDisplay displayInventory;
|
||||
private final IInventory detailInventory;
|
||||
private final IInventory createInventory;
|
||||
private DisplayMode displayMode = DisplayMode.LISTINGS;
|
||||
private Slot detailSlot;
|
||||
private Slot createSlot;
|
||||
private int hiddenDisplaySlot = -1;
|
||||
|
||||
public ContainerManageAuction(EntityPlayer player) {
|
||||
super(player);
|
||||
this.player = player;
|
||||
|
||||
displayInventory = new InventoryAuctionDisplay(DISPLAY_SLOT_COUNT);
|
||||
detailInventory = new InventoryBasic("GlobalAuctionDetail", false, 1);
|
||||
createInventory = new InventoryBasic("GlobalAuctionCreate", false, 1);
|
||||
|
||||
// 9x5 display grid (listings / global claims)
|
||||
for (int row = 0; row < DISPLAY_ROWS; row++) {
|
||||
for (int col = 0; col < DISPLAY_COLS; col++) {
|
||||
int slotIndex = col + row * DISPLAY_COLS;
|
||||
int x = DISPLAY_X + col * 18;
|
||||
int y = DISPLAY_Y + row * 18;
|
||||
addSlotToContainer(new SlotAuctionDisplay(displayInventory, slotIndex, x, y));
|
||||
}
|
||||
}
|
||||
|
||||
// Player inventory below display grid
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int col = 0; col < 9; col++) {
|
||||
int playerIndex = col + row * 9 + 9;
|
||||
int x = PLAYER_INV_X + col * 18;
|
||||
int y = PLAYER_INV_Y + row * 18;
|
||||
addSlotToContainer(new Slot(player.inventory, playerIndex, x, y));
|
||||
}
|
||||
}
|
||||
for (int col = 0; col < 9; col++) {
|
||||
int x = PLAYER_INV_X + col * 18;
|
||||
addSlotToContainer(new Slot(player.inventory, col, x, HOTBAR_Y));
|
||||
}
|
||||
|
||||
// Listing details slot (right panel)
|
||||
detailSlot = new SlotAuctionDisplay(detailInventory, 0, DETAIL_SLOT_X, DETAIL_SLOT_Y);
|
||||
addSlotToContainer(detailSlot);
|
||||
|
||||
// Staged fake listing slot
|
||||
createSlot = new Slot(createInventory, 0, CREATE_SLOT_X, CREATE_SLOT_Y) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
addSlotToContainer(createSlot);
|
||||
|
||||
setDetailSlotVisible(false);
|
||||
setCreateSlotVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotIndex, int mouseButton, int mode, EntityPlayer player) {
|
||||
// Block native container interactions. GUI handles all click behaviors.
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setDisplayMode(DisplayMode mode) {
|
||||
this.displayMode = mode != null ? mode : DisplayMode.LISTINGS;
|
||||
}
|
||||
|
||||
public DisplayMode getDisplayMode() {
|
||||
return displayMode;
|
||||
}
|
||||
|
||||
public void clearDisplay() {
|
||||
displayInventory.clear();
|
||||
}
|
||||
|
||||
public void setListingsPage(List<AuctionListing> listings) {
|
||||
displayMode = DisplayMode.LISTINGS;
|
||||
clearHiddenDisplaySlot();
|
||||
displayInventory.clear();
|
||||
if (listings == null) return;
|
||||
|
||||
for (int i = 0; i < listings.size() && i < DISPLAY_SLOT_COUNT; i++) {
|
||||
displayInventory.setListing(i, listings.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void setClaimsPage(List<AuctionClaim> claims) {
|
||||
displayMode = DisplayMode.CLAIMS;
|
||||
clearHiddenDisplaySlot();
|
||||
displayInventory.clear();
|
||||
if (claims == null) return;
|
||||
|
||||
for (int i = 0; i < claims.size() && i < DISPLAY_SLOT_COUNT; i++) {
|
||||
displayInventory.setClaimItem(i, claims.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Claims page can contain both global claims and active global listings.
|
||||
* Order mirrors My Trades:
|
||||
* sold claims, outbid claims, won claims, active listings, expired claims.
|
||||
*/
|
||||
public void setClaimsAndListingsPage(List<AuctionClaim> claims, List<AuctionListing> listings) {
|
||||
displayMode = DisplayMode.CLAIMS;
|
||||
clearHiddenDisplaySlot();
|
||||
displayInventory.clear();
|
||||
|
||||
List<AuctionClaim> soldClaims = new ArrayList<AuctionClaim>();
|
||||
List<AuctionClaim> outbidClaims = new ArrayList<AuctionClaim>();
|
||||
List<AuctionClaim> wonClaims = new ArrayList<AuctionClaim>();
|
||||
List<AuctionClaim> expiredClaims = new ArrayList<AuctionClaim>();
|
||||
if (claims != null) {
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (claim == null) continue;
|
||||
if (claim.type == EnumClaimType.CURRENCY) {
|
||||
soldClaims.add(claim);
|
||||
} else if (claim.type == EnumClaimType.REFUND) {
|
||||
outbidClaims.add(claim);
|
||||
} else if (claim.type == EnumClaimType.ITEM) {
|
||||
if (claim.isReturned) {
|
||||
expiredClaims.add(claim);
|
||||
} else {
|
||||
wonClaims.add(claim);
|
||||
}
|
||||
} else {
|
||||
wonClaims.add(claim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int slot = 0;
|
||||
slot = fillClaims(slot, soldClaims);
|
||||
slot = fillClaims(slot, outbidClaims);
|
||||
slot = fillClaims(slot, wonClaims);
|
||||
|
||||
if (listings != null) {
|
||||
for (int i = 0; i < listings.size() && slot < DISPLAY_SLOT_COUNT; i++) {
|
||||
displayInventory.setListing(slot, listings.get(i));
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
|
||||
fillClaims(slot, expiredClaims);
|
||||
}
|
||||
|
||||
private int fillClaims(int slot, List<AuctionClaim> claims) {
|
||||
if (claims == null) return slot;
|
||||
for (int i = 0; i < claims.size() && slot < DISPLAY_SLOT_COUNT; i++) {
|
||||
displayInventory.setClaimItem(slot, claims.get(i));
|
||||
slot++;
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
|
||||
public boolean isDisplaySlot(int containerSlotIndex) {
|
||||
return containerSlotIndex >= DISPLAY_SLOT_START && containerSlotIndex < DISPLAY_SLOT_START + DISPLAY_SLOT_COUNT;
|
||||
}
|
||||
|
||||
public int toDisplayIndex(int containerSlotIndex) {
|
||||
if (!isDisplaySlot(containerSlotIndex)) return -1;
|
||||
return containerSlotIndex - DISPLAY_SLOT_START;
|
||||
}
|
||||
|
||||
public AuctionListing getListingAtDisplay(int displayIndex) {
|
||||
if (displayIndex < 0 || displayIndex >= DISPLAY_SLOT_COUNT) return null;
|
||||
return displayInventory.getListing(displayIndex);
|
||||
}
|
||||
|
||||
public AuctionClaim getClaimAtDisplay(int displayIndex) {
|
||||
if (displayIndex < 0 || displayIndex >= DISPLAY_SLOT_COUNT) return null;
|
||||
return displayInventory.getClaim(displayIndex);
|
||||
}
|
||||
|
||||
public boolean isPlayerSlot(int containerSlotIndex) {
|
||||
return containerSlotIndex >= PLAYER_SLOT_START && containerSlotIndex < PLAYER_SLOT_START + PLAYER_SLOT_COUNT;
|
||||
}
|
||||
|
||||
public boolean isCreateSlot(int containerSlotIndex) {
|
||||
return containerSlotIndex == CREATE_SLOT_INDEX;
|
||||
}
|
||||
|
||||
public boolean isDetailSlot(int containerSlotIndex) {
|
||||
return containerSlotIndex == DETAIL_SLOT_INDEX;
|
||||
}
|
||||
|
||||
public void setDetailItem(ItemStack stack) {
|
||||
detailInventory.setInventorySlotContents(0, stack != null ? stack.copy() : null);
|
||||
}
|
||||
|
||||
public void clearDetailItem() {
|
||||
detailInventory.setInventorySlotContents(0, null);
|
||||
}
|
||||
|
||||
public void setDetailSlotVisible(boolean visible) {
|
||||
if (detailSlot == null) return;
|
||||
detailSlot.xDisplayPosition = visible ? DETAIL_SLOT_X : HIDDEN_SLOT_X;
|
||||
detailSlot.yDisplayPosition = visible ? DETAIL_SLOT_Y : HIDDEN_SLOT_Y;
|
||||
}
|
||||
|
||||
public void setCreateSlotVisible(boolean visible) {
|
||||
if (createSlot == null) return;
|
||||
createSlot.xDisplayPosition = visible ? CREATE_SLOT_X : HIDDEN_SLOT_X;
|
||||
createSlot.yDisplayPosition = visible ? CREATE_SLOT_Y : HIDDEN_SLOT_Y;
|
||||
}
|
||||
|
||||
public void setHiddenDisplaySlot(int displayIndex) {
|
||||
if (displayIndex < 0 || displayIndex >= DISPLAY_SLOT_COUNT) {
|
||||
clearHiddenDisplaySlot();
|
||||
return;
|
||||
}
|
||||
if (hiddenDisplaySlot == displayIndex) return;
|
||||
|
||||
clearHiddenDisplaySlot();
|
||||
hiddenDisplaySlot = displayIndex;
|
||||
displayInventory.setInventorySlotContents(displayIndex, null);
|
||||
}
|
||||
|
||||
public void clearHiddenDisplaySlot() {
|
||||
if (hiddenDisplaySlot < 0 || hiddenDisplaySlot >= DISPLAY_SLOT_COUNT) {
|
||||
hiddenDisplaySlot = -1;
|
||||
return;
|
||||
}
|
||||
restoreDisplaySlot(hiddenDisplaySlot);
|
||||
hiddenDisplaySlot = -1;
|
||||
}
|
||||
|
||||
public int getHiddenDisplaySlot() {
|
||||
return hiddenDisplaySlot;
|
||||
}
|
||||
|
||||
private void restoreDisplaySlot(int displayIndex) {
|
||||
if (displayIndex < 0 || displayIndex >= DISPLAY_SLOT_COUNT) return;
|
||||
|
||||
AuctionClaim claim = displayInventory.getClaim(displayIndex);
|
||||
if (claim != null) {
|
||||
displayInventory.setClaimItem(displayIndex, claim);
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionListing listing = displayInventory.getListing(displayIndex);
|
||||
if (listing != null) {
|
||||
displayInventory.setListing(displayIndex, listing);
|
||||
return;
|
||||
}
|
||||
|
||||
displayInventory.setInventorySlotContents(displayIndex, null);
|
||||
}
|
||||
|
||||
public ItemStack getCreateItem() {
|
||||
return createInventory.getStackInSlot(0);
|
||||
}
|
||||
|
||||
public void clearCreateSlot() {
|
||||
createInventory.setInventorySlotContents(0, null);
|
||||
}
|
||||
|
||||
public void addToCreateSlot(int containerPlayerSlot, boolean fullStack) {
|
||||
if (!isPlayerSlot(containerPlayerSlot)) return;
|
||||
|
||||
Slot slot = (Slot) inventorySlots.get(containerPlayerSlot);
|
||||
if (slot == null) return;
|
||||
ItemStack source = slot.getStack();
|
||||
if (source == null) return;
|
||||
|
||||
ItemStack staged = createInventory.getStackInSlot(0);
|
||||
int toAdd = fullStack ? source.stackSize : 1;
|
||||
|
||||
if (staged == null) {
|
||||
ItemStack copy = source.copy();
|
||||
copy.stackSize = Math.min(MAX_STACK, toAdd);
|
||||
createInventory.setInventorySlotContents(0, copy);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!itemsMatch(staged, source)) {
|
||||
ItemStack copy = source.copy();
|
||||
copy.stackSize = Math.min(MAX_STACK, toAdd);
|
||||
createInventory.setInventorySlotContents(0, copy);
|
||||
return;
|
||||
}
|
||||
|
||||
int space = MAX_STACK - staged.stackSize;
|
||||
int add = Math.min(space, toAdd);
|
||||
if (add > 0) {
|
||||
staged.stackSize += add;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFromCreateSlot(boolean removeAll) {
|
||||
ItemStack staged = createInventory.getStackInSlot(0);
|
||||
if (staged == null) return;
|
||||
|
||||
if (removeAll || staged.stackSize <= 1) {
|
||||
createInventory.setInventorySlotContents(0, null);
|
||||
} else {
|
||||
staged.stackSize--;
|
||||
}
|
||||
}
|
||||
|
||||
public int countItemInPlayerInventory(ItemStack target) {
|
||||
if (target == null || player == null || player.inventory == null) return 0;
|
||||
int total = 0;
|
||||
for (int i = 0; i < player.inventory.mainInventory.length; i++) {
|
||||
ItemStack stack = player.inventory.mainInventory[i];
|
||||
if (stack != null && itemsMatch(target, stack)) {
|
||||
total += stack.stackSize;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private boolean itemsMatch(ItemStack a, ItemStack b) {
|
||||
return NoppesUtilPlayer.compareItems(a, b, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer player) {
|
||||
super.onContainerClosed(player);
|
||||
clearHiddenDisplaySlot();
|
||||
clearDetailItem();
|
||||
clearCreateSlot();
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
@@ -63,7 +64,8 @@ public class AuctionController implements IAuctionHandler {
|
||||
|
||||
// Main data stores - listings only, claims are stored in PlayerData
|
||||
private final Map<String, AuctionListing> listings = new ConcurrentHashMap<>();
|
||||
// Claims are now stored in PlayerData.tradeData, not here
|
||||
// Shared global claims for admin-managed auction actions
|
||||
private final List<AuctionClaim> globalClaims = new CopyOnWriteArrayList<>();
|
||||
|
||||
// =========================================
|
||||
// Player Indices for O(1) Lookups
|
||||
@@ -163,9 +165,12 @@ public class AuctionController implements IAuctionHandler {
|
||||
if (listing.status != EnumAuctionStatus.ACTIVE) return;
|
||||
|
||||
listing.status = EnumAuctionStatus.ENDED;
|
||||
boolean isGlobalListing = listing.isGlobalListing;
|
||||
|
||||
// Remove from seller's active listings
|
||||
removeFromPlayerListings(listing.sellerUUID, listing.id);
|
||||
if (!isGlobalListing && listing.sellerUUID != null) {
|
||||
removeFromPlayerListings(listing.sellerUUID, listing.id);
|
||||
}
|
||||
|
||||
// Remove from bidder's active bids if any
|
||||
if (listing.highBidderUUID != null) {
|
||||
@@ -188,26 +193,38 @@ public class AuctionController implements IAuctionHandler {
|
||||
AuctionClaim currencyClaim = AuctionClaim.createCurrencyClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, sellerReceives,
|
||||
itemDisplayName, listing.highBidderName);
|
||||
addClaimToPlayer(listing.sellerUUID, currencyClaim);
|
||||
if (isGlobalListing) {
|
||||
addGlobalClaim(currencyClaim);
|
||||
} else {
|
||||
addClaimToPlayer(listing.sellerUUID, currencyClaim);
|
||||
}
|
||||
|
||||
// Notifications
|
||||
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_WON, listing.id,
|
||||
"You won the auction for " + itemDisplayName + "!");
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
|
||||
"Your " + itemDisplayName + " sold for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
|
||||
if (!isGlobalListing && listing.sellerUUID != null) {
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
|
||||
"Your " + itemDisplayName + " sold for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
|
||||
}
|
||||
|
||||
logAuction(EnumAuctionLogAction.SOLD, listing.sellerName, itemDisplayName, saleAmount,
|
||||
"Winner: " + listing.highBidderName + ", Tax: " + tax);
|
||||
"Winner: " + listing.highBidderName + ", Tax: " + tax + (isGlobalListing ? ", Global listing" : ""));
|
||||
} else {
|
||||
// No bids - return item to seller
|
||||
// No bids - return item to seller/global claims
|
||||
AuctionClaim returnClaim = AuctionClaim.createItemReturnedClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
|
||||
addClaimToPlayer(listing.sellerUUID, returnClaim);
|
||||
if (isGlobalListing) {
|
||||
addGlobalClaim(returnClaim);
|
||||
} else {
|
||||
addClaimToPlayer(listing.sellerUUID, returnClaim);
|
||||
if (listing.sellerUUID != null) {
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_EXPIRED, listing.id,
|
||||
"Your auction for " + itemDisplayName + " expired with no bids.");
|
||||
}
|
||||
}
|
||||
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_EXPIRED, listing.id,
|
||||
"Your auction for " + itemDisplayName + " expired with no bids.");
|
||||
|
||||
logAuction(EnumAuctionLogAction.EXPIRED, listing.sellerName, itemDisplayName, listing.startingPrice, "No bids");
|
||||
logAuction(EnumAuctionLogAction.EXPIRED, listing.sellerName, itemDisplayName, listing.startingPrice,
|
||||
"No bids" + (isGlobalListing ? ", Global listing" : ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,10 +234,12 @@ public class AuctionController implements IAuctionHandler {
|
||||
// =========================================
|
||||
|
||||
private void addToPlayerListings(UUID playerUUID, String listingId) {
|
||||
if (playerUUID == null || listingId == null || listingId.isEmpty()) return;
|
||||
playerListingIds.computeIfAbsent(playerUUID, k -> ConcurrentHashMap.newKeySet()).add(listingId);
|
||||
}
|
||||
|
||||
private void removeFromPlayerListings(UUID playerUUID, String listingId) {
|
||||
if (playerUUID == null || listingId == null || listingId.isEmpty()) return;
|
||||
Set<String> ids = playerListingIds.get(playerUUID);
|
||||
if (ids != null) {
|
||||
ids.remove(listingId);
|
||||
@@ -231,10 +250,12 @@ public class AuctionController implements IAuctionHandler {
|
||||
}
|
||||
|
||||
private void addToPlayerBids(UUID playerUUID, String listingId) {
|
||||
if (playerUUID == null || listingId == null || listingId.isEmpty()) return;
|
||||
playerBidIds.computeIfAbsent(playerUUID, k -> ConcurrentHashMap.newKeySet()).add(listingId);
|
||||
}
|
||||
|
||||
private void removeFromPlayerBids(UUID playerUUID, String listingId) {
|
||||
if (playerUUID == null || listingId == null || listingId.isEmpty()) return;
|
||||
Set<String> ids = playerBidIds.get(playerUUID);
|
||||
if (ids != null) {
|
||||
ids.remove(listingId);
|
||||
@@ -259,6 +280,70 @@ public class AuctionController implements IAuctionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a claim to the global admin claims pool.
|
||||
*/
|
||||
private void addGlobalClaim(AuctionClaim claim) {
|
||||
if (claim == null || claim.claimed) return;
|
||||
|
||||
// Global claims are not tied to a single player.
|
||||
claim.playerUUID = null;
|
||||
claim.playerName = "Global";
|
||||
globalClaims.add(claim);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
private List<AuctionClaim> getGlobalClaimsSnapshot() {
|
||||
List<AuctionClaim> result = new ArrayList<>();
|
||||
for (AuctionClaim claim : globalClaims) {
|
||||
if (claim != null && !claim.claimed) {
|
||||
result.add(claim);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private AuctionClaim getGlobalClaimInternal(String claimId) {
|
||||
if (claimId == null || claimId.isEmpty()) return null;
|
||||
for (AuctionClaim claim : globalClaims) {
|
||||
if (claim != null && !claim.claimed && claimId.equals(claim.id)) {
|
||||
return claim;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean claimAndRemoveGlobal(String claimId) {
|
||||
AuctionClaim claim = getGlobalClaimInternal(claimId);
|
||||
if (claim == null) return false;
|
||||
claim.claimed = true;
|
||||
return globalClaims.remove(claim);
|
||||
}
|
||||
|
||||
/**
|
||||
* Full list of unclaimed global claims sorted newest-first.
|
||||
*/
|
||||
public List<AuctionClaim> getAllGlobalClaims() {
|
||||
List<AuctionClaim> snapshot = getGlobalClaimsSnapshot();
|
||||
snapshot.sort((a, b) -> Long.compare(b.createdTime, a.createdTime));
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Full list of active global listings sorted newest-first.
|
||||
*/
|
||||
public List<AuctionListing> getActiveGlobalListings() {
|
||||
List<AuctionListing> result = new ArrayList<>();
|
||||
for (AuctionListing listing : listings.values()) {
|
||||
if (listing == null) continue;
|
||||
if (!listing.isGlobalListing) continue;
|
||||
if (!listing.isActive()) continue;
|
||||
result.add(listing);
|
||||
}
|
||||
result.sort((a, b) -> Long.compare(b.createdTime, a.createdTime));
|
||||
return result;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Listing Management
|
||||
// =========================================
|
||||
@@ -335,12 +420,57 @@ public class AuctionController implements IAuctionHandler {
|
||||
return null; // Success
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fake/global listing managed through the global auction admin GUI.
|
||||
* Global listings do not consume player currency and route proceeds to global claims.
|
||||
*/
|
||||
public String createGlobalListing(EntityPlayer admin, String sellerName, ItemStack item, long startingPrice, long buyoutPrice, int durationHours) {
|
||||
if (!ConfigMarket.AuctionEnabled) {
|
||||
return "Auction is disabled.";
|
||||
}
|
||||
if (admin == null) {
|
||||
return "Admin is missing.";
|
||||
}
|
||||
if (item == null) {
|
||||
return "No item provided.";
|
||||
}
|
||||
|
||||
if (startingPrice < ConfigMarket.MinimumListingPrice) {
|
||||
return "Starting price must be at least " + ConfigMarket.MinimumListingPrice + " " + ConfigMarket.CurrencyName + ".";
|
||||
}
|
||||
if (buyoutPrice > 0 && buyoutPrice < startingPrice) {
|
||||
return "Buyout price must be higher than starting price.";
|
||||
}
|
||||
|
||||
String cleanSeller = sellerName != null ? sellerName.trim() : "";
|
||||
if (cleanSeller.isEmpty()) {
|
||||
cleanSeller = "Server";
|
||||
}
|
||||
|
||||
int hours = durationHours > 0 ? durationHours : ConfigMarket.AuctionDurationHours;
|
||||
long durationMs = hours * 60L * 60L * 1000L;
|
||||
|
||||
// Global listings do not belong to a player UUID, only to the global pool.
|
||||
AuctionListing listing = new AuctionListing(null, cleanSeller, item, startingPrice, buyoutPrice, durationMs);
|
||||
listing.isGlobalListing = true;
|
||||
listings.put(listing.id, listing);
|
||||
markDirty();
|
||||
|
||||
logAuction(EnumAuctionLogAction.CREATED, admin.getCommandSenderName(), item.getDisplayName(), startingPrice,
|
||||
"Global listing, Seller: " + cleanSeller + ", Buyout: " + (buyoutPrice > 0 ? buyoutPrice : "None") + ", DurationHours: " + hours);
|
||||
return null;
|
||||
}
|
||||
|
||||
public String cancelListing(String listingId, EntityPlayer player, boolean isAdmin) {
|
||||
AuctionListing listing = listings.get(listingId);
|
||||
if (listing == null) {
|
||||
return "Listing not found.";
|
||||
}
|
||||
|
||||
if (isAdmin && listing.isGlobalListing) {
|
||||
return adminStopListingToGlobal(listingId, player, true);
|
||||
}
|
||||
|
||||
synchronized (listing) {
|
||||
if (!listing.status.canCancel()) {
|
||||
return "This auction cannot be cancelled.";
|
||||
@@ -616,14 +746,22 @@ public class AuctionController implements IAuctionHandler {
|
||||
AuctionClaim currencyClaim = AuctionClaim.createCurrencyClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, sellerReceives,
|
||||
listing.item.getDisplayName(), playerName);
|
||||
addClaimToPlayer(listing.sellerUUID, currencyClaim);
|
||||
if (listing.isGlobalListing) {
|
||||
addGlobalClaim(currencyClaim);
|
||||
} else {
|
||||
addClaimToPlayer(listing.sellerUUID, currencyClaim);
|
||||
}
|
||||
|
||||
// Notifications
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
|
||||
"Your " + listing.item.getDisplayName() + " was bought out for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
|
||||
if (!listing.isGlobalListing && listing.sellerUUID != null) {
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
|
||||
"Your " + listing.item.getDisplayName() + " was bought out for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
|
||||
}
|
||||
|
||||
// Remove from seller's active listings
|
||||
removeFromPlayerListings(listing.sellerUUID, listing.id);
|
||||
if (!listing.isGlobalListing && listing.sellerUUID != null) {
|
||||
removeFromPlayerListings(listing.sellerUUID, listing.id);
|
||||
}
|
||||
|
||||
listing.status = EnumAuctionStatus.ENDED;
|
||||
listing.highBidderUUID = playerUUID;
|
||||
@@ -633,7 +771,7 @@ public class AuctionController implements IAuctionHandler {
|
||||
markDirty();
|
||||
|
||||
logAuction(EnumAuctionLogAction.BUYOUT, playerName, listing.item.getDisplayName(), listing.buyoutPrice,
|
||||
"Seller: " + listing.sellerName + ", Tax: " + tax);
|
||||
"Seller: " + listing.sellerName + ", Tax: " + tax + (listing.isGlobalListing ? ", Global listing" : ""));
|
||||
}
|
||||
|
||||
return null; // Success
|
||||
@@ -665,6 +803,77 @@ public class AuctionController implements IAuctionHandler {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Paginated global claims used by the global auction admin GUI.
|
||||
*/
|
||||
public List<AuctionClaim> getGlobalClaims(int page, int pageSize) {
|
||||
List<AuctionClaim> snapshot = getGlobalClaimsSnapshot();
|
||||
snapshot.sort((a, b) -> Long.compare(b.createdTime, a.createdTime));
|
||||
|
||||
int safePage = Math.max(0, page);
|
||||
int safePageSize = Math.max(1, pageSize);
|
||||
int start = safePage * safePageSize;
|
||||
if (start >= snapshot.size()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
int end = Math.min(start + safePageSize, snapshot.size());
|
||||
return new ArrayList<>(snapshot.subList(start, end));
|
||||
}
|
||||
|
||||
public int getTotalGlobalClaims() {
|
||||
return getGlobalClaimsSnapshot().size();
|
||||
}
|
||||
|
||||
public boolean hasGlobalClaims() {
|
||||
return getTotalGlobalClaims() > 0;
|
||||
}
|
||||
|
||||
public String claimGlobalItem(String claimId, EntityPlayer player) {
|
||||
AuctionClaim claim = getGlobalClaimInternal(claimId);
|
||||
if (claim == null) {
|
||||
return "Global claim not found.";
|
||||
}
|
||||
if (!claim.type.isItem()) {
|
||||
return "This global claim is not an item claim.";
|
||||
}
|
||||
if (claim.item == null) {
|
||||
return "Item data is missing.";
|
||||
}
|
||||
|
||||
if (!player.inventory.addItemStackToInventory(claim.item.copy())) {
|
||||
return "Your inventory is full.";
|
||||
}
|
||||
|
||||
claimAndRemoveGlobal(claim.id);
|
||||
cleanupListingIfComplete(claim.listingId);
|
||||
markDirty();
|
||||
|
||||
logAuction(EnumAuctionLogAction.CLAIMED, player.getCommandSenderName(), claim.item.getDisplayName(), 0,
|
||||
"Global item claim");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Global currency claims are acknowledged/cleared and do not alter player balances.
|
||||
*/
|
||||
public String claimGlobalCurrency(String claimId, EntityPlayer player) {
|
||||
AuctionClaim claim = getGlobalClaimInternal(claimId);
|
||||
if (claim == null) {
|
||||
return "Global claim not found.";
|
||||
}
|
||||
if (!claim.type.isCurrency()) {
|
||||
return "This global claim is not a currency claim.";
|
||||
}
|
||||
|
||||
claimAndRemoveGlobal(claim.id);
|
||||
cleanupListingIfComplete(claim.listingId);
|
||||
markDirty();
|
||||
|
||||
logAuction(EnumAuctionLogAction.CLAIMED, player.getCommandSenderName(), ConfigMarket.CurrencyName, claim.currency,
|
||||
"Global currency claim acknowledged (no balance change)");
|
||||
return null;
|
||||
}
|
||||
|
||||
public String claimItem(String claimId, EntityPlayer player) {
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
if (playerData == null) {
|
||||
@@ -1119,6 +1328,30 @@ public class AuctionController implements IAuctionHandler {
|
||||
|
||||
player.addChatMessage(new ChatComponentText(msg.toString()));
|
||||
}
|
||||
|
||||
// Notify admins with permission about pending global claims.
|
||||
if (CustomNpcsPermissions.hasCustomPermission(player, "customnpcs.global.auction")) {
|
||||
List<AuctionClaim> global = getGlobalClaimsSnapshot();
|
||||
if (!global.isEmpty()) {
|
||||
int itemClaims = 0;
|
||||
int currencyClaims = 0;
|
||||
for (AuctionClaim claim : global) {
|
||||
if (claim.type.isItem()) {
|
||||
itemClaims++;
|
||||
} else {
|
||||
currencyClaims++;
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append(EnumChatFormatting.GOLD).append("[Auction] ");
|
||||
msg.append(EnumChatFormatting.AQUA).append("Global claims available: ");
|
||||
msg.append(EnumChatFormatting.GREEN).append(itemClaims).append(" item claim(s)");
|
||||
msg.append(EnumChatFormatting.GRAY).append(", ");
|
||||
msg.append(EnumChatFormatting.YELLOW).append(currencyClaims).append(" currency claim(s)");
|
||||
player.addChatMessage(new ChatComponentText(msg.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onPlayerLogout(UUID playerUUID) {
|
||||
@@ -1228,6 +1461,7 @@ public class AuctionController implements IAuctionHandler {
|
||||
|
||||
public void load() {
|
||||
listings.clear();
|
||||
globalClaims.clear();
|
||||
playerListingIds.clear();
|
||||
playerBidIds.clear();
|
||||
|
||||
@@ -1270,7 +1504,9 @@ public class AuctionController implements IAuctionHandler {
|
||||
// Index listings
|
||||
for (AuctionListing listing : listings.values()) {
|
||||
if (listing.status == EnumAuctionStatus.ACTIVE) {
|
||||
addToPlayerListings(listing.sellerUUID, listing.id);
|
||||
if (!listing.isGlobalListing && listing.sellerUUID != null) {
|
||||
addToPlayerListings(listing.sellerUUID, listing.id);
|
||||
}
|
||||
if (listing.highBidderUUID != null) {
|
||||
addToPlayerBids(listing.highBidderUUID, listing.id);
|
||||
}
|
||||
@@ -1291,22 +1527,42 @@ public class AuctionController implements IAuctionHandler {
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
// Listings only - claims are stored in PlayerData
|
||||
// Listings + global claims (player claims are stored in PlayerData)
|
||||
NBTTagList listingsList = new NBTTagList();
|
||||
for (AuctionListing listing : listings.values()) {
|
||||
listingsList.appendTag(listing.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
compound.setTag("Listings", listingsList);
|
||||
|
||||
NBTTagList globalClaimsList = new NBTTagList();
|
||||
for (AuctionClaim claim : globalClaims) {
|
||||
if (claim != null && !claim.claimed) {
|
||||
globalClaimsList.appendTag(claim.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
compound.setTag("GlobalClaims", globalClaimsList);
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
globalClaims.clear();
|
||||
|
||||
NBTTagList listingsList = compound.getTagList("Listings", 10);
|
||||
for (int i = 0; i < listingsList.tagCount(); i++) {
|
||||
AuctionListing listing = AuctionListing.fromNBT(listingsList.getCompoundTagAt(i));
|
||||
listings.put(listing.id, listing);
|
||||
}
|
||||
|
||||
if (compound.hasKey("GlobalClaims")) {
|
||||
NBTTagList claimsList = compound.getTagList("GlobalClaims", 10);
|
||||
for (int i = 0; i < claimsList.tagCount(); i++) {
|
||||
AuctionClaim claim = AuctionClaim.fromNBT(claimsList.getCompoundTagAt(i));
|
||||
if (!claim.claimed) {
|
||||
globalClaims.add(claim);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================
|
||||
@@ -1473,10 +1729,77 @@ public class AuctionController implements IAuctionHandler {
|
||||
return new ArrayList<>(listings.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin management flow for listings.
|
||||
* cancelCompletely=false: stop listing and return assets to the original owners' claim pools.
|
||||
* cancelCompletely=true: cancel listing and route assets to global claims.
|
||||
*/
|
||||
public String adminStopListingToGlobal(String listingId, EntityPlayer admin, boolean cancelCompletely) {
|
||||
AuctionListing listing = listings.get(listingId);
|
||||
if (listing == null) {
|
||||
return "Listing not found.";
|
||||
}
|
||||
if (admin == null) {
|
||||
return "Admin player is missing.";
|
||||
}
|
||||
|
||||
synchronized (listing) {
|
||||
if (!listing.status.canCancel()) {
|
||||
return "This auction cannot be managed.";
|
||||
}
|
||||
|
||||
String itemName = listing.item != null ? listing.item.getDisplayName() : "Unknown Item";
|
||||
|
||||
// Return active highest bid.
|
||||
if (listing.hasBids() && listing.highBidderUUID != null) {
|
||||
AuctionClaim refundClaim;
|
||||
if (cancelCompletely) {
|
||||
refundClaim = AuctionClaim.createRefundClaim(
|
||||
null, "Global", listing.id, listing.currentBid, itemName,
|
||||
listing.highBidderName, null);
|
||||
addGlobalClaim(refundClaim);
|
||||
} else {
|
||||
refundClaim = AuctionClaim.createRefundClaim(
|
||||
listing.highBidderUUID, listing.highBidderName, listing.id, listing.currentBid, itemName,
|
||||
listing.sellerName, null);
|
||||
addClaimToPlayer(listing.highBidderUUID, refundClaim);
|
||||
}
|
||||
removeFromPlayerBids(listing.highBidderUUID, listing.id);
|
||||
}
|
||||
|
||||
// Return the listed item.
|
||||
if (listing.item != null) {
|
||||
AuctionClaim itemClaim;
|
||||
if (cancelCompletely || listing.sellerUUID == null) {
|
||||
itemClaim = AuctionClaim.createItemReturnedClaim(
|
||||
null, "Global", listing.id, listing.item);
|
||||
addGlobalClaim(itemClaim);
|
||||
} else {
|
||||
itemClaim = AuctionClaim.createItemReturnedClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
|
||||
addClaimToPlayer(listing.sellerUUID, itemClaim);
|
||||
}
|
||||
}
|
||||
|
||||
if (!listing.isGlobalListing && listing.sellerUUID != null) {
|
||||
removeFromPlayerListings(listing.sellerUUID, listing.id);
|
||||
}
|
||||
|
||||
listing.status = cancelCompletely ? EnumAuctionStatus.CANCELLED : EnumAuctionStatus.ENDED;
|
||||
markDirty();
|
||||
|
||||
logAuction(EnumAuctionLogAction.CANCELLED, admin.getCommandSenderName(), itemName, listing.currentBid,
|
||||
(cancelCompletely ? "Admin cancelled to global claims" : "Admin stopped to owner claims") +
|
||||
", OriginalSeller: " + listing.sellerName);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void adminCancelListing(String listingId, EntityPlayer admin, String reason) {
|
||||
AuctionListing listing = listings.get(listingId);
|
||||
String itemName = listing != null && listing.item != null ? listing.item.getDisplayName() : "Unknown";
|
||||
cancelListing(listingId, admin, true);
|
||||
adminStopListingToGlobal(listingId, admin, true);
|
||||
if (reason != null && !reason.isEmpty()) {
|
||||
logAuction(EnumAuctionLogAction.CANCELLED, admin.getCommandSenderName(), itemName, 0, "Admin cancel - Reason: " + reason);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
public long createdTime;
|
||||
public long endTime;
|
||||
public EnumAuctionStatus status;
|
||||
public boolean isGlobalListing;
|
||||
|
||||
public AuctionListing() {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
@@ -31,6 +32,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
this.bidCount = 0;
|
||||
this.currentBid = 0;
|
||||
this.createdTime = System.currentTimeMillis();
|
||||
this.isGlobalListing = false;
|
||||
}
|
||||
|
||||
public AuctionListing(UUID sellerUUID, String sellerName, ItemStack item, long startingPrice, long buyoutPrice, long durationMs) {
|
||||
@@ -228,6 +230,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
compound.setLong("CreatedTime", createdTime);
|
||||
compound.setLong("EndTime", endTime);
|
||||
compound.setInteger("Status", status.ordinal());
|
||||
compound.setBoolean("IsGlobalListing", isGlobalListing);
|
||||
|
||||
return compound;
|
||||
}
|
||||
@@ -255,6 +258,7 @@ public class AuctionListing implements IAuctionListing {
|
||||
createdTime = compound.getLong("CreatedTime");
|
||||
endTime = compound.getLong("EndTime");
|
||||
status = EnumAuctionStatus.fromOrdinal(compound.getInteger("Status"));
|
||||
isGlobalListing = compound.getBoolean("IsGlobalListing");
|
||||
}
|
||||
|
||||
public static AuctionListing fromNBT(NBTTagCompound compound) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.gui.global.GuiNpcManageAuction;
|
||||
import noppes.npcs.client.gui.player.GuiAuctionInterface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -31,7 +32,7 @@ public abstract class MixinItemStack {
|
||||
@Inject(method = "getTooltip", at = @At("TAIL"), cancellable = true)
|
||||
public void getAttributeTooltip(EntityPlayer player, boolean advanced, CallbackInfoReturnable<List<String>> cir) {
|
||||
boolean override = false;
|
||||
if (Minecraft.getMinecraft().currentScreen instanceof GuiAuctionInterface) {
|
||||
if (Minecraft.getMinecraft().currentScreen instanceof GuiAuctionInterface || Minecraft.getMinecraft().currentScreen instanceof GuiNpcManageAuction) {
|
||||
override = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user