mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 19:42:19 +00:00
Merge branch 'dev' into syntax-highlighter-unified
This commit is contained in:
commit
39a43a339b
78 files changed
+4554
-1446
No files matched your search
@@ -24,6 +24,7 @@ import kamkeel.npcs.command.profile.CommandProfile;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.TelegraphController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.profile.CNPCData;
|
||||
import kamkeel.npcs.developer.Developer;
|
||||
@@ -331,7 +332,7 @@ public class CustomNpcs {
|
||||
new AnimationController();
|
||||
new AbilityController();
|
||||
AbilityController.Instance.load();
|
||||
|
||||
TelegraphController.init();
|
||||
|
||||
LinkedItemController.getInstance().load();
|
||||
|
||||
|
||||
@@ -110,6 +110,9 @@ public class CustomNpcsPermissions {
|
||||
public static final Permission PROFILE_REGION_BYPASS = new Permission("customnpcs.profile.region-bypass");
|
||||
public static final Permission PROFILE_MAX = new Permission("customnpcs.profile.max.*");
|
||||
|
||||
// Auction
|
||||
public static final Permission AUCTION_TRADES_MAX = new Permission("customnpcs.auction.trades.*");
|
||||
|
||||
public static CustomNpcsPermissions Instance;
|
||||
private Method hasPermission;
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package noppes.npcs;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.packets.data.ability.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.TelegraphSpawnPacket;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphSpawnPacket;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
@@ -68,6 +68,11 @@ public class ServerTickHandler {
|
||||
playerData.onLogout();
|
||||
}
|
||||
|
||||
// Clear auction permission cache on logout
|
||||
if (AuctionController.Instance != null) {
|
||||
AuctionController.Instance.onPlayerLogout(event.player.getUniqueID());
|
||||
}
|
||||
|
||||
// Save and unload the player's profile data on logout
|
||||
ProfileController.Instance.logout(event.player);
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
public class AuctionClientConfig {
|
||||
// Cached values from server
|
||||
private static long listingFee = 0;
|
||||
private static String currencyName = "Gold";
|
||||
private static int auctionDurationHours = 48;
|
||||
private static String currencyName = "Coins";
|
||||
private static int auctionDurationHours = 24;
|
||||
private static double minBidIncrement = 0.05;
|
||||
private static int maxActiveListings = 10;
|
||||
private static int claimExpirationDays = 30;
|
||||
private static int maxActiveListings = 8;
|
||||
private static int claimExpirationDays = 20;
|
||||
private static boolean auctionEnabled = false;
|
||||
|
||||
/**
|
||||
@@ -47,11 +47,11 @@ public class AuctionClientConfig {
|
||||
*/
|
||||
public static void reset() {
|
||||
listingFee = 0;
|
||||
currencyName = "Gold";
|
||||
auctionDurationHours = 48;
|
||||
currencyName = "Coins";
|
||||
auctionDurationHours = 24;
|
||||
minBidIncrement = 0.05;
|
||||
maxActiveListings = 10;
|
||||
claimExpirationDays = 30;
|
||||
maxActiveListings = 8;
|
||||
claimExpirationDays = 20;
|
||||
auctionEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import kamkeel.npcs.addon.client.DBCClient;
|
||||
import kamkeel.npcs.client.renderer.TelegraphRenderer;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
|
||||
@@ -5,7 +5,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.CheckPlayerValue;
|
||||
import kamkeel.npcs.network.packets.player.InputDevicePacket;
|
||||
|
||||
@@ -3,7 +3,7 @@ package noppes.npcs.client.gui.advanced;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.Condition;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
@@ -47,9 +47,9 @@ public class SubGuiAbilityHazard extends SubGuiAbilityConfig {
|
||||
|
||||
y += 24;
|
||||
|
||||
// Row 3: Damage Per Tick + Damage Interval
|
||||
addLabel(new GuiNpcLabel(104, "ability.dmgPerTick", labelX, y + 5));
|
||||
addTextField(createFloatField(104, fieldX, y, 50, hazard.getDamagePerTick()));
|
||||
// Row 3: Damage Per Second + Damage Interval
|
||||
addLabel(new GuiNpcLabel(104, "ability.dmgPerSec", labelX, y + 5));
|
||||
addTextField(createFloatField(104, fieldX, y, 50, hazard.getDamagePerSecond()));
|
||||
|
||||
addLabel(new GuiNpcLabel(105, "ability.dmgInterval", col2LabelX, y + 5));
|
||||
addTextField(createIntField(105, col2FieldX, y, 50, hazard.getDamageInterval()));
|
||||
@@ -99,7 +99,7 @@ public class SubGuiAbilityHazard extends SubGuiAbilityConfig {
|
||||
hazard.setInnerRadius(parseFloat(field, hazard.getInnerRadius()));
|
||||
break;
|
||||
case 104:
|
||||
hazard.setDamagePerTick(parseFloat(field, hazard.getDamagePerTick()));
|
||||
hazard.setDamagePerSecond(parseFloat(field, hazard.getDamagePerSecond()));
|
||||
break;
|
||||
case 105:
|
||||
hazard.setDamageInterval(field.getInteger());
|
||||
|
||||
@@ -50,7 +50,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData {
|
||||
int y = guiTop + 10;
|
||||
this.addButton(new GuiNpcButton(3, guiLeft + 85 + 160, y, 52, 20, "selectServer.edit"));
|
||||
this.addButton(new GuiNpcButton(8, guiLeft + 85, y, 155, 20, new String[]{"role.none", "role.trader", "role.follower", "role.bank", "role.transporter", "role.mailman", NoppesStringUtils.translate("role.companion", "(WIP)"), "role.mount", "role.auctioneer"}, npc.advanced.role.ordinal()));
|
||||
getButton(3).setEnabled(npc.advanced.role != EnumRoleType.None && npc.advanced.role != EnumRoleType.Postman);
|
||||
getButton(3).setEnabled(npc.advanced.role != EnumRoleType.None && npc.advanced.role != EnumRoleType.Postman && npc.advanced.role != EnumRoleType.Auctioneer);
|
||||
|
||||
this.addButton(new GuiNpcButton(4, guiLeft + 85 + 160, y += 22, 52, 20, "selectServer.edit"));
|
||||
this.addButton(new GuiNpcButton(5, guiLeft + 85, y, 155, 20, new String[]{"job.none", "job.bard", "job.healer", "job.guard", "job.itemgiver", "role.follower", "job.spawner", "job.conversation", "job.chunkloader"}, npc.advanced.job.ordinal()));
|
||||
@@ -84,7 +84,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData {
|
||||
hasChanges = true;
|
||||
npc.advanced.setRole(button.getValue());
|
||||
|
||||
getButton(3).setEnabled(npc.advanced.role != EnumRoleType.None && npc.advanced.role != EnumRoleType.Postman);
|
||||
getButton(3).setEnabled(npc.advanced.role != EnumRoleType.None && npc.advanced.role != EnumRoleType.Postman && npc.advanced.role != EnumRoleType.Auctioneer);
|
||||
}
|
||||
if (button.id == 4) {
|
||||
save();
|
||||
|
||||
@@ -8,7 +8,9 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.AuctionClientConfig;
|
||||
import noppes.npcs.constants.EnumClaimType;
|
||||
import noppes.npcs.containers.ContainerAuctionListing;
|
||||
import noppes.npcs.containers.ContainerAuctionSell;
|
||||
import noppes.npcs.containers.ContainerAuctionTrades;
|
||||
import noppes.npcs.controllers.data.AuctionClaim;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
@@ -41,6 +43,10 @@ public class AuctionTooltipHandler {
|
||||
else if (screen instanceof GuiAuctionTrades) {
|
||||
addTradesTooltip((GuiAuctionTrades) screen, stack, tooltip);
|
||||
}
|
||||
// Check if we're in the sell GUI
|
||||
else if (screen instanceof GuiAuctionSell) {
|
||||
addSellTooltip((GuiAuctionSell) screen, stack, tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,10 +60,7 @@ public class AuctionTooltipHandler {
|
||||
AuctionListing listing = container.getListingForItem(stack);
|
||||
if (listing == null) return;
|
||||
|
||||
// Add separator
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.DARK_GRAY + "--- " + EnumChatFormatting.GOLD +
|
||||
StatCollector.translateToLocal("auction.title") + EnumChatFormatting.DARK_GRAY + " ---");
|
||||
|
||||
// Seller
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.seller")
|
||||
@@ -94,22 +97,21 @@ public class AuctionTooltipHandler {
|
||||
ContainerAuctionTrades container = (ContainerAuctionTrades) gui.inventorySlots;
|
||||
if (container == null) return;
|
||||
|
||||
// Check if it's an active listing
|
||||
AuctionListing listing = container.getListingForItem(stack);
|
||||
if (listing != null) {
|
||||
// Check if it's an item I'm selling
|
||||
AuctionListing sellingListing = container.getSellingListingForItem(stack);
|
||||
if (sellingListing != null) {
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.DARK_GRAY + "--- " + EnumChatFormatting.GOLD +
|
||||
StatCollector.translateToLocal("auction.trades.activeListing") + EnumChatFormatting.DARK_GRAY + " ---");
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.trades.selling"));
|
||||
|
||||
if (listing.hasBids()) {
|
||||
if (sellingListing.hasBids()) {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.currentBid")
|
||||
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(listing.currentBid)));
|
||||
tooltip.add(EnumChatFormatting.GRAY + String.format(StatCollector.translateToLocal("auction.bids"), listing.bidCount));
|
||||
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(sellingListing.currentBid)));
|
||||
tooltip.add(EnumChatFormatting.GRAY + String.format(StatCollector.translateToLocal("auction.bids"), sellingListing.bidCount));
|
||||
} else {
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.noBids"));
|
||||
}
|
||||
|
||||
long timeRemaining = listing.getTimeRemaining();
|
||||
long timeRemaining = sellingListing.getTimeRemaining();
|
||||
String timeText = StatCollector.translateToLocal("auction.timeLeft")
|
||||
.replace("%s", formatTimeRemaining(timeRemaining));
|
||||
tooltip.add((timeRemaining < 3600000 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
|
||||
@@ -119,29 +121,65 @@ public class AuctionTooltipHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if it's an item I'm bidding on
|
||||
AuctionListing biddingListing = container.getBiddingListingForItem(stack);
|
||||
if (biddingListing != null) {
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.trades.bidding"));
|
||||
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.currentBid")
|
||||
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(biddingListing.currentBid)));
|
||||
tooltip.add(EnumChatFormatting.GRAY + String.format(StatCollector.translateToLocal("auction.bids"), biddingListing.bidCount));
|
||||
|
||||
long timeRemaining = biddingListing.getTimeRemaining();
|
||||
String timeText = StatCollector.translateToLocal("auction.timeLeft")
|
||||
.replace("%s", formatTimeRemaining(timeRemaining));
|
||||
tooltip.add((timeRemaining < 3600000 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
|
||||
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.trades.clickToRebid"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if it's a claim
|
||||
AuctionClaim claim = container.getClaimForItem(stack);
|
||||
if (claim != null) {
|
||||
tooltip.add("");
|
||||
|
||||
String claimTitle;
|
||||
// Title based on claim type
|
||||
switch (claim.type) {
|
||||
case ITEM:
|
||||
claimTitle = StatCollector.translateToLocal("auction.claim.item");
|
||||
if (claim.isReturned) {
|
||||
// Expired - returned to seller
|
||||
tooltip.add(EnumChatFormatting.RED + StatCollector.translateToLocal("auction.trades.expired"));
|
||||
} else {
|
||||
// Won item
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.trades.won"));
|
||||
}
|
||||
break;
|
||||
case CURRENCY:
|
||||
claimTitle = StatCollector.translateToLocal("auction.claim.currency");
|
||||
// Sold - money to claim
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.trades.sold"));
|
||||
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));
|
||||
}
|
||||
break;
|
||||
case REFUND:
|
||||
claimTitle = StatCollector.translateToLocal("auction.claim.refund");
|
||||
// Outbid - refund available
|
||||
tooltip.add(EnumChatFormatting.RED + StatCollector.translateToLocal("auction.trades.outbid"));
|
||||
if (claim.otherPlayerName != null && !claim.otherPlayerName.isEmpty()) {
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.claim.outbidBy")
|
||||
.replace("%s", EnumChatFormatting.WHITE + claim.otherPlayerName));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
claimTitle = "Claim";
|
||||
}
|
||||
|
||||
tooltip.add(EnumChatFormatting.DARK_GRAY + "--- " + EnumChatFormatting.GOLD +
|
||||
claimTitle + EnumChatFormatting.DARK_GRAY + " ---");
|
||||
|
||||
// Amount for currency claims (including REFUND)
|
||||
if (claim.type.isCurrency()) {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.claim.amount")
|
||||
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(claim.currency)));
|
||||
@@ -158,10 +196,40 @@ public class AuctionTooltipHandler {
|
||||
}
|
||||
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.claim.clickToClaim"));
|
||||
|
||||
// Show rebid option for REFUND claims with item (active auction)
|
||||
if (claim.type == EnumClaimType.REFUND && claim.item != null) {
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.trades.leftClickRebid"));
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.trades.rightClickRefund"));
|
||||
} else {
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.claim.clickToClaim"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add sell page tooltip info.
|
||||
*/
|
||||
private static void addSellTooltip(GuiAuctionSell gui, ItemStack stack, List<String> tooltip) {
|
||||
ContainerAuctionSell container = (ContainerAuctionSell) gui.inventorySlots;
|
||||
if (container == null) return;
|
||||
|
||||
// Check if this is the sell slot item
|
||||
ItemStack sellItem = container.getItemToSell();
|
||||
if (sellItem != null && ItemStack.areItemStacksEqual(stack, sellItem)) {
|
||||
// This is the item in the sell slot
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.sell.leftClear"));
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.sell.rightRemove"));
|
||||
return;
|
||||
}
|
||||
|
||||
// This is an inventory item - show add controls
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.sell.leftAdd"));
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.sell.rightAddOne"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Format currency with commas.
|
||||
*/
|
||||
|
||||
@@ -29,20 +29,19 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
private static final ResourceLocation ICON_BID = new ResourceLocation("customnpcs", "textures/items/npcCoinDiamond.png");
|
||||
private static final ResourceLocation ICON_BUYOUT = new ResourceLocation("customnpcs", "textures/items/npcCoinEmerald.png");
|
||||
|
||||
// Layout - non-final for testing/positioning
|
||||
protected int itemSlotX = 56;
|
||||
protected int itemSlotY = 52;
|
||||
protected int btnBidX = 56;
|
||||
protected int btnBidY = 80;
|
||||
protected int btnBuyoutX = 80;
|
||||
protected int btnBuyoutY = 80;
|
||||
protected int infoX = 110;
|
||||
protected int infoY = 50;
|
||||
protected int infoWidth = 130;
|
||||
// Layout
|
||||
private int itemSlotX = 70;
|
||||
private int itemSlotY = 75;
|
||||
private int btnBidX = 58;
|
||||
private int btnBidY = 110;
|
||||
private int btnBuyoutX = 82;
|
||||
private int btnBuyoutY = 110;
|
||||
private int infoX = 110;
|
||||
private int infoY = 50;
|
||||
|
||||
// Button IDs
|
||||
private static final int BTN_BID = 200;
|
||||
private static final int BTN_BUYOUT = 201;
|
||||
private int btnBidId = 200;
|
||||
private int btnBuyoutId = 201;
|
||||
|
||||
private final ContainerAuctionBidding biddingContainer;
|
||||
private AuctionListing listing;
|
||||
@@ -64,12 +63,12 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
super.initGui();
|
||||
|
||||
// Bid button (diamond coin)
|
||||
btnBid = new GuiAuctionNavButton(BTN_BID, guiLeft + btnBidX, guiTop + btnBidY,
|
||||
btnBid = new GuiAuctionNavButton(btnBidId, guiLeft + btnBidX, guiTop + btnBidY,
|
||||
"auction.bid.place", ICON_BID);
|
||||
addButton(btnBid);
|
||||
|
||||
// Buy Now button (emerald coin) - only visible if listing has buyout
|
||||
btnBuyout = new GuiAuctionNavButton(BTN_BUYOUT, guiLeft + btnBuyoutX, guiTop + btnBuyoutY,
|
||||
btnBuyout = new GuiAuctionNavButton(btnBuyoutId, guiLeft + btnBuyoutX, guiTop + btnBuyoutY,
|
||||
"auction.bid.buyout", ICON_BUYOUT);
|
||||
addButton(btnBuyout);
|
||||
|
||||
@@ -112,15 +111,12 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
|
||||
if (listing == null) return;
|
||||
|
||||
switch (button.id) {
|
||||
case BTN_BID:
|
||||
openBidSubGui();
|
||||
break;
|
||||
case BTN_BUYOUT:
|
||||
if (listing.hasBuyout()) {
|
||||
openBuyNowSubGui();
|
||||
}
|
||||
break;
|
||||
if (button.id == btnBidId) {
|
||||
openBidSubGui();
|
||||
} else if (button.id == btnBuyoutId) {
|
||||
if (listing.hasBuyout()) {
|
||||
openBuyNowSubGui();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,38 +186,46 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
|
||||
/** Draw auction listing information on the right side */
|
||||
private void drawAuctionInfo() {
|
||||
int x = guiLeft + infoX;
|
||||
int x = guiLeft + 105;
|
||||
int y = guiTop + infoY;
|
||||
int lineHeight = 12;
|
||||
String currencyName = AuctionClientConfig.getCurrencyName();
|
||||
int xRight = guiLeft + 215;
|
||||
|
||||
int lineHeight = 9;
|
||||
|
||||
// Seller
|
||||
String sellerLabel = StatCollector.translateToLocal("auction.seller").replace("%s", "");
|
||||
fontRendererObj.drawString(EnumChatFormatting.GRAY + sellerLabel, x, y, 0xFFFFFF);
|
||||
y += lineHeight;
|
||||
fontRendererObj.drawString(EnumChatFormatting.WHITE + listing.sellerName, x + 10, y, 0xFFFFFF);
|
||||
|
||||
String label = listing.sellerName;
|
||||
int length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(EnumChatFormatting.WHITE + listing.sellerName, xRight - length, y, 0xFFFFFF);
|
||||
y += lineHeight + 4;
|
||||
|
||||
// Current Bid or Starting Price
|
||||
if (listing.hasBids()) {
|
||||
String bidLabel = StatCollector.translateToLocal("auction.info.currentBid");
|
||||
String bidLabel = StatCollector.translateToLocal("auction.info.currentBid") + ":";
|
||||
fontRendererObj.drawString(EnumChatFormatting.YELLOW + bidLabel, x, y, 0xFFFFFF);
|
||||
y += lineHeight;
|
||||
fontRendererObj.drawString(EnumChatFormatting.GOLD + formatCurrency(listing.currentBid) + " " + currencyName, x + 10, y, 0xFFFFFF);
|
||||
|
||||
label = formatCurrency(listing.currentBid);
|
||||
length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(EnumChatFormatting.GOLD + label, xRight - length, y, 0xFFFFFF);
|
||||
y += lineHeight + 4;
|
||||
|
||||
// Current Bidder
|
||||
String bidderLabel = StatCollector.translateToLocal("auction.info.highBidder");
|
||||
fontRendererObj.drawString(EnumChatFormatting.GRAY + bidderLabel, x, y, 0xFFFFFF);
|
||||
y += lineHeight;
|
||||
String bidderName = listing.highBidderName != null ? listing.highBidderName : "???";
|
||||
fontRendererObj.drawString(EnumChatFormatting.WHITE + bidderName, x + 10, y, 0xFFFFFF);
|
||||
|
||||
label = listing.highBidderName != null ? listing.highBidderName : "???";
|
||||
length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(EnumChatFormatting.WHITE + label, xRight - length, y, 0xFFFFFF);
|
||||
y += lineHeight + 4;
|
||||
} else {
|
||||
String startLabel = StatCollector.translateToLocal("auction.info.startingPrice");
|
||||
fontRendererObj.drawString(EnumChatFormatting.YELLOW + startLabel, x, y, 0xFFFFFF);
|
||||
y += lineHeight;
|
||||
fontRendererObj.drawString(EnumChatFormatting.GOLD + formatCurrency(listing.startingPrice) + " " + currencyName, x + 10, y, 0xFFFFFF);
|
||||
|
||||
label = formatCurrency(listing.startingPrice);
|
||||
length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(EnumChatFormatting.GOLD + label, xRight - length, y, 0xFFFFFF);
|
||||
y += lineHeight + 4;
|
||||
}
|
||||
|
||||
@@ -229,25 +233,31 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
if (listing.hasBuyout()) {
|
||||
String buyoutLabel = StatCollector.translateToLocal("auction.info.buyoutPrice");
|
||||
fontRendererObj.drawString(EnumChatFormatting.GREEN + buyoutLabel, x, y, 0xFFFFFF);
|
||||
y += lineHeight;
|
||||
fontRendererObj.drawString(EnumChatFormatting.GREEN + formatCurrency(listing.buyoutPrice) + " " + currencyName, x + 10, y, 0xFFFFFF);
|
||||
|
||||
label = formatCurrency(listing.buyoutPrice);
|
||||
length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(EnumChatFormatting.GREEN + label, xRight - length, y, 0xFFFFFF);
|
||||
y += lineHeight + 4;
|
||||
}
|
||||
|
||||
// Time Remaining
|
||||
String timeLabel = StatCollector.translateToLocal("auction.info.timeLeft");
|
||||
fontRendererObj.drawString(EnumChatFormatting.GRAY + timeLabel, x, y, 0xFFFFFF);
|
||||
y += lineHeight;
|
||||
long timeRemaining = listing.getTimeRemaining();
|
||||
EnumChatFormatting timeColor = timeRemaining < 3600000 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE;
|
||||
fontRendererObj.drawString(timeColor + formatTimeRemaining(timeRemaining), x + 10, y, 0xFFFFFF);
|
||||
|
||||
label = timeColor + formatTimeRemaining(timeRemaining);
|
||||
length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(label, xRight - length, y, 0xFFFFFF);
|
||||
y += lineHeight + 4;
|
||||
|
||||
// Bid Count
|
||||
String bidCountLabel = StatCollector.translateToLocal("auction.info.bidCount");
|
||||
fontRendererObj.drawString(EnumChatFormatting.GRAY + bidCountLabel, x, y, 0xFFFFFF);
|
||||
y += lineHeight;
|
||||
fontRendererObj.drawString(EnumChatFormatting.WHITE + String.valueOf(listing.bidCount), x + 10, y, 0xFFFFFF);
|
||||
|
||||
label = String.valueOf(listing.bidCount);
|
||||
length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(EnumChatFormatting.WHITE + label, xRight - length, y, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,6 @@ import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
import noppes.npcs.client.AuctionClientConfig;
|
||||
import noppes.npcs.containers.ContainerAuctionSell;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -30,23 +29,23 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
private static final ResourceLocation ICON_COIN = new ResourceLocation("customnpcs", "textures/items/npcCoinBronze.png");
|
||||
private static final ResourceLocation ICON_BAG = new ResourceLocation("customnpcs", "textures/items/npcBag.png");
|
||||
|
||||
// Layout - non-final for testing/positioning
|
||||
protected int contentX = 50;
|
||||
protected int contentY = 50;
|
||||
protected int confirmBtnX = 180;
|
||||
protected int confirmBtnY = 120;
|
||||
protected int navYBuyout = 109;
|
||||
// Layout
|
||||
private int contentX = 58;
|
||||
private int contentY = 50;
|
||||
private int confirmBtnX = 200;
|
||||
private int confirmBtnY = 118;
|
||||
private int navYBuyout = 109;
|
||||
|
||||
// Component IDs
|
||||
private static final int TXT_STARTING_PRICE = 1;
|
||||
private static final int TXT_BUYOUT_PRICE = 2;
|
||||
private static final int BTN_CONFIRM = 10;
|
||||
private static final int BTN_ALLOW_BUYOUT = 11;
|
||||
private int txtStartingPriceId = 1;
|
||||
private int txtBuyoutPriceId = 2;
|
||||
private int btnConfirmId = 10;
|
||||
private int btnAllowBuyoutId = 11;
|
||||
|
||||
private final ContainerAuctionSell sellContainer;
|
||||
private long startingPrice = 0;
|
||||
private long buyoutPrice = 0;
|
||||
private boolean allowBuyout = false;
|
||||
private boolean allowBuyout = true;
|
||||
private String errorMessage = null;
|
||||
|
||||
// Buttons
|
||||
@@ -67,7 +66,7 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
|
||||
// Starting Price label and field
|
||||
addLabel(new GuiNpcLabel(1, "auction.sell.startingPrice", guiLeft + contentX, y + 5, 0xFFFFFF));
|
||||
GuiNpcTextField startingField = new GuiNpcTextField(TXT_STARTING_PRICE, this, fontRendererObj,
|
||||
GuiNpcTextField startingField = new GuiNpcTextField(txtStartingPriceId, this, fontRendererObj,
|
||||
guiLeft + contentX + 80, y, 80, 18, startingPrice > 0 ? String.valueOf(startingPrice) : "");
|
||||
startingField.setIntegersOnly();
|
||||
addTextField(startingField);
|
||||
@@ -78,20 +77,20 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
lblBuyout = new GuiNpcLabel(2, "auction.sell.buyoutPrice", guiLeft + contentX, y + 5, 0xFFFFFF);
|
||||
addLabel(lblBuyout);
|
||||
|
||||
txtBuyout = new GuiNpcTextField(TXT_BUYOUT_PRICE, this, fontRendererObj,
|
||||
txtBuyout = new GuiNpcTextField(txtBuyoutPriceId, this, fontRendererObj,
|
||||
guiLeft + contentX + 80, y, 80, 18, buyoutPrice > 0 ? String.valueOf(buyoutPrice) : "");
|
||||
txtBuyout.setIntegersOnly();
|
||||
addTextField(txtBuyout);
|
||||
|
||||
// Allow Buyout toggle button (18x18 with bag icon)
|
||||
btnAllowBuyout = new GuiAuctionNavButton(BTN_ALLOW_BUYOUT, guiLeft + navX, guiTop + navYBuyout,
|
||||
btnAllowBuyout = new GuiAuctionNavButton(btnAllowBuyoutId, guiLeft + navX, guiTop + navYBuyout,
|
||||
"auction.sell.allowBuyout", ICON_BAG);
|
||||
btnAllowBuyout.setToggle(true); // This is a toggle, not a nav button
|
||||
btnAllowBuyout.setSelected(allowBuyout);
|
||||
addButton(btnAllowBuyout);
|
||||
|
||||
// Confirm button (custom textured button - using GuiAuctionNavButton)
|
||||
GuiAuctionNavButton btnConfirm = new GuiAuctionNavButton(BTN_CONFIRM, guiLeft + confirmBtnX, guiTop + confirmBtnY,
|
||||
GuiAuctionNavButton btnConfirm = new GuiAuctionNavButton(btnConfirmId, guiLeft + confirmBtnX - 20, guiTop + confirmBtnY - 10,
|
||||
"auction.sell.confirm", ICON_COIN);
|
||||
addButton(btnConfirm);
|
||||
|
||||
@@ -141,13 +140,13 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textfield) {
|
||||
if (textfield.id == TXT_STARTING_PRICE) {
|
||||
if (textfield.id == txtStartingPriceId) {
|
||||
try {
|
||||
startingPrice = Long.parseLong(textfield.getText());
|
||||
} catch (NumberFormatException e) {
|
||||
startingPrice = 0;
|
||||
}
|
||||
} else if (textfield.id == TXT_BUYOUT_PRICE) {
|
||||
} else if (textfield.id == txtBuyoutPriceId) {
|
||||
try {
|
||||
String text = textfield.getText().trim();
|
||||
buyoutPrice = text.isEmpty() ? 0 : Long.parseLong(text);
|
||||
@@ -162,9 +161,9 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
public void actionPerformed(GuiButton button) {
|
||||
super.actionPerformed(button);
|
||||
|
||||
if (button.id == BTN_CONFIRM) {
|
||||
if (button.id == btnConfirmId) {
|
||||
createListing();
|
||||
} else if (button.id == BTN_ALLOW_BUYOUT) {
|
||||
} else if (button.id == btnAllowBuyoutId) {
|
||||
allowBuyout = !allowBuyout;
|
||||
btnAllowBuyout.setSelected(allowBuyout);
|
||||
updateBuyoutVisibility();
|
||||
@@ -175,8 +174,8 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
|
||||
private void createListing() {
|
||||
// Get latest values from text fields
|
||||
GuiNpcTextField startingField = getTextField(TXT_STARTING_PRICE);
|
||||
GuiNpcTextField buyoutField = getTextField(TXT_BUYOUT_PRICE);
|
||||
GuiNpcTextField startingField = getTextField(txtStartingPriceId);
|
||||
GuiNpcTextField buyoutField = getTextField(txtBuyoutPriceId);
|
||||
|
||||
if (startingField != null) {
|
||||
try {
|
||||
@@ -234,21 +233,20 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
@Override
|
||||
protected void drawAuctionContent(float partialTicks, int mouseX, int mouseY) {
|
||||
// Draw sell slot background (centered in content area)
|
||||
int slotX = guiLeft + contentX + 30;
|
||||
int slotY = guiTop + contentY + 55;
|
||||
int slotX = guiLeft + contentX;
|
||||
int slotY = guiTop + contentY + 50;
|
||||
drawAuctionSlot(slotX, slotY);
|
||||
|
||||
// Draw listing fee info (uses cached config from server)
|
||||
String feeText = StatCollector.translateToLocal("auction.sell.fee")
|
||||
.replace("%s", formatCurrency(AuctionClientConfig.getListingFee()) + " " + AuctionClientConfig.getCurrencyName());
|
||||
fontRendererObj.drawString(EnumChatFormatting.GRAY + feeText, guiLeft + contentX, guiTop + contentY + 80, 0xFFFFFF);
|
||||
fontRendererObj.drawString(EnumChatFormatting.GRAY + feeText, guiLeft + contentX, guiTop + contentY + 77, 0xFFFFFF);
|
||||
|
||||
// Draw error message if any
|
||||
if (errorMessage != null) {
|
||||
fontRendererObj.drawString(EnumChatFormatting.RED + errorMessage, guiLeft + contentX, guiTop + contentY + 95, 0xFFFFFF);
|
||||
}
|
||||
|
||||
// Draw item count indicator for sell slot
|
||||
drawSellSlotIndicator(slotX, slotY);
|
||||
}
|
||||
|
||||
@@ -261,14 +259,11 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
|
||||
// Color: green if valid, red if over limit
|
||||
int color = sellItem.stackSize <= inventoryCount ? 0x55FF55 : 0xFF5555;
|
||||
|
||||
int textWidth = fontRendererObj.getStringWidth(countText);
|
||||
fontRendererObj.drawStringWithShadow(countText, slotX + 18 + 4, slotY + 5, color);
|
||||
} else {
|
||||
// Draw "Place item here" hint
|
||||
String hint = StatCollector.translateToLocal("auction.sell.placeItem");
|
||||
int hintWidth = fontRendererObj.getStringWidth(hint);
|
||||
fontRendererObj.drawString(EnumChatFormatting.GRAY + hint, slotX + 9 - hintWidth / 2 + 20, slotY + 5, 0xFFFFFF);
|
||||
fontRendererObj.drawString(EnumChatFormatting.GRAY + hint, slotX + 20, slotY + 5, 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,14 +304,8 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
if (hasSubGui()) return;
|
||||
|
||||
// Draw tooltips for buttons
|
||||
// Draw tooltips for buttons (icons, not items - item tooltips handled by AuctionTooltipHandler)
|
||||
drawSellPageTooltips(mouseX, mouseY);
|
||||
|
||||
// Sell slot tooltip
|
||||
drawSellSlotTooltip(mouseX, mouseY);
|
||||
|
||||
// Inventory item tooltip (only add extra info, item tooltip is handled by AuctionTooltipHandler)
|
||||
drawInventoryTooltip(mouseX, mouseY);
|
||||
}
|
||||
|
||||
/** Draw tooltips for sell page buttons */
|
||||
@@ -324,7 +313,7 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
List<String> tooltip = null;
|
||||
|
||||
// Check all buttons
|
||||
GuiNpcButton confirmBtn = getButton(BTN_CONFIRM);
|
||||
GuiNpcButton confirmBtn = getButton(btnConfirmId);
|
||||
if (confirmBtn instanceof GuiAuctionNavButton) {
|
||||
GuiAuctionNavButton btn = (GuiAuctionNavButton) confirmBtn;
|
||||
if (btn.isHovered()) {
|
||||
@@ -337,64 +326,7 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
}
|
||||
|
||||
if (tooltip != null && !tooltip.isEmpty()) {
|
||||
drawTooltip(tooltip, mouseX - guiLeft, mouseY - guiTop);
|
||||
drawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj);
|
||||
}
|
||||
}
|
||||
|
||||
/** Draw tooltip for sell slot */
|
||||
private void drawSellSlotTooltip(int mouseX, int mouseY) {
|
||||
int slotX = guiLeft + contentX + 30;
|
||||
int slotY = guiTop + contentY + 55;
|
||||
|
||||
if (mouseX >= slotX && mouseX < slotX + 18 && mouseY >= slotY && mouseY < slotY + 18) {
|
||||
ItemStack sellItem = sellContainer.getItemToSell();
|
||||
if (sellItem != null) {
|
||||
List<String> tooltip = new ArrayList<>();
|
||||
tooltip.add(EnumChatFormatting.GOLD + StatCollector.translateToLocal("auction.sell.slotTitle"));
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.sell.leftClear"));
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.sell.rightRemove"));
|
||||
drawTooltip(tooltip, mouseX - guiLeft, mouseY - guiTop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Draw tooltip for inventory items */
|
||||
private void drawInventoryTooltip(int mouseX, int mouseY) {
|
||||
Slot hoveredSlot = getSlotUnderMouse(mouseX, mouseY);
|
||||
if (hoveredSlot != null && sellContainer.isPlayerInventorySlot(hoveredSlot.slotNumber)) {
|
||||
if (hoveredSlot.getStack() != null) {
|
||||
List<String> tooltip = new ArrayList<>();
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.sell.leftAdd"));
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.sell.rightAddOne"));
|
||||
drawTooltip(tooltip, mouseX - guiLeft, mouseY - guiTop + 40);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Get slot under mouse position */
|
||||
private Slot getSlotUnderMouse(int mouseX, int mouseY) {
|
||||
for (int i = 0; i < inventorySlots.inventorySlots.size(); i++) {
|
||||
Slot slot = (Slot) inventorySlots.inventorySlots.get(i);
|
||||
if (isMouseOverSlot(slot, mouseX, mouseY)) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Check if mouse is over a slot */
|
||||
private boolean isMouseOverSlot(Slot slot, int mouseX, int mouseY) {
|
||||
int x = guiLeft + slot.xDisplayPosition;
|
||||
int y = guiTop + slot.yDisplayPosition;
|
||||
return mouseX >= x && mouseX < x + 16 && mouseY >= y && mouseY < y + 16;
|
||||
}
|
||||
|
||||
/** Draw tooltip with proper GL state */
|
||||
private void drawTooltip(List<String> tooltip, int x, int y) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
drawHoveringText(tooltip, x, y, fontRendererObj);
|
||||
GL11.glPopAttrib();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
// Icon textures
|
||||
private static final ResourceLocation ICON_X = new ResourceLocation("customnpcs", "textures/gui/auction/x_icon.png");
|
||||
private static final ResourceLocation ICON_CHECK = new ResourceLocation("customnpcs", "textures/gui/auction/check_icon.png");
|
||||
private static final ResourceLocation ICON_COIN = new ResourceLocation("customnpcs", "textures/items/npcCoinGold.png");
|
||||
|
||||
// Grid layout
|
||||
private static final int GRID_X = 56;
|
||||
@@ -37,9 +38,10 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
private static final int TOTAL_SLOTS = COLS * ROWS;
|
||||
|
||||
// Slot tint colors (ARGB)
|
||||
private static final int TINT_BLUE = 0x303060FF; // Active listing/bid
|
||||
private static final int TINT_GREEN = 0x3030FF60; // Claimable
|
||||
private static final int TINT_RED = 0x30FF4040; // Refund
|
||||
private static final int TINT_BLUE = 0x303060FF; // Active listing/bid (selling)
|
||||
private static final int TINT_GREEN = 0x3030FF30; // Sold (currency claim) or Won (item claim)
|
||||
private static final int TINT_YELLOW = 0x30FFFF30; // Outbid (refund claim)
|
||||
private static final int TINT_RED = 0x30FF3030; // Expired/Returned (item returned to seller)
|
||||
|
||||
private final ContainerAuctionTrades tradesContainer;
|
||||
private int maxTradeSlots;
|
||||
@@ -53,7 +55,8 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
public GuiAuctionTrades(EntityNPCInterface npc, ContainerAuctionTrades container) {
|
||||
super(npc, container);
|
||||
this.tradesContainer = container;
|
||||
this.maxTradeSlots = AuctionClientConfig.getMaxActiveListings() * 2;
|
||||
// Initial value from client config, updated when server sends trades data
|
||||
this.maxTradeSlots = AuctionClientConfig.getMaxActiveListings();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,10 +92,28 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
// Right-click on own listing = show cancel
|
||||
setPending(slot, PendingOp.CANCEL);
|
||||
NoppesUtil.clickSound();
|
||||
} else if (claim != null && mouseButton == 0) {
|
||||
// Left-click on claim = show claim
|
||||
setPending(slot, PendingOp.CLAIM);
|
||||
} else if (listing != null && tradesContainer.isBiddingAt(slot) && mouseButton == 0) {
|
||||
// Left-click on active bid = open bidding GUI to increase bid
|
||||
AuctionActionPacket.openBidding(listing.id);
|
||||
NoppesUtil.clickSound();
|
||||
} else if (claim != null) {
|
||||
// Handle claim clicks
|
||||
if (claim.type == EnumClaimType.REFUND && claim.item != null) {
|
||||
// REFUND with item = can rebid
|
||||
if (mouseButton == 0) {
|
||||
// Left-click = open bidding to rebid
|
||||
AuctionActionPacket.openBidding(claim.listingId);
|
||||
NoppesUtil.clickSound();
|
||||
} else if (mouseButton == 1) {
|
||||
// Right-click = show refund claim confirmation
|
||||
setPending(slot, PendingOp.CLAIM);
|
||||
NoppesUtil.clickSound();
|
||||
}
|
||||
} else if (mouseButton == 0) {
|
||||
// Normal claim - left-click shows claim confirmation
|
||||
setPending(slot, PendingOp.CLAIM);
|
||||
NoppesUtil.clickSound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,18 +127,31 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
playConfirmSound();
|
||||
}
|
||||
clearPending();
|
||||
} else if (pendingOp == PendingOp.CLAIM && mouseButton == 0) {
|
||||
// Left-click confirms claim
|
||||
} else if (pendingOp == PendingOp.CLAIM) {
|
||||
AuctionClaim claim = tradesContainer.getClaimAt(pendingSlot);
|
||||
if (claim != null) {
|
||||
if (claim.type.isItem()) {
|
||||
AuctionActionPacket.claimItem(claim.id);
|
||||
// For REFUND claims with item (rebid option), right-click confirms refund
|
||||
// For all others, left-click confirms claim
|
||||
boolean shouldClaim = (claim.type == EnumClaimType.REFUND && claim.item != null)
|
||||
? mouseButton == 1 // Right-click for rebiddable refunds
|
||||
: mouseButton == 0; // Left-click for normal claims
|
||||
|
||||
if (shouldClaim) {
|
||||
if (claim.type.isItem()) {
|
||||
AuctionActionPacket.claimItem(claim.id);
|
||||
} else {
|
||||
AuctionActionPacket.claimCurrency(claim.id);
|
||||
}
|
||||
playConfirmSound();
|
||||
clearPending();
|
||||
} else {
|
||||
AuctionActionPacket.claimCurrency(claim.id);
|
||||
// Wrong button - cancel operation
|
||||
clearPending();
|
||||
NoppesUtil.clickSound();
|
||||
}
|
||||
playConfirmSound();
|
||||
} else {
|
||||
clearPending();
|
||||
}
|
||||
clearPending();
|
||||
} else {
|
||||
// Wrong button - cancel operation
|
||||
clearPending();
|
||||
@@ -156,7 +190,6 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
int col = relX / 18;
|
||||
int row = relY / 18;
|
||||
if (col >= COLS || row >= ROWS) return -1;
|
||||
if (relX % 18 >= 18 || relY % 18 >= 18) return -1;
|
||||
|
||||
return col + row * COLS;
|
||||
}
|
||||
@@ -184,13 +217,23 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
drawDarkenedOverlay(x, y);
|
||||
}
|
||||
|
||||
// Pending operation icon
|
||||
// Pending operation icon or currency claim coin
|
||||
if (slot == pendingSlot) {
|
||||
if (pendingOp == PendingOp.CANCEL) {
|
||||
drawIconOverlay(x, y, ICON_X);
|
||||
} else if (pendingOp == PendingOp.CLAIM) {
|
||||
drawIconOverlay(x, y, ICON_CHECK);
|
||||
}
|
||||
} else {
|
||||
// Draw coin icon for currency claims or refund claims without item
|
||||
AuctionClaim claim = tradesContainer.getClaimAt(slot);
|
||||
if (claim != null) {
|
||||
// Show coin if: CURRENCY claim OR REFUND claim without item
|
||||
if (claim.type == EnumClaimType.CURRENCY ||
|
||||
(claim.type == EnumClaimType.REFUND && claim.item == null)) {
|
||||
drawIconOverlay(x, y, ICON_COIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,9 +245,27 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
AuctionClaim claim = tradesContainer.getClaimAt(slot);
|
||||
|
||||
if (listing != null) {
|
||||
return TINT_BLUE;
|
||||
if (tradesContainer.isSellingAt(slot)) {
|
||||
// Selling - Blue
|
||||
return TINT_BLUE;
|
||||
} else {
|
||||
// Bidding - Yellow
|
||||
return TINT_YELLOW;
|
||||
}
|
||||
} else if (claim != null) {
|
||||
return (claim.type == EnumClaimType.REFUND) ? TINT_RED : TINT_GREEN;
|
||||
switch (claim.type) {
|
||||
case CURRENCY:
|
||||
// Sold item - Green
|
||||
return TINT_GREEN;
|
||||
case REFUND:
|
||||
// Outbid - Red (whether rebiddable or not)
|
||||
return TINT_RED;
|
||||
case ITEM:
|
||||
// Won item (green) or Returned/Expired (red)
|
||||
return claim.isReturned ? TINT_RED : TINT_GREEN;
|
||||
default:
|
||||
return TINT_GREEN;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -247,12 +308,41 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
} else if (tradesContainer.isBiddingAt(slot)) {
|
||||
tooltip.add(EnumChatFormatting.AQUA + StatCollector.translateToLocal("auction.trades.activeBid"));
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.trades.winningBid"));
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.trades.leftClickToIncrease"));
|
||||
}
|
||||
} else if (claim != null) {
|
||||
if (claim.type == EnumClaimType.REFUND) {
|
||||
tooltip.add(EnumChatFormatting.RED + StatCollector.translateToLocal("auction.trades.refundClaim"));
|
||||
} else {
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.trades.pendingClaim"));
|
||||
switch (claim.type) {
|
||||
case CURRENCY:
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.trades.soldClaim"));
|
||||
if (!claim.itemName.isEmpty()) {
|
||||
tooltip.add(EnumChatFormatting.WHITE + claim.itemName);
|
||||
}
|
||||
if (!claim.otherPlayerName.isEmpty()) {
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.trades.buyer") + ": " + EnumChatFormatting.AQUA + claim.otherPlayerName);
|
||||
}
|
||||
tooltip.add(EnumChatFormatting.GOLD + String.format("%,d", claim.currency) + " " + AuctionClientConfig.getCurrencyName());
|
||||
break;
|
||||
case REFUND:
|
||||
tooltip.add(EnumChatFormatting.RED + StatCollector.translateToLocal("auction.trades.outbid"));
|
||||
if (!claim.otherPlayerName.isEmpty()) {
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.trades.outbidBy") + ": " + EnumChatFormatting.AQUA + claim.otherPlayerName);
|
||||
}
|
||||
tooltip.add(EnumChatFormatting.GOLD + String.format("%,d", claim.currency) + " " + AuctionClientConfig.getCurrencyName());
|
||||
// Show rebid option if item is present (active listing)
|
||||
if (claim.item != null) {
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.trades.leftClickRebid"));
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.trades.rightClickRefund"));
|
||||
return; // Skip the generic claim message
|
||||
}
|
||||
break;
|
||||
case ITEM:
|
||||
if (claim.isReturned) {
|
||||
tooltip.add(EnumChatFormatting.RED + StatCollector.translateToLocal("auction.trades.expiredClaim"));
|
||||
} else {
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.trades.wonClaim"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.trades.leftClickToClaim"));
|
||||
} else if (slot >= maxTradeSlots) {
|
||||
@@ -280,7 +370,14 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if (compound.hasKey("TradesUpdate")) {
|
||||
if (compound.hasKey("TradesData")) {
|
||||
// Full trades data received from server
|
||||
tradesContainer.setTradesData(compound);
|
||||
// Update max trade slots from server (permission-aware)
|
||||
this.maxTradeSlots = tradesContainer.getMaxTradeSlots();
|
||||
clearPending();
|
||||
} else if (compound.hasKey("TradesUpdate")) {
|
||||
// Legacy flag - should not happen now but keep for safety
|
||||
tradesContainer.refreshData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
* Shows minimum bid, player balance, and input field.
|
||||
*/
|
||||
public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListener {
|
||||
private static final int TXT_BID = 1;
|
||||
private static final int BTN_BID = 10;
|
||||
private static final int BTN_CANCEL = 11;
|
||||
private int txtBidId = 1;
|
||||
private int btnBidId = 10;
|
||||
private int btnCancelId = 11;
|
||||
|
||||
private final String listingId;
|
||||
private final long minimumBid;
|
||||
@@ -47,25 +47,21 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
|
||||
int y = guiTop + 15;
|
||||
String currencyName = AuctionClientConfig.getCurrencyName();
|
||||
|
||||
// Title
|
||||
addLabel(new GuiNpcLabel(0, "auction.bid.title", centerX - 50, y, 0xFFFFFF));
|
||||
y += 18;
|
||||
|
||||
// Minimum bid info
|
||||
String minText = StatCollector.translateToLocal("auction.bid.minimum")
|
||||
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(minimumBid) + " " + currencyName);
|
||||
addLabel(new GuiNpcLabel(1, minText, guiLeft + 15, y, 0xAAAAAA));
|
||||
.replace("%s", EnumChatFormatting.DARK_RED + formatCurrency(minimumBid) + " " + currencyName);
|
||||
addLabel(new GuiNpcLabel(1, minText, guiLeft + 15, y));
|
||||
y += 14;
|
||||
|
||||
// Your balance
|
||||
String balanceText = StatCollector.translateToLocal("auction.bid.yourBalance")
|
||||
.replace("%s", EnumChatFormatting.WHITE + formatCurrency(playerBalance) + " " + currencyName);
|
||||
addLabel(new GuiNpcLabel(2, balanceText, guiLeft + 15, y, 0xAAAAAA));
|
||||
.replace("%s", EnumChatFormatting.DARK_GREEN + formatCurrency(playerBalance) + " " + currencyName);
|
||||
addLabel(new GuiNpcLabel(2, balanceText, guiLeft + 15, y));
|
||||
y += 18;
|
||||
|
||||
// Bid amount field
|
||||
addLabel(new GuiNpcLabel(3, "auction.bid.yourBid", guiLeft + 15, y + 4, 0xFFFFFF));
|
||||
GuiNpcTextField bidField = new GuiNpcTextField(TXT_BID, this, fontRendererObj,
|
||||
addLabel(new GuiNpcLabel(3, "auction.bid.yourBid", guiLeft + 15, y + 4));
|
||||
GuiNpcTextField bidField = new GuiNpcTextField(txtBidId, this, fontRendererObj,
|
||||
guiLeft + 80, y, 100, 18, String.valueOf(minimumBid));
|
||||
bidField.setIntegersOnly();
|
||||
addTextField(bidField);
|
||||
@@ -81,13 +77,13 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
|
||||
int totalBtnWidth = btnWidth * 2 + btnSpacing;
|
||||
int btnX = centerX - totalBtnWidth / 2;
|
||||
|
||||
addButton(new GuiNpcButton(BTN_BID, btnX, y, btnWidth, 20, "auction.bid.placeBid"));
|
||||
addButton(new GuiNpcButton(BTN_CANCEL, btnX + btnWidth + btnSpacing, y, btnWidth, 20, "gui.cancel"));
|
||||
addButton(new GuiNpcButton(btnBidId, btnX, y, btnWidth, 20, "auction.bid.placeBid"));
|
||||
addButton(new GuiNpcButton(btnCancelId, btnX + btnWidth + btnSpacing, y, btnWidth, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textfield) {
|
||||
if (textfield.id == TXT_BID) {
|
||||
if (textfield.id == txtBidId) {
|
||||
try {
|
||||
bidAmount = Long.parseLong(textfield.getText());
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -100,19 +96,16 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton button) {
|
||||
switch (button.id) {
|
||||
case BTN_BID:
|
||||
placeBid();
|
||||
break;
|
||||
case BTN_CANCEL:
|
||||
close();
|
||||
break;
|
||||
if (button.id == btnBidId) {
|
||||
placeBid();
|
||||
} else if (button.id == btnCancelId) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
private void placeBid() {
|
||||
// Get latest value from text field
|
||||
GuiNpcTextField bidField = getTextField(TXT_BID);
|
||||
GuiNpcTextField bidField = getTextField(txtBidId);
|
||||
if (bidField != null) {
|
||||
try {
|
||||
bidAmount = Long.parseLong(bidField.getText());
|
||||
|
||||
@@ -14,8 +14,8 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
* Shows buyout price, player balance, and confirmation buttons.
|
||||
*/
|
||||
public class SubGuiAuctionBuyNow extends SubGuiInterface {
|
||||
private static final int BTN_CONFIRM = 10;
|
||||
private static final int BTN_CANCEL = 11;
|
||||
private int btnConfirmId = 10;
|
||||
private int btnCancelId = 11;
|
||||
|
||||
private final String listingId;
|
||||
private final long buyoutPrice;
|
||||
@@ -44,25 +44,25 @@ public class SubGuiAuctionBuyNow extends SubGuiInterface {
|
||||
// Title
|
||||
String title = StatCollector.translateToLocal("auction.buyout.title");
|
||||
int titleWidth = fontRendererObj.getStringWidth(title);
|
||||
addLabel(new GuiNpcLabel(0, title, centerX - titleWidth / 2, y, 0xFFFFFF));
|
||||
addLabel(new GuiNpcLabel(0, title, centerX - titleWidth / 2, y));
|
||||
y += 20;
|
||||
|
||||
// Confirmation message
|
||||
String confirmMsg = StatCollector.translateToLocal("auction.buyout.confirm");
|
||||
int confirmWidth = fontRendererObj.getStringWidth(confirmMsg);
|
||||
addLabel(new GuiNpcLabel(1, confirmMsg, centerX - confirmWidth / 2, y, 0xAAAAAA));
|
||||
addLabel(new GuiNpcLabel(1, confirmMsg, centerX - confirmWidth / 2, y));
|
||||
y += 16;
|
||||
|
||||
// Buyout price
|
||||
String priceText = EnumChatFormatting.GREEN + formatCurrency(buyoutPrice) + " " + currencyName;
|
||||
String priceText = EnumChatFormatting.DARK_RED + formatCurrency(buyoutPrice) + " " + currencyName;
|
||||
int priceWidth = fontRendererObj.getStringWidth(priceText);
|
||||
addLabel(new GuiNpcLabel(2, priceText, centerX - priceWidth / 2, y, 0xFFFFFF));
|
||||
addLabel(new GuiNpcLabel(2, priceText, centerX - priceWidth / 2, y));
|
||||
y += 20;
|
||||
|
||||
// Your balance
|
||||
String balanceLabel = StatCollector.translateToLocal("auction.bid.yourBalance");
|
||||
String balanceText = balanceLabel.replace("%s", EnumChatFormatting.WHITE + formatCurrency(playerBalance) + " " + currencyName);
|
||||
addLabel(new GuiNpcLabel(3, balanceText, guiLeft + 20, y, 0xAAAAAA));
|
||||
String balanceText = balanceLabel.replace("%s", EnumChatFormatting.DARK_GREEN + formatCurrency(playerBalance) + " " + currencyName);
|
||||
addLabel(new GuiNpcLabel(3, balanceText, guiLeft + 20, y));
|
||||
y += 14;
|
||||
|
||||
// Insufficient funds warning
|
||||
@@ -78,23 +78,20 @@ public class SubGuiAuctionBuyNow extends SubGuiInterface {
|
||||
int totalBtnWidth = btnWidth * 2 + btnSpacing;
|
||||
int btnX = centerX - totalBtnWidth / 2;
|
||||
|
||||
GuiNpcButton confirmBtn = new GuiNpcButton(BTN_CONFIRM, btnX, y, btnWidth, 20, "gui.yes");
|
||||
GuiNpcButton confirmBtn = new GuiNpcButton(btnConfirmId, btnX, y, btnWidth, 20, "gui.yes");
|
||||
confirmBtn.enabled = playerBalance >= buyoutPrice;
|
||||
addButton(confirmBtn);
|
||||
addButton(new GuiNpcButton(BTN_CANCEL, btnX + btnWidth + btnSpacing, y, btnWidth, 20, "gui.cancel"));
|
||||
addButton(new GuiNpcButton(btnCancelId, btnX + btnWidth + btnSpacing, y, btnWidth, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton button) {
|
||||
switch (button.id) {
|
||||
case BTN_CONFIRM:
|
||||
if (playerBalance >= buyoutPrice) {
|
||||
confirmPurchase();
|
||||
}
|
||||
break;
|
||||
case BTN_CANCEL:
|
||||
close();
|
||||
break;
|
||||
if (button.id == btnConfirmId) {
|
||||
if (playerBalance >= buyoutPrice) {
|
||||
confirmPurchase();
|
||||
}
|
||||
} else if (button.id == btnCancelId) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,16 +11,14 @@ import java.util.Arrays;
|
||||
public class ConfigMarket {
|
||||
public static Configuration config;
|
||||
|
||||
public final static String MARKET = "Market";
|
||||
public final static String CURRENCY = "Market.Currency";
|
||||
public final static String TRADER = "Market.Trader";
|
||||
public final static String AUCTION = "Market.Auction";
|
||||
public final static String AUCTION_BLACKLIST = "Market.Auction.Blacklist";
|
||||
public final static String AUCTION_LOGGING = "Market.Auction.Logging";
|
||||
|
||||
// =========================================
|
||||
// Market General
|
||||
// =========================================
|
||||
public static boolean MarketEnabled = true;
|
||||
// Max trades grid = 9x5 = 45 slots
|
||||
public static final int MAX_TRADE_SLOTS = 45;
|
||||
public static final int MIN_TRADE_SLOTS = 1;
|
||||
|
||||
// =========================================
|
||||
// Currency Settings
|
||||
@@ -30,25 +28,28 @@ public class ConfigMarket {
|
||||
public static long StartingBalance = 0;
|
||||
public static long MaxBalance = Long.MAX_VALUE;
|
||||
|
||||
// =========================================
|
||||
// Trader Settings
|
||||
// =========================================
|
||||
public static boolean EnableStockByDefault = false;
|
||||
public static String DefaultResetType = "NONE";
|
||||
|
||||
// =========================================
|
||||
// Auction Settings
|
||||
// =========================================
|
||||
public static boolean AuctionEnabled = true;
|
||||
public static int AuctionDurationHours = 24;
|
||||
public static long ListingFee = 10;
|
||||
public static long MinimumListingPrice = 1;
|
||||
public static double SalesTaxPercent = 0.05;
|
||||
public static int DefaultMaxListings = 5;
|
||||
public static int DefaultMaxTrades = 8;
|
||||
public static int SnipeProtectionMinutes = 2;
|
||||
public static int ClaimExpirationDays = 20;
|
||||
public static double MinBidIncrementPercent = 0.05;
|
||||
public static double CancellationPenaltyPercent = 0.10;
|
||||
|
||||
// =========================================
|
||||
// Auction Blacklist Settings
|
||||
// =========================================
|
||||
public static boolean BlacklistEnabled = true;
|
||||
public static String[] BlacklistedItems = new String[]{};
|
||||
public static String[] BlacklistedMods = new String[]{};
|
||||
public static String[] BlacklistedNBTTags = new String[]{};
|
||||
|
||||
// =========================================
|
||||
// Auction Logging Settings
|
||||
// =========================================
|
||||
@@ -67,12 +68,6 @@ public class ConfigMarket {
|
||||
try {
|
||||
config.load();
|
||||
|
||||
// =========================================
|
||||
// Market General
|
||||
// =========================================
|
||||
MarketEnabled = config.get(MARKET, "Enable Market System", true,
|
||||
"Enable the market/economy system").getBoolean(true);
|
||||
|
||||
// =========================================
|
||||
// Currency Settings
|
||||
// =========================================
|
||||
@@ -90,24 +85,13 @@ public class ConfigMarket {
|
||||
MaxBalance = config.get(CURRENCY, "Max Balance", Integer.MAX_VALUE,
|
||||
"Maximum currency balance a player can have").getInt(Integer.MAX_VALUE);
|
||||
|
||||
// =========================================
|
||||
// Trader Settings
|
||||
// =========================================
|
||||
config.setCategoryComment(TRADER, "Trader stock system settings");
|
||||
|
||||
EnableStockByDefault = config.get(TRADER, "Enable Stock By Default", false,
|
||||
"Enable stock system by default for new traders").getBoolean(false);
|
||||
|
||||
DefaultResetType = config.get(TRADER, "Default Reset Type", "NONE",
|
||||
"Default stock reset type (NONE, MCDAILY, MCWEEKLY, RLDAILY, RLWEEKLY)").getString();
|
||||
|
||||
// =========================================
|
||||
// Auction Settings
|
||||
// =========================================
|
||||
config.setCategoryComment(AUCTION, "Auction House system settings. The Auction House allows players to list items for sale with bidding and buyout options.");
|
||||
config.setCategoryComment(AUCTION, "Auction system settings. The Auction allows players to list items for sale with bidding and buyout options.");
|
||||
|
||||
AuctionEnabled = config.get(AUCTION, "Enable Auction House", true,
|
||||
"Enable the Auction House system").getBoolean(true);
|
||||
AuctionEnabled = config.get(AUCTION, "Enable Auction", true,
|
||||
"Enable the Auction system").getBoolean(true);
|
||||
|
||||
AuctionDurationHours = config.get(AUCTION, "Auction Duration Hours", 24,
|
||||
"Default duration for auctions in hours").getInt(24);
|
||||
@@ -115,11 +99,16 @@ public class ConfigMarket {
|
||||
ListingFee = config.get(AUCTION, "Listing Fee", 10,
|
||||
"Flat fee charged when creating a listing").getInt(10);
|
||||
|
||||
MinimumListingPrice = config.get(AUCTION, "Minimum Listing Price", 1,
|
||||
"Minimum starting price for auction listings").getInt(1);
|
||||
if (MinimumListingPrice < 1) MinimumListingPrice = 1;
|
||||
|
||||
SalesTaxPercent = config.get(AUCTION, "Sales Tax Percent", 0.05,
|
||||
"Percentage of sale price taken as tax (0.05 = 5%). Tax is deleted as a currency sink.").getDouble(0.05);
|
||||
|
||||
DefaultMaxListings = config.get(AUCTION, "Default Max Listings", 5,
|
||||
"Default maximum number of active listings per player").getInt(5);
|
||||
int maxTrades = config.get(AUCTION, "Default Max Trades", 8,
|
||||
"Default maximum number of trade slots per player (listings + bids + claims). Min: 1, Max: 45. Players can have more via customnpcs.auction.trades.X permissions.").getInt(8);
|
||||
DefaultMaxTrades = Math.max(MIN_TRADE_SLOTS, Math.min(MAX_TRADE_SLOTS, maxTrades));
|
||||
|
||||
SnipeProtectionMinutes = config.get(AUCTION, "Snipe Protection Minutes", 2,
|
||||
"When a bid is placed with less than this many minutes remaining, the auction is extended to this duration").getInt(2);
|
||||
@@ -133,10 +122,49 @@ public class ConfigMarket {
|
||||
CancellationPenaltyPercent = config.get(AUCTION, "Cancellation Penalty Percent", 0.10,
|
||||
"Percentage of current bid taken as penalty when seller cancels an auction with bids (0.10 = 10%)").getDouble(0.10);
|
||||
|
||||
// =========================================
|
||||
// Auction Blacklist Settings
|
||||
// =========================================
|
||||
config.setCategoryComment(AUCTION_BLACKLIST,
|
||||
"Item Blacklist settings for the Auction House.\n" +
|
||||
"Prevents specific items, mods, or items with certain NBT tags from being listed.\n\n" +
|
||||
"ITEM FORMAT: Use 'modid:itemname' format (e.g., 'minecraft:bedrock', 'customnpcs:npcWand')\n" +
|
||||
"WILDCARDS: Use * for wildcards (e.g., 'customnpcs:npc*' blocks all items starting with 'npc')\n" +
|
||||
"MOD FORMAT: Use just the mod ID (e.g., 'projecte' blocks all items from that mod)\n" +
|
||||
"NBT FORMAT: Use the NBT tag key name (e.g., 'AdminOnly' blocks items with that tag)");
|
||||
|
||||
BlacklistEnabled = config.get(AUCTION_BLACKLIST, "Enable Blacklist", true,
|
||||
"Enable item blacklist checking when creating listings").getBoolean(true);
|
||||
|
||||
BlacklistedItems = config.get(AUCTION_BLACKLIST, "Blacklisted Items", new String[]{
|
||||
"minecraft:bedrock",
|
||||
"minecraft:command_block",
|
||||
"customnpcs:npcWand",
|
||||
"customnpcs:npcMobCloner",
|
||||
"customnpcs:npcScripter",
|
||||
"customnpcs:npcMovingPath",
|
||||
"customnpcs:npcMounter",
|
||||
"customnpcs:npcTeleporter",
|
||||
"customnpcs:npcTool",
|
||||
"customnpcs:npcSoulstoneFilled"
|
||||
},
|
||||
"Items that cannot be listed on the Auction House.\n" +
|
||||
"Format: modid:itemname (supports * wildcards)\n" +
|
||||
"Example: 'minecraft:diamond_sword' or 'customnpcs:npc*'").getStringList();
|
||||
|
||||
BlacklistedMods = config.get(AUCTION_BLACKLIST, "Blacklisted Mods", new String[]{},
|
||||
"All items from these mods are blocked from the Auction House.\n" +
|
||||
"Format: modid (e.g., 'projecte', 'thaumcraft')").getStringList();
|
||||
|
||||
BlacklistedNBTTags = config.get(AUCTION_BLACKLIST, "Blacklisted NBT Tags", new String[]{},
|
||||
"Items containing any of these NBT tag keys are blocked.\n" +
|
||||
"Checks the root level of the item's NBT compound.\n" +
|
||||
"Example: 'AdminOnly', 'CreativeMode'").getStringList();
|
||||
|
||||
// =========================================
|
||||
// Auction Logging Settings
|
||||
// =========================================
|
||||
config.setCategoryComment(AUCTION_LOGGING, "Auction House logging settings. Enable specific log types to track auction activity.");
|
||||
config.setCategoryComment(AUCTION_LOGGING, "Auction logging settings. Enable specific log types to track auction activity.");
|
||||
|
||||
AuctionLoggingEnabled = config.get(AUCTION_LOGGING, "Enable Auction Logging", false,
|
||||
"Master switch for auction logging. If false, no auction events are logged.").getBoolean(false);
|
||||
@@ -163,10 +191,6 @@ public class ConfigMarket {
|
||||
"Log when claims are collected").getBoolean(true);
|
||||
|
||||
// Set category order
|
||||
config.setCategoryPropertyOrder(MARKET, new ArrayList<>(Arrays.asList(
|
||||
"Enable Market System"
|
||||
)));
|
||||
|
||||
config.setCategoryPropertyOrder(CURRENCY, new ArrayList<>(Arrays.asList(
|
||||
"Use Vault",
|
||||
"Currency Name",
|
||||
@@ -174,23 +198,26 @@ public class ConfigMarket {
|
||||
"Max Balance"
|
||||
)));
|
||||
|
||||
config.setCategoryPropertyOrder(TRADER, new ArrayList<>(Arrays.asList(
|
||||
"Enable Stock By Default",
|
||||
"Default Reset Type"
|
||||
)));
|
||||
|
||||
config.setCategoryPropertyOrder(AUCTION, new ArrayList<>(Arrays.asList(
|
||||
"Enable Auction House",
|
||||
"Enable Auction",
|
||||
"Auction Duration Hours",
|
||||
"Listing Fee",
|
||||
"Minimum Listing Price",
|
||||
"Sales Tax Percent",
|
||||
"Default Max Listings",
|
||||
"Default Max Trades",
|
||||
"Snipe Protection Minutes",
|
||||
"Claim Expiration Days",
|
||||
"Min Bid Increment Percent",
|
||||
"Cancellation Penalty Percent"
|
||||
)));
|
||||
|
||||
config.setCategoryPropertyOrder(AUCTION_BLACKLIST, new ArrayList<>(Arrays.asList(
|
||||
"Enable Blacklist",
|
||||
"Blacklisted Items",
|
||||
"Blacklisted Mods",
|
||||
"Blacklisted NBT Tags"
|
||||
)));
|
||||
|
||||
config.setCategoryPropertyOrder(AUCTION_LOGGING, new ArrayList<>(Arrays.asList(
|
||||
"Enable Auction Logging",
|
||||
"Log Created",
|
||||
|
||||
@@ -14,9 +14,9 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
*/
|
||||
public class ContainerAuctionBidding extends ContainerAuction {
|
||||
// Display slot layout
|
||||
public static final int ITEM_SLOT_X = 75;
|
||||
public static final int ITEM_SLOT_Y = 70;
|
||||
public static final int ITEM_SLOT_INDEX = PLAYER_INV_SLOT_COUNT;
|
||||
private int itemSlotX = 71;
|
||||
private int itemSlotY = 76;
|
||||
private int itemSlotIndex = PLAYER_INV_SLOT_COUNT;
|
||||
|
||||
private final IInventory displayInventory;
|
||||
private AuctionListing listing;
|
||||
@@ -26,7 +26,7 @@ public class ContainerAuctionBidding extends ContainerAuction {
|
||||
displayInventory = new InventoryBasic("Display", false, 1);
|
||||
|
||||
// Display slot (read-only)
|
||||
addSlotToContainer(new Slot(displayInventory, 0, ITEM_SLOT_X, ITEM_SLOT_Y) {
|
||||
addSlotToContainer(new Slot(displayInventory, 0, itemSlotX, itemSlotY) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) { return false; }
|
||||
@Override
|
||||
@@ -58,6 +58,6 @@ public class ContainerAuctionBidding extends ContainerAuction {
|
||||
* Check if this is the display slot.
|
||||
*/
|
||||
public boolean isDisplaySlot(int slotIndex) {
|
||||
return slotIndex == ITEM_SLOT_INDEX;
|
||||
return slotIndex == itemSlotIndex;
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,10 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
* Items are cloned from inventory, not moved. Validation happens on submit.
|
||||
*/
|
||||
public class ContainerAuctionSell extends ContainerAuction {
|
||||
public static final int SELL_SLOT_X = 101;
|
||||
public static final int SELL_SLOT_Y = 106;
|
||||
public static final int SELL_SLOT_INDEX = PLAYER_INV_SLOT_COUNT;
|
||||
private static final int MAX_STACK = 64;
|
||||
private int sellSlotX = 59;
|
||||
private int sellSlotY = 101;
|
||||
private int sellSlotIndex = PLAYER_INV_SLOT_COUNT;
|
||||
private int maxStack = 64;
|
||||
|
||||
private final IInventory sellInventory;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
sellInventory = new InventoryBasic("Sell", false, 1);
|
||||
|
||||
// Sell slot blocks direct interaction
|
||||
addSlotToContainer(new Slot(sellInventory, 0, SELL_SLOT_X, SELL_SLOT_Y) {
|
||||
addSlotToContainer(new Slot(sellInventory, 0, sellSlotX, sellSlotY) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) { return false; }
|
||||
@Override
|
||||
@@ -59,11 +59,11 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
if (sellStack == null) {
|
||||
// Empty slot - create new stack
|
||||
ItemStack newStack = source.copy();
|
||||
newStack.stackSize = Math.min(toAdd, MAX_STACK);
|
||||
newStack.stackSize = Math.min(toAdd, maxStack);
|
||||
sellInventory.setInventorySlotContents(0, newStack);
|
||||
} else if (itemsMatch(sellStack, source)) {
|
||||
// Same item - add to existing (capped at 64)
|
||||
int space = MAX_STACK - sellStack.stackSize;
|
||||
int space = maxStack - sellStack.stackSize;
|
||||
int add = Math.min(toAdd, space);
|
||||
if (add > 0) {
|
||||
sellStack.stackSize += add;
|
||||
@@ -71,7 +71,7 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
} else {
|
||||
// Different item - replace
|
||||
ItemStack newStack = source.copy();
|
||||
newStack.stackSize = Math.min(toAdd, MAX_STACK);
|
||||
newStack.stackSize = Math.min(toAdd, maxStack);
|
||||
sellInventory.setInventorySlotContents(0, newStack);
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
|
||||
/** Check if sell slot is this container slot index */
|
||||
public boolean isSellSlot(int slotIndex) {
|
||||
return slotIndex == SELL_SLOT_INDEX;
|
||||
return slotIndex == sellSlotIndex;
|
||||
}
|
||||
|
||||
/** Check if two stacks match using NoppesUtilPlayer.compareItems (same item, damage, and NBT) */
|
||||
|
||||
@@ -2,6 +2,9 @@ package noppes.npcs.containers;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.constants.EnumClaimType;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
import noppes.npcs.controllers.data.AuctionClaim;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
@@ -13,6 +16,7 @@ import java.util.List;
|
||||
/**
|
||||
* Container for viewing player's auction trades.
|
||||
* Shows active listings, bids, and claims in a 9x5 grid.
|
||||
* Order: SOLD claims, OUTBID claims, WON claims, SELLING, BIDDING, EXPIRED claims
|
||||
*/
|
||||
public class ContainerAuctionTrades extends ContainerAuction {
|
||||
// Grid layout
|
||||
@@ -27,6 +31,11 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
private List<AuctionListing> activeBids = new ArrayList<>();
|
||||
private List<AuctionClaim> claims = new ArrayList<>();
|
||||
private int hiddenSlot = -1;
|
||||
private int maxTradeSlots = 8; // Player's max trade slots (permission-aware, synced from server)
|
||||
|
||||
// Slot type tracking for proper accessor methods
|
||||
private int[] slotTypes = new int[SLOT_COUNT]; // 0=empty, 1=selling, 2=bidding, 3=claim
|
||||
private int[] slotDataIndex = new int[SLOT_COUNT]; // Index into respective list
|
||||
|
||||
public ContainerAuctionTrades(EntityNPCInterface npc, EntityPlayer player) {
|
||||
super(npc, player);
|
||||
@@ -44,34 +53,163 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
refreshData();
|
||||
}
|
||||
|
||||
/** Refresh data from controller */
|
||||
/** Refresh data from controller (server-side only) */
|
||||
public void refreshData() {
|
||||
// Clear existing data
|
||||
clearData();
|
||||
|
||||
// Only works on server where AuctionController exists
|
||||
if (AuctionController.Instance == null) return;
|
||||
|
||||
List<AuctionListing> newListings = AuctionController.Instance.getPlayerActiveListings(player.getUniqueID());
|
||||
List<AuctionListing> newBids = AuctionController.Instance.getPlayerActiveBids(player.getUniqueID());
|
||||
List<AuctionClaim> newClaims = AuctionController.Instance.getPlayerClaims(player.getUniqueID());
|
||||
|
||||
populateDisplay(newListings, newBids, newClaims);
|
||||
}
|
||||
|
||||
/** Set data from NBT received from server (client-side) */
|
||||
public void setTradesData(NBTTagCompound compound) {
|
||||
// Clear existing data
|
||||
clearData();
|
||||
|
||||
// Read player's max trade slots (permission-aware)
|
||||
if (compound.hasKey("MaxTradeSlots")) {
|
||||
maxTradeSlots = compound.getInteger("MaxTradeSlots");
|
||||
}
|
||||
|
||||
List<AuctionListing> newListings = new ArrayList<>();
|
||||
List<AuctionListing> newBids = new ArrayList<>();
|
||||
List<AuctionClaim> newClaims = new ArrayList<>();
|
||||
|
||||
// Parse active listings
|
||||
if (compound.hasKey("ActiveListings")) {
|
||||
NBTTagList listingsNBT = compound.getTagList("ActiveListings", 10);
|
||||
for (int i = 0; i < listingsNBT.tagCount(); i++) {
|
||||
newListings.add(AuctionListing.fromNBT(listingsNBT.getCompoundTagAt(i)));
|
||||
}
|
||||
}
|
||||
|
||||
// Parse active bids
|
||||
if (compound.hasKey("ActiveBids")) {
|
||||
NBTTagList bidsNBT = compound.getTagList("ActiveBids", 10);
|
||||
for (int i = 0; i < bidsNBT.tagCount(); i++) {
|
||||
newBids.add(AuctionListing.fromNBT(bidsNBT.getCompoundTagAt(i)));
|
||||
}
|
||||
}
|
||||
|
||||
// Parse claims
|
||||
if (compound.hasKey("Claims")) {
|
||||
NBTTagList claimsNBT = compound.getTagList("Claims", 10);
|
||||
for (int i = 0; i < claimsNBT.tagCount(); i++) {
|
||||
newClaims.add(AuctionClaim.fromNBT(claimsNBT.getCompoundTagAt(i)));
|
||||
}
|
||||
}
|
||||
|
||||
populateDisplay(newListings, newBids, newClaims);
|
||||
}
|
||||
|
||||
/** Clear all data and reset display */
|
||||
private void clearData() {
|
||||
activeListings.clear();
|
||||
activeBids.clear();
|
||||
claims.clear();
|
||||
displayInventory.clear();
|
||||
|
||||
if (AuctionController.Instance == null) return;
|
||||
// Reset slot tracking
|
||||
for (int i = 0; i < SLOT_COUNT; i++) {
|
||||
slotTypes[i] = 0;
|
||||
slotDataIndex[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
activeListings = AuctionController.Instance.getPlayerActiveListings(player.getUniqueID());
|
||||
activeBids = AuctionController.Instance.getPlayerActiveBids(player.getUniqueID());
|
||||
claims = AuctionController.Instance.getPlayerClaims(player.getUniqueID());
|
||||
/** Populate display from provided data lists */
|
||||
private void populateDisplay(List<AuctionListing> newListings, List<AuctionListing> newBids, List<AuctionClaim> allClaims) {
|
||||
activeListings = new ArrayList<>(newListings);
|
||||
activeBids = new ArrayList<>(newBids);
|
||||
|
||||
// Populate display: listings first, then bids, then claims
|
||||
// Sort claims into categories for proper display order
|
||||
List<AuctionClaim> soldClaims = new ArrayList<>(); // CURRENCY - sold items
|
||||
List<AuctionClaim> outbidClaims = new ArrayList<>(); // REFUND - outbid refunds
|
||||
List<AuctionClaim> wonClaims = new ArrayList<>(); // ITEM won (isReturned=false)
|
||||
List<AuctionClaim> expiredClaims = new ArrayList<>(); // ITEM returned (isReturned=true)
|
||||
|
||||
for (AuctionClaim claim : allClaims) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Populate display in order: SOLD, OUTBID, WON, SELLING, BIDDING, EXPIRED
|
||||
int slot = 0;
|
||||
|
||||
// 1. Sold claims (green) - you have money to claim!
|
||||
for (AuctionClaim claim : soldClaims) {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
|
||||
// 2. Outbid claims (yellow) - refunds available
|
||||
for (AuctionClaim claim : outbidClaims) {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
|
||||
// 3. Won claims (green) - items to claim!
|
||||
for (AuctionClaim claim : wonClaims) {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
|
||||
// 4. Active listings (blue) - items you're selling
|
||||
int listingIdx = 0;
|
||||
for (AuctionListing listing : activeListings) {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
if (listing.item != null) displayInventory.setInventorySlotContents(slot, listing.item.copy());
|
||||
slotTypes[slot] = 1; // selling
|
||||
slotDataIndex[slot] = listingIdx;
|
||||
slot++;
|
||||
listingIdx++;
|
||||
}
|
||||
|
||||
// 5. Active bids (blue) - items you're bidding on
|
||||
int bidIdx = 0;
|
||||
for (AuctionListing bid : activeBids) {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
if (bid.item != null) displayInventory.setInventorySlotContents(slot, bid.item.copy());
|
||||
slotTypes[slot] = 2; // bidding
|
||||
slotDataIndex[slot] = bidIdx;
|
||||
slot++;
|
||||
bidIdx++;
|
||||
}
|
||||
for (AuctionClaim claim : claims) {
|
||||
|
||||
// 6. Expired claims (red) - returned items (lowest priority)
|
||||
for (AuctionClaim claim : expiredClaims) {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
@@ -80,37 +218,42 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
|
||||
/** Get listing at slot (or null if claim/empty) */
|
||||
public AuctionListing getListingAt(int slot) {
|
||||
if (slot >= 0 && slot < activeListings.size()) {
|
||||
return activeListings.get(slot);
|
||||
}
|
||||
int bidIdx = slot - activeListings.size();
|
||||
if (bidIdx >= 0 && bidIdx < activeBids.size()) {
|
||||
return activeBids.get(bidIdx);
|
||||
if (slot < 0 || slot >= SLOT_COUNT) return null;
|
||||
int type = slotTypes[slot];
|
||||
int idx = slotDataIndex[slot];
|
||||
if (idx < 0) return null;
|
||||
|
||||
if (type == 1 && idx < activeListings.size()) {
|
||||
return activeListings.get(idx);
|
||||
} else if (type == 2 && idx < activeBids.size()) {
|
||||
return activeBids.get(idx);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Get claim at slot (or null if listing/empty) */
|
||||
public AuctionClaim getClaimAt(int slot) {
|
||||
int claimIdx = slot - activeListings.size() - activeBids.size();
|
||||
if (claimIdx >= 0 && claimIdx < claims.size()) {
|
||||
return claims.get(claimIdx);
|
||||
if (slot < 0 || slot >= SLOT_COUNT) return null;
|
||||
if (slotTypes[slot] == 3) {
|
||||
int idx = slotDataIndex[slot];
|
||||
if (idx >= 0 && idx < claims.size()) {
|
||||
return claims.get(idx);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Check if slot is player's active listing */
|
||||
public boolean isSellingAt(int slot) {
|
||||
return slot >= 0 && slot < activeListings.size();
|
||||
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == 1;
|
||||
}
|
||||
|
||||
/** Check if slot is player's active bid */
|
||||
public boolean isBiddingAt(int slot) {
|
||||
int bidIdx = slot - activeListings.size();
|
||||
return bidIdx >= 0 && bidIdx < activeBids.size();
|
||||
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == 2;
|
||||
}
|
||||
|
||||
/** Find listing matching item */
|
||||
/** Find listing matching item (searches both selling and bidding) */
|
||||
public AuctionListing getListingForItem(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
for (AuctionListing listing : activeListings) {
|
||||
@@ -122,6 +265,24 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Find listing in selling list */
|
||||
public AuctionListing getSellingListingForItem(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
for (AuctionListing listing : activeListings) {
|
||||
if (listing.item != null && ItemStack.areItemStacksEqual(listing.item, stack)) return listing;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Find listing in bidding list */
|
||||
public AuctionListing getBiddingListingForItem(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
for (AuctionListing bid : activeBids) {
|
||||
if (bid.item != null && ItemStack.areItemStacksEqual(bid.item, stack)) return bid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Find claim matching item */
|
||||
public AuctionClaim getClaimForItem(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
@@ -159,26 +320,34 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
hiddenSlot = -1;
|
||||
}
|
||||
|
||||
/** Restore item at slot from data */
|
||||
/** Restore item at slot from data using slot tracking */
|
||||
private void restoreSlotItem(int slot) {
|
||||
if (slot < activeListings.size()) {
|
||||
AuctionListing listing = activeListings.get(slot);
|
||||
if (slot < 0 || slot >= SLOT_COUNT) return;
|
||||
|
||||
int type = slotTypes[slot];
|
||||
int idx = slotDataIndex[slot];
|
||||
if (idx < 0) return;
|
||||
|
||||
if (type == 1 && idx < activeListings.size()) {
|
||||
// Selling
|
||||
AuctionListing listing = activeListings.get(idx);
|
||||
if (listing != null && listing.item != null) {
|
||||
displayInventory.setInventorySlotContents(slot, listing.item.copy());
|
||||
}
|
||||
} else if (slot < activeListings.size() + activeBids.size()) {
|
||||
int bidIdx = slot - activeListings.size();
|
||||
AuctionListing bid = activeBids.get(bidIdx);
|
||||
} else if (type == 2 && idx < activeBids.size()) {
|
||||
// Bidding
|
||||
AuctionListing bid = activeBids.get(idx);
|
||||
if (bid != null && bid.item != null) {
|
||||
displayInventory.setInventorySlotContents(slot, bid.item.copy());
|
||||
}
|
||||
} else {
|
||||
int claimIdx = slot - activeListings.size() - activeBids.size();
|
||||
if (claimIdx < claims.size()) {
|
||||
displayInventory.setClaimItem(slot, claims.get(claimIdx));
|
||||
}
|
||||
} else if (type == 3 && idx < claims.size()) {
|
||||
// Claim
|
||||
displayInventory.setClaimItem(slot, claims.get(idx));
|
||||
}
|
||||
}
|
||||
|
||||
public int getHiddenSlot() { return hiddenSlot; }
|
||||
|
||||
/** Get player's max trade slots (synced from server based on permissions) */
|
||||
public int getMaxTradeSlots() { return maxTradeSlots; }
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class ContainerNPCTrader extends ContainerNpcInterface {
|
||||
long currencyCost = role.getCurrencyCost(i);
|
||||
if (currencyCost > 0) {
|
||||
PlayerData data = PlayerData.get(entityplayer);
|
||||
if (data.currencyData.getBalance() < currencyCost) {
|
||||
if (data.tradeData.getBalance() < currencyCost) {
|
||||
return null; // Can't afford currency cost
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class ContainerNPCTrader extends ContainerNpcInterface {
|
||||
// Withdraw currency cost (after item consumption to maintain order)
|
||||
if (currencyCost > 0) {
|
||||
PlayerData data = PlayerData.get(entityplayer);
|
||||
data.currencyData.withdraw(currencyCost);
|
||||
data.tradeData.withdraw(currencyCost);
|
||||
}
|
||||
|
||||
// Consume stock
|
||||
|
||||
@@ -3,7 +3,6 @@ package noppes.npcs.containers;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.constants.EnumClaimType;
|
||||
import noppes.npcs.controllers.data.AuctionClaim;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
@@ -49,19 +48,26 @@ public class InventoryAuctionDisplay implements IInventory {
|
||||
|
||||
/**
|
||||
* Set a claim item in the inventory.
|
||||
* For ITEM claims, shows the item.
|
||||
* For CURRENCY/REFUND claims, shows a gold coin as visual representation.
|
||||
* Shows actual item for ITEM claims.
|
||||
* For CURRENCY claims, shows coin icon (null item).
|
||||
* For REFUND claims, shows item if present (for rebid option), otherwise coin icon.
|
||||
*/
|
||||
public void setClaimItem(int slot, AuctionClaim claim) {
|
||||
if (slot >= 0 && slot < size) {
|
||||
claims.set(slot, claim);
|
||||
listings.set(slot, null);
|
||||
if (claim != null) {
|
||||
if (claim.type == EnumClaimType.ITEM && claim.item != null) {
|
||||
items[slot] = claim.item;
|
||||
if (claim.type == EnumClaimType.CURRENCY) {
|
||||
// Sold - gold coin icon drawn by GUI
|
||||
items[slot] = null;
|
||||
} else if (claim.type == EnumClaimType.REFUND) {
|
||||
// Outbid - show item if present (for rebid), otherwise coin
|
||||
items[slot] = claim.item != null ? claim.item.copy() : null;
|
||||
} else if (claim.item != null) {
|
||||
// Show actual item for ITEM claims
|
||||
items[slot] = claim.item.copy();
|
||||
} else {
|
||||
// For currency claims, show a gold coin
|
||||
items[slot] = new ItemStack(CustomItems.coinGold);
|
||||
items[slot] = null;
|
||||
}
|
||||
} else {
|
||||
items[slot] = null;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class AuctionConfigSync {
|
||||
compound.setString("CurrencyName", getEffectiveCurrencyName());
|
||||
compound.setInteger("AuctionDurationHours", ConfigMarket.AuctionDurationHours);
|
||||
compound.setDouble("MinBidIncrement", ConfigMarket.MinBidIncrementPercent);
|
||||
compound.setInteger("MaxActiveListings", ConfigMarket.DefaultMaxListings);
|
||||
compound.setInteger("MaxActiveListings", ConfigMarket.DefaultMaxTrades);
|
||||
compound.setInteger("ClaimExpirationDays", ConfigMarket.ClaimExpirationDays);
|
||||
return compound;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -364,6 +364,17 @@ public class PlayerDataController {
|
||||
return data;
|
||||
}
|
||||
|
||||
public PlayerData getData(UUID uuid) {
|
||||
EntityPlayer player = getPlayerFromUUID(uuid);
|
||||
PlayerData data;
|
||||
if (player == null) {
|
||||
data = new PlayerData();
|
||||
data.setNBT(PlayerDataController.Instance.loadPlayerData(uuid.toString()));
|
||||
} else
|
||||
data = PlayerData.get(player);
|
||||
return data;
|
||||
}
|
||||
|
||||
public void addPlayerMessage(String username, PlayerMail mail) {
|
||||
mail.time = System.currentTimeMillis();
|
||||
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import kamkeel.npcs.util.AttributeItemUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AuctionBlacklist {
|
||||
private static Set<String> blacklistedItems = new HashSet<>();
|
||||
private static Set<Pattern> wildcardPatterns = new HashSet<>();
|
||||
private static Set<String> blacklistedMods = new HashSet<>();
|
||||
private static Set<String> blacklistedNBTTags = new HashSet<>();
|
||||
|
||||
// Built-in bound item requirement keys (always blocked)
|
||||
private static final String SOULBIND_KEY = "cnpc_soulbind";
|
||||
private static final String PROFILE_SLOT_KEY = "cnpc_profile_slot";
|
||||
|
||||
// Bypass permission
|
||||
private static final String BYPASS_PERMISSION = "customnpcs.auction.blacklist.bypass";
|
||||
|
||||
public static void reload() {
|
||||
blacklistedItems.clear();
|
||||
wildcardPatterns.clear();
|
||||
blacklistedMods.clear();
|
||||
blacklistedNBTTags.clear();
|
||||
|
||||
// Load blacklisted items
|
||||
for (String item : ConfigMarket.BlacklistedItems) {
|
||||
if (item == null || item.isEmpty()) continue;
|
||||
item = item.toLowerCase().trim();
|
||||
|
||||
if (item.contains("*")) {
|
||||
String regex = "^" + item.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
wildcardPatterns.add(Pattern.compile(regex));
|
||||
} else {
|
||||
blacklistedItems.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Load blacklisted mods
|
||||
for (String mod : ConfigMarket.BlacklistedMods) {
|
||||
if (mod == null || mod.isEmpty()) continue;
|
||||
blacklistedMods.add(mod.toLowerCase().trim());
|
||||
}
|
||||
|
||||
// Load blacklisted NBT tags
|
||||
for (String tag : ConfigMarket.BlacklistedNBTTags) {
|
||||
if (tag == null || tag.isEmpty()) continue;
|
||||
blacklistedNBTTags.add(tag.trim());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player can bypass the blacklist (OP or has permission)
|
||||
*/
|
||||
public static boolean canBypass(EntityPlayer player) {
|
||||
if (player == null) return false;
|
||||
|
||||
// Check OP status
|
||||
if (player.canCommandSenderUseCommand(2, BYPASS_PERMISSION)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check custom permission
|
||||
return CustomNpcsPermissions.hasCustomPermission(player, BYPASS_PERMISSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is blacklisted (without bypass check)
|
||||
*/
|
||||
public static boolean isBlacklisted(ItemStack item) {
|
||||
if (!ConfigMarket.BlacklistEnabled) return false;
|
||||
if (item == null || item.getItem() == null) return true;
|
||||
|
||||
// Check bound items (always blocked, even if blacklist is "disabled")
|
||||
if (hasBoundRequirement(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get registry name
|
||||
GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(item.getItem());
|
||||
if (uid == null) return true;
|
||||
|
||||
String registryName = (uid.modId + ":" + uid.name).toLowerCase();
|
||||
String modId = uid.modId.toLowerCase();
|
||||
|
||||
// Check exact item match
|
||||
if (blacklistedItems.contains(registryName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check wildcard patterns
|
||||
for (Pattern pattern : wildcardPatterns) {
|
||||
if (pattern.matcher(registryName).matches()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check mod blacklist
|
||||
if (blacklistedMods.contains(modId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check NBT tags
|
||||
if (item.hasTagCompound() && !blacklistedNBTTags.isEmpty()) {
|
||||
NBTTagCompound tag = item.getTagCompound();
|
||||
for (String nbtKey : blacklistedNBTTags) {
|
||||
if (tag.hasKey(nbtKey)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is blacklisted for a specific player (with bypass check)
|
||||
*/
|
||||
public static boolean isBlacklistedForPlayer(ItemStack item, EntityPlayer player) {
|
||||
if (canBypass(player)) return false;
|
||||
return isBlacklisted(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registry name of an item
|
||||
*/
|
||||
public static String getRegistryName(ItemStack item) {
|
||||
if (item == null || item.getItem() == null) return null;
|
||||
GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(item.getItem());
|
||||
if (uid == null) return null;
|
||||
return uid.modId + ":" + uid.name;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Bound Item Checking (RPGCore/Requirements)
|
||||
// =========================================
|
||||
|
||||
/**
|
||||
* Check if item has soulbind or profile slot requirement.
|
||||
* Requirements are stored under: item.stackTagCompound/RPGCore/Requirements
|
||||
*/
|
||||
private static boolean hasBoundRequirement(ItemStack item) {
|
||||
if (item == null || !item.hasTagCompound()) return false;
|
||||
|
||||
NBTTagCompound root = item.getTagCompound();
|
||||
if (!root.hasKey(AttributeItemUtil.TAG_RPGCORE)) return false;
|
||||
|
||||
NBTTagCompound rpgCore = root.getCompoundTag(AttributeItemUtil.TAG_RPGCORE);
|
||||
if (!rpgCore.hasKey(AttributeItemUtil.TAG_REQUIREMENTS)) return false;
|
||||
|
||||
NBTTagCompound requirements = rpgCore.getCompoundTag(AttributeItemUtil.TAG_REQUIREMENTS);
|
||||
return requirements.hasKey(SOULBIND_KEY) || requirements.hasKey(PROFILE_SLOT_KEY);
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Runtime Blacklist Management
|
||||
// =========================================
|
||||
|
||||
public static boolean addItem(String registryName) {
|
||||
if (registryName == null || registryName.isEmpty()) return false;
|
||||
registryName = registryName.toLowerCase().trim();
|
||||
|
||||
if (registryName.contains("*")) {
|
||||
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
wildcardPatterns.add(Pattern.compile(regex));
|
||||
} else {
|
||||
blacklistedItems.add(registryName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean removeItem(String registryName) {
|
||||
if (registryName == null || registryName.isEmpty()) return false;
|
||||
registryName = registryName.toLowerCase().trim();
|
||||
|
||||
if (registryName.contains("*")) {
|
||||
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
return wildcardPatterns.removeIf(p -> p.pattern().equals(regex));
|
||||
} else {
|
||||
return blacklistedItems.remove(registryName);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean addMod(String modId) {
|
||||
if (modId == null || modId.isEmpty()) return false;
|
||||
return blacklistedMods.add(modId.toLowerCase().trim());
|
||||
}
|
||||
|
||||
public static boolean removeMod(String modId) {
|
||||
if (modId == null || modId.isEmpty()) return false;
|
||||
return blacklistedMods.remove(modId.toLowerCase().trim());
|
||||
}
|
||||
|
||||
public static boolean addNBTTag(String tag) {
|
||||
if (tag == null || tag.isEmpty()) return false;
|
||||
return blacklistedNBTTags.add(tag.trim());
|
||||
}
|
||||
|
||||
public static boolean removeNBTTag(String tag) {
|
||||
if (tag == null || tag.isEmpty()) return false;
|
||||
return blacklistedNBTTags.remove(tag.trim());
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Getters for listing
|
||||
// =========================================
|
||||
|
||||
public static List<String> getBlacklistedItems() {
|
||||
List<String> result = new ArrayList<>(blacklistedItems);
|
||||
for (Pattern p : wildcardPatterns) {
|
||||
// Convert regex back to wildcard format
|
||||
String pattern = p.pattern();
|
||||
pattern = pattern.substring(1, pattern.length() - 1); // Remove ^ and $
|
||||
pattern = pattern.replace("\\.", ".").replace(".*", "*");
|
||||
result.add(pattern);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getBlacklistedMods() {
|
||||
return new ArrayList<>(blacklistedMods);
|
||||
}
|
||||
|
||||
public static List<String> getBlacklistedNBTTags() {
|
||||
return new ArrayList<>(blacklistedNBTTags);
|
||||
}
|
||||
}
|
||||
@@ -2,28 +2,39 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.handler.data.IAuctionClaim;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
import noppes.npcs.constants.EnumClaimType;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuctionClaim {
|
||||
public class AuctionClaim implements IAuctionClaim {
|
||||
public String id;
|
||||
public UUID playerUUID;
|
||||
public String playerName;
|
||||
public String listingId;
|
||||
public EnumClaimType type;
|
||||
public ItemStack item;
|
||||
public ItemStack item; // The item (for ITEM claims only)
|
||||
public String itemName; // Display name of item (for CURRENCY/REFUND tooltip)
|
||||
public String otherPlayerName; // Buyer name (CURRENCY) or who outbid (REFUND)
|
||||
public long currency;
|
||||
public long createdTime;
|
||||
public boolean claimed;
|
||||
public boolean isReturned; // For ITEM claims: true if returned to seller, false if won by buyer
|
||||
|
||||
public AuctionClaim() {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
this.createdTime = System.currentTimeMillis();
|
||||
this.claimed = false;
|
||||
this.isReturned = false;
|
||||
this.itemName = "";
|
||||
this.otherPlayerName = "";
|
||||
}
|
||||
|
||||
public static AuctionClaim createItemClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
/** Create claim for winning an item (buyer won auction or buyout) */
|
||||
public static AuctionClaim createItemWonClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
claim.playerName = playerName;
|
||||
@@ -31,28 +42,50 @@ public class AuctionClaim {
|
||||
claim.type = EnumClaimType.ITEM;
|
||||
claim.item = item != null ? item.copy() : null;
|
||||
claim.currency = 0;
|
||||
claim.isReturned = false;
|
||||
return claim;
|
||||
}
|
||||
|
||||
public static AuctionClaim createCurrencyClaim(UUID playerUUID, String playerName, String listingId, long currency) {
|
||||
/** Create claim for returned item (seller's expired/cancelled listing) */
|
||||
public static AuctionClaim createItemReturnedClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
claim.playerName = playerName;
|
||||
claim.listingId = listingId;
|
||||
claim.type = EnumClaimType.ITEM;
|
||||
claim.item = item != null ? item.copy() : null;
|
||||
claim.currency = 0;
|
||||
claim.isReturned = true;
|
||||
return claim;
|
||||
}
|
||||
|
||||
/** Create claim for seller's proceeds (stores item name for tooltip, not full item) */
|
||||
public static AuctionClaim createCurrencyClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String buyerName) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
claim.playerName = playerName;
|
||||
claim.listingId = listingId;
|
||||
claim.type = EnumClaimType.CURRENCY;
|
||||
claim.item = null;
|
||||
claim.item = null; // No item stored for currency claims
|
||||
claim.itemName = itemName != null ? itemName : "";
|
||||
claim.otherPlayerName = buyerName != null ? buyerName : "";
|
||||
claim.currency = currency;
|
||||
claim.isReturned = false;
|
||||
return claim;
|
||||
}
|
||||
|
||||
public static AuctionClaim createRefundClaim(UUID playerUUID, String playerName, String listingId, long currency) {
|
||||
/** Create claim for outbid refund (stores item for display and rebid option) */
|
||||
public static AuctionClaim createRefundClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String outbidderName, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
claim.playerName = playerName;
|
||||
claim.listingId = listingId;
|
||||
claim.type = EnumClaimType.REFUND;
|
||||
claim.item = null;
|
||||
claim.item = item != null ? item.copy() : null; // Store item for display and rebid
|
||||
claim.itemName = itemName != null ? itemName : "";
|
||||
claim.otherPlayerName = outbidderName != null ? outbidderName : "";
|
||||
claim.currency = currency;
|
||||
claim.isReturned = false;
|
||||
return claim;
|
||||
}
|
||||
|
||||
@@ -71,6 +104,95 @@ public class AuctionClaim {
|
||||
return playerUUID != null && playerUUID.equals(uuid);
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// IAuctionClaim Implementation
|
||||
// =========================================
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerUUID() {
|
||||
return playerUUID != null ? playerUUID.toString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getListingId() {
|
||||
return listingId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return type.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemClaim() {
|
||||
return type == EnumClaimType.ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurrencyClaim() {
|
||||
return type == EnumClaimType.CURRENCY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRefundClaim() {
|
||||
return type == EnumClaimType.REFUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getItem() {
|
||||
return item != null ? NpcAPI.Instance().getIItemStack(item) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemName() {
|
||||
return itemName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOtherPlayerName() {
|
||||
return otherPlayerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCreatedTime() {
|
||||
return createdTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClaimed() {
|
||||
return claimed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReturnedItem() {
|
||||
return isReturned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDaysUntilExpiration() {
|
||||
return getDaysUntilExpiration(ConfigMarket.ClaimExpirationDays);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpired() {
|
||||
return isExpired(ConfigMarket.ClaimExpirationDays);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("ID", id);
|
||||
compound.setString("PlayerUUID", playerUUID != null ? playerUUID.toString() : "");
|
||||
@@ -84,9 +206,12 @@ public class AuctionClaim {
|
||||
compound.setTag("Item", itemTag);
|
||||
}
|
||||
|
||||
compound.setString("ItemName", itemName != null ? itemName : "");
|
||||
compound.setString("OtherPlayerName", otherPlayerName != null ? otherPlayerName : "");
|
||||
compound.setLong("Currency", currency);
|
||||
compound.setLong("CreatedTime", createdTime);
|
||||
compound.setBoolean("Claimed", claimed);
|
||||
compound.setBoolean("IsReturned", isReturned);
|
||||
|
||||
return compound;
|
||||
}
|
||||
@@ -107,9 +232,12 @@ public class AuctionClaim {
|
||||
item = null;
|
||||
}
|
||||
|
||||
itemName = compound.getString("ItemName");
|
||||
otherPlayerName = compound.getString("OtherPlayerName");
|
||||
currency = compound.getLong("Currency");
|
||||
createdTime = compound.getLong("CreatedTime");
|
||||
claimed = compound.getBoolean("Claimed");
|
||||
isReturned = compound.getBoolean("IsReturned");
|
||||
}
|
||||
|
||||
public static AuctionClaim fromNBT(NBTTagCompound compound) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Filter for auction listings.
|
||||
* Supports search by item name and sorting options.
|
||||
* Supports search by item name or seller name and sorting options.
|
||||
*/
|
||||
public class AuctionFilter {
|
||||
private static final Pattern COLOR_CODE_PATTERN = Pattern.compile("§[0-9a-fk-or]", Pattern.CASE_INSENSITIVE);
|
||||
@@ -37,26 +37,42 @@ public class AuctionFilter {
|
||||
return stripped.toLowerCase().trim();
|
||||
}
|
||||
|
||||
/** Check if item name matches search text */
|
||||
public boolean matchesSearch(String itemName) {
|
||||
/** Check if item name or seller name matches search text */
|
||||
public boolean matchesSearch(String itemName, String sellerName) {
|
||||
if (!hasSearchText()) return true;
|
||||
String normalized = normalizeForSearch(itemName);
|
||||
return normalized.contains(normalizedSearch);
|
||||
String normalizedItem = normalizeForSearch(itemName);
|
||||
String normalizedSeller = normalizeForSearch(sellerName);
|
||||
// Match if search text is found in either item name or seller name
|
||||
return normalizedItem.contains(normalizedSearch) || normalizedSeller.contains(normalizedSearch);
|
||||
}
|
||||
|
||||
/** Advanced search - all words must be present */
|
||||
public boolean matchesSearchAdvanced(String itemName) {
|
||||
/** Legacy method - only checks item name */
|
||||
public boolean matchesSearch(String itemName) {
|
||||
return matchesSearch(itemName, "");
|
||||
}
|
||||
|
||||
/** Advanced search - all words must be present in item name OR seller name */
|
||||
public boolean matchesSearchAdvanced(String itemName, String sellerName) {
|
||||
if (!hasSearchText()) return true;
|
||||
String normalized = normalizeForSearch(itemName);
|
||||
String normalizedItem = normalizeForSearch(itemName);
|
||||
String normalizedSeller = normalizeForSearch(sellerName);
|
||||
String[] words = normalizedSearch.split("\\s+");
|
||||
for (String word : words) {
|
||||
if (!word.isEmpty() && !normalized.contains(word)) {
|
||||
return false;
|
||||
if (!word.isEmpty()) {
|
||||
// Word must be in item name OR seller name
|
||||
if (!normalizedItem.contains(word) && !normalizedSeller.contains(word)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Legacy method - only checks item name */
|
||||
public boolean matchesSearchAdvanced(String itemName) {
|
||||
return matchesSearchAdvanced(itemName, "");
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
searchText = "";
|
||||
sortBy = EnumAuctionSort.NEWEST;
|
||||
|
||||
@@ -2,11 +2,15 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.handler.data.IAuctionListing;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
import noppes.npcs.constants.EnumAuctionStatus;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuctionListing {
|
||||
public class AuctionListing implements IAuctionListing {
|
||||
public String id;
|
||||
public UUID sellerUUID;
|
||||
public String sellerName;
|
||||
@@ -40,22 +44,6 @@ public class AuctionListing {
|
||||
this.endTime = this.createdTime + durationMs;
|
||||
}
|
||||
|
||||
public boolean hasBids() {
|
||||
return bidCount > 0 && highBidderUUID != null;
|
||||
}
|
||||
|
||||
public boolean hasBuyout() {
|
||||
return buyoutPrice > 0;
|
||||
}
|
||||
|
||||
public boolean isExpired() {
|
||||
return System.currentTimeMillis() >= endTime;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return status == EnumAuctionStatus.ACTIVE && !isExpired();
|
||||
}
|
||||
|
||||
public long getTimeRemaining() {
|
||||
return Math.max(0, endTime - System.currentTimeMillis());
|
||||
}
|
||||
@@ -88,6 +76,136 @@ public class AuctionListing {
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// IAuctionListing Implementation
|
||||
// =========================================
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSellerUUID() {
|
||||
return sellerUUID != null ? sellerUUID.toString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSellerName() {
|
||||
return sellerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getItem() {
|
||||
return item != null ? NpcAPI.Instance().getIItemStack(item) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartingPrice() {
|
||||
return startingPrice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBuyoutPrice() {
|
||||
return buyoutPrice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCurrentBid() {
|
||||
return currentBid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHighBidderUUID() {
|
||||
return highBidderUUID != null ? highBidderUUID.toString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHighBidderName() {
|
||||
return highBidderName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBidCount() {
|
||||
return bidCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCreatedTime() {
|
||||
return createdTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRemainingTime() {
|
||||
return getTimeRemaining();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatus() {
|
||||
return status.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMinimumBid() {
|
||||
return getMinimumBid(ConfigMarket.MinBidIncrementPercent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSeller(String playerUUID) {
|
||||
if (playerUUID == null || sellerUUID == null) return false;
|
||||
return sellerUUID.toString().equals(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHighBidder(String playerUUID) {
|
||||
if (playerUUID == null || highBidderUUID == null) return false;
|
||||
return highBidderUUID.toString().equals(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemainingTimeFormatted() {
|
||||
long remaining = getTimeRemaining();
|
||||
if (remaining <= 0) return "Ended";
|
||||
|
||||
long hours = remaining / (60 * 60 * 1000);
|
||||
long minutes = (remaining % (60 * 60 * 1000)) / (60 * 1000);
|
||||
|
||||
if (hours > 0) {
|
||||
return hours + "h " + minutes + "m";
|
||||
} else if (minutes > 0) {
|
||||
return minutes + "m";
|
||||
} else {
|
||||
long seconds = (remaining % (60 * 1000)) / 1000;
|
||||
return seconds + "s";
|
||||
}
|
||||
}
|
||||
|
||||
// Override existing methods with @Override annotation
|
||||
@Override
|
||||
public boolean hasBids() {
|
||||
return bidCount > 0 && highBidderUUID != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBuyout() {
|
||||
return buyoutPrice > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpired() {
|
||||
return System.currentTimeMillis() >= endTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return status == EnumAuctionStatus.ACTIVE && !isExpired();
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("ID", id);
|
||||
compound.setString("SellerUUID", sellerUUID != null ? sellerUUID.toString() : "");
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.util.VaultUtil;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.handler.IPlayerCurrencyData;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
/**
|
||||
* Stores player currency balance.
|
||||
* This data is NOT profile slot bound - all profile slots share the same currency pool.
|
||||
* When Vault API is available and UseVault config is enabled, operations delegate to Vault.
|
||||
* The built-in CNPC+ currency data is always preserved in NBT, but unused when Vault is active.
|
||||
*/
|
||||
public class PlayerCurrencyData implements IPlayerCurrencyData {
|
||||
private final PlayerData playerData;
|
||||
|
||||
// Built-in CNPC+ currency (always saved, used as fallback)
|
||||
private long balance;
|
||||
private long lifetimeEarned;
|
||||
private long lifetimeSpent;
|
||||
|
||||
public PlayerCurrencyData(PlayerData playerData) {
|
||||
this.playerData = playerData;
|
||||
this.balance = ConfigMarket.StartingBalance;
|
||||
this.lifetimeEarned = 0;
|
||||
this.lifetimeSpent = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Vault should be used for currency operations.
|
||||
* Requires both config enabled AND Vault actually available.
|
||||
*/
|
||||
private boolean shouldUseVault() {
|
||||
return ConfigMarket.UseVault && VaultUtil.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get player name for Vault operations
|
||||
*/
|
||||
private String getPlayerName() {
|
||||
if (playerData != null && playerData.player != null) {
|
||||
return playerData.player.getCommandSenderName();
|
||||
}
|
||||
return playerData != null ? playerData.playername : null;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
if (compound.hasKey("CurrencyBalance")) {
|
||||
this.balance = compound.getLong("CurrencyBalance");
|
||||
} else {
|
||||
this.balance = ConfigMarket.StartingBalance;
|
||||
}
|
||||
this.lifetimeEarned = compound.getLong("CurrencyLifetimeEarned");
|
||||
this.lifetimeSpent = compound.getLong("CurrencyLifetimeSpent");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
// Always save built-in currency data (preserved even when using Vault)
|
||||
compound.setLong("CurrencyBalance", this.balance);
|
||||
compound.setLong("CurrencyLifetimeEarned", this.lifetimeEarned);
|
||||
compound.setLong("CurrencyLifetimeSpent", this.lifetimeSpent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current balance
|
||||
*/
|
||||
@Override
|
||||
public long getBalance() {
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
return (long) VaultUtil.getBalance(playerName);
|
||||
}
|
||||
}
|
||||
return balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the balance directly (use with caution)
|
||||
*/
|
||||
@Override
|
||||
public void setBalance(long balance) {
|
||||
if (balance < 0) {
|
||||
balance = 0;
|
||||
}
|
||||
if (balance > ConfigMarket.MaxBalance) {
|
||||
balance = ConfigMarket.MaxBalance;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
VaultUtil.setBalance(playerName, balance);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add currency to balance (deposit)
|
||||
*
|
||||
* @param amount Amount to add
|
||||
* @return true if successful, false if would exceed max balance
|
||||
*/
|
||||
@Override
|
||||
public boolean deposit(long amount) {
|
||||
if (amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
boolean success = VaultUtil.addMoney(playerName, amount);
|
||||
if (success) {
|
||||
this.lifetimeEarned += amount;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
// Built-in currency
|
||||
long newBalance = this.balance + amount;
|
||||
if (newBalance > ConfigMarket.MaxBalance) {
|
||||
return false;
|
||||
}
|
||||
if (newBalance < this.balance) {
|
||||
// Overflow protection
|
||||
return false;
|
||||
}
|
||||
this.balance = newBalance;
|
||||
this.lifetimeEarned += amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove currency from balance (withdraw)
|
||||
*
|
||||
* @param amount Amount to remove
|
||||
* @return true if successful, false if insufficient funds
|
||||
*/
|
||||
@Override
|
||||
public boolean withdraw(long amount) {
|
||||
if (amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
boolean success = VaultUtil.withdrawMoney(playerName, amount);
|
||||
if (success) {
|
||||
this.lifetimeSpent += amount;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
// Built-in currency
|
||||
if (this.balance < amount) {
|
||||
return false;
|
||||
}
|
||||
this.balance -= amount;
|
||||
this.lifetimeSpent += amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player can afford an amount
|
||||
*/
|
||||
@Override
|
||||
public boolean canAfford(long amount) {
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
return VaultUtil.has(playerName, amount);
|
||||
}
|
||||
}
|
||||
return this.balance >= amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lifetime earned currency
|
||||
*/
|
||||
@Override
|
||||
public long getLifetimeEarned() {
|
||||
return lifetimeEarned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lifetime spent currency
|
||||
*/
|
||||
@Override
|
||||
public long getLifetimeSpent() {
|
||||
return lifetimeSpent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the balance for display
|
||||
*/
|
||||
@Override
|
||||
public String formatBalance() {
|
||||
if (shouldUseVault()) {
|
||||
return VaultUtil.format(getBalance());
|
||||
}
|
||||
return formatAmount(this.balance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an amount for display
|
||||
*/
|
||||
public static String formatAmount(long amount) {
|
||||
return String.format("%,d %s", amount, ConfigMarket.CurrencyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Vault is being used for currency operations.
|
||||
* Returns true only if config is enabled AND Vault is actually available.
|
||||
*/
|
||||
@Override
|
||||
public boolean isUsingVault() {
|
||||
return shouldUseVault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Vault is configured (regardless of availability)
|
||||
*/
|
||||
public boolean isVaultConfigured() {
|
||||
return ConfigMarket.UseVault;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.handler.IPlayerBankData;
|
||||
import noppes.npcs.api.handler.IPlayerCurrencyData;
|
||||
import noppes.npcs.api.handler.IPlayerTradeData;
|
||||
import noppes.npcs.api.handler.IPlayerData;
|
||||
import noppes.npcs.api.handler.IPlayerDialogData;
|
||||
import noppes.npcs.api.handler.IPlayerFactionData;
|
||||
@@ -46,6 +46,8 @@ import java.io.FileOutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
||||
|
||||
public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public PlayerDialogData dialogData = new PlayerDialogData(this);
|
||||
public PlayerBankData bankData = new PlayerBankData(this);
|
||||
@@ -60,8 +62,8 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public DataSkinOverlays skinOverlays = new DataSkinOverlays(this);
|
||||
public MagicData magicData = new MagicData();
|
||||
|
||||
// Currency data - NOT slot-bound, shared across all profile slots
|
||||
public PlayerCurrencyData currencyData = new PlayerCurrencyData(this);
|
||||
// Trade data (currency + auction claims) - shared across all profile slots
|
||||
public PlayerTradeData tradeData = new PlayerTradeData(this);
|
||||
|
||||
public ActionManager actionManager = new ActionManager();
|
||||
public PlayerDataScript scriptData;
|
||||
@@ -134,6 +136,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
animationData.readFromNBT(data);
|
||||
effectData.readFromNBT(data);
|
||||
magicData.readToNBT(data);
|
||||
tradeData.readFromNBT(data);
|
||||
|
||||
if (player != null) {
|
||||
playername = player.getCommandSenderName();
|
||||
@@ -176,6 +179,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
animationData.writeToNBT(compound);
|
||||
effectData.writeToNBT(compound);
|
||||
magicData.writeToNBT(compound);
|
||||
tradeData.writeToNBT(compound);
|
||||
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
@@ -228,6 +232,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
transportData.saveNBTData(compound);
|
||||
factionData.saveNBTData(compound);
|
||||
mailData.saveNBTData(compound);
|
||||
tradeData.writeToNBT(compound);
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
DBCAddon.instance.writeToNBT(this, compound);
|
||||
@@ -241,6 +246,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
transportData.loadNBTData(data);
|
||||
factionData.loadNBTData(data);
|
||||
mailData.loadNBTData(data);
|
||||
tradeData.readFromNBT(data);
|
||||
if (player != null) {
|
||||
playername = player.getCommandSenderName();
|
||||
uuid = player.getPersistentID().toString();
|
||||
@@ -401,8 +407,8 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
return mailData;
|
||||
}
|
||||
|
||||
public IPlayerCurrencyData getCurrencyData() {
|
||||
return currencyData;
|
||||
public IPlayerTradeData getTradeData() {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
public synchronized void save() {
|
||||
@@ -414,9 +420,6 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
}
|
||||
|
||||
final NBTTagCompound compound = getNBT();
|
||||
// Currency data is saved at player level, NOT per profile slot
|
||||
currencyData.writeToNBT(compound);
|
||||
|
||||
final String filename;
|
||||
if (ConfigMain.DatFormat) {
|
||||
filename = uuid + ".dat";
|
||||
@@ -453,10 +456,6 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
if (data.hasNoTags()) {
|
||||
data = getNBT();
|
||||
}
|
||||
|
||||
// Load currency BEFORE setNBT - currency is player-level, NOT per profile slot
|
||||
currencyData.readFromNBT(data);
|
||||
|
||||
setNBT(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,414 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.util.VaultUtil;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.api.handler.IPlayerTradeData;
|
||||
import noppes.npcs.api.handler.data.IAuctionClaim;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* Stores player's trade-related data: currency and auction claims.
|
||||
* This data is shared across all profile slots.
|
||||
* Uses CopyOnWriteArrayList for thread-safety when adding claims asynchronously.
|
||||
*/
|
||||
public class PlayerTradeData implements IPlayerTradeData {
|
||||
// NBT key used by trade data - excluded from per-slot profile saving
|
||||
public static final String NBT_KEY = "TradeData";
|
||||
|
||||
private final PlayerData playerData;
|
||||
|
||||
// =========================================
|
||||
// Currency Data
|
||||
// =========================================
|
||||
|
||||
// Built-in CNPC+ currency (always saved, used as fallback)
|
||||
private long balance;
|
||||
private long lifetimeEarned;
|
||||
private long lifetimeSpent;
|
||||
|
||||
// =========================================
|
||||
// Auction Claims Data
|
||||
// =========================================
|
||||
|
||||
// Thread-safe list for claims - can be modified from CNPC+ thread
|
||||
private final CopyOnWriteArrayList<AuctionClaim> claims = new CopyOnWriteArrayList<>();
|
||||
|
||||
public PlayerTradeData(PlayerData playerData) {
|
||||
this.playerData = playerData;
|
||||
this.balance = ConfigMarket.StartingBalance;
|
||||
this.lifetimeEarned = 0;
|
||||
this.lifetimeSpent = 0;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Currency Methods
|
||||
// =========================================
|
||||
|
||||
/**
|
||||
* Check if Vault should be used for currency operations.
|
||||
* Requires both config enabled AND Vault actually available.
|
||||
*/
|
||||
private boolean shouldUseVault() {
|
||||
return ConfigMarket.UseVault && VaultUtil.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get player name for Vault operations
|
||||
*/
|
||||
private String getPlayerName() {
|
||||
if (playerData != null && playerData.player != null) {
|
||||
return playerData.player.getCommandSenderName();
|
||||
}
|
||||
return playerData != null ? playerData.playername : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current balance
|
||||
*/
|
||||
@Override
|
||||
public long getBalance() {
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
return (long) VaultUtil.getBalance(playerName);
|
||||
}
|
||||
}
|
||||
return balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the balance directly (use with caution)
|
||||
*/
|
||||
@Override
|
||||
public void setBalance(long balance) {
|
||||
if (balance < 0) {
|
||||
balance = 0;
|
||||
}
|
||||
if (balance > ConfigMarket.MaxBalance) {
|
||||
balance = ConfigMarket.MaxBalance;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
VaultUtil.setBalance(playerName, balance);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add currency to balance (deposit)
|
||||
*
|
||||
* @param amount Amount to add
|
||||
* @return true if successful, false if would exceed max balance
|
||||
*/
|
||||
@Override
|
||||
public boolean deposit(long amount) {
|
||||
if (amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
boolean success = VaultUtil.addMoney(playerName, amount);
|
||||
if (success) {
|
||||
this.lifetimeEarned += amount;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
// Built-in currency
|
||||
long newBalance = this.balance + amount;
|
||||
if (newBalance > ConfigMarket.MaxBalance) {
|
||||
return false;
|
||||
}
|
||||
if (newBalance < this.balance) {
|
||||
// Overflow protection
|
||||
return false;
|
||||
}
|
||||
this.balance = newBalance;
|
||||
this.lifetimeEarned += amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove currency from balance (withdraw)
|
||||
*
|
||||
* @param amount Amount to remove
|
||||
* @return true if successful, false if insufficient funds
|
||||
*/
|
||||
@Override
|
||||
public boolean withdraw(long amount) {
|
||||
if (amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
boolean success = VaultUtil.withdrawMoney(playerName, amount);
|
||||
if (success) {
|
||||
this.lifetimeSpent += amount;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
// Built-in currency
|
||||
if (this.balance < amount) {
|
||||
return false;
|
||||
}
|
||||
this.balance -= amount;
|
||||
this.lifetimeSpent += amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player can afford an amount
|
||||
*/
|
||||
@Override
|
||||
public boolean canAfford(long amount) {
|
||||
if (shouldUseVault()) {
|
||||
String playerName = getPlayerName();
|
||||
if (playerName != null) {
|
||||
return VaultUtil.has(playerName, amount);
|
||||
}
|
||||
}
|
||||
return this.balance >= amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lifetime earned currency
|
||||
*/
|
||||
@Override
|
||||
public long getLifetimeEarned() {
|
||||
return lifetimeEarned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lifetime spent currency
|
||||
*/
|
||||
@Override
|
||||
public long getLifetimeSpent() {
|
||||
return lifetimeSpent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the balance for display
|
||||
*/
|
||||
@Override
|
||||
public String formatBalance() {
|
||||
if (shouldUseVault()) {
|
||||
return VaultUtil.format(getBalance());
|
||||
}
|
||||
return formatAmount(this.balance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an amount for display
|
||||
*/
|
||||
public static String formatAmount(long amount) {
|
||||
return String.format("%,d %s", amount, ConfigMarket.CurrencyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Vault is being used for currency operations.
|
||||
* Returns true only if config is enabled AND Vault is actually available.
|
||||
*/
|
||||
@Override
|
||||
public boolean isUsingVault() {
|
||||
return shouldUseVault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Vault is configured (regardless of availability)
|
||||
*/
|
||||
public boolean isVaultConfigured() {
|
||||
return ConfigMarket.UseVault;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Auction Claims Methods
|
||||
// =========================================
|
||||
|
||||
/**
|
||||
* Add a claim to this player's pending claims.
|
||||
* Thread-safe - can be called from any thread.
|
||||
*/
|
||||
public void addClaim(AuctionClaim claim) {
|
||||
if (claim != null && !claim.claimed) {
|
||||
claims.add(claim);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all unclaimed claims for this player (internal use).
|
||||
* Returns a copy of the list for safe iteration.
|
||||
*/
|
||||
public List<AuctionClaim> getClaimsList() {
|
||||
List<AuctionClaim> result = new ArrayList<>();
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (!claim.claimed) {
|
||||
result.add(claim);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all unclaimed claims for this player (API).
|
||||
*/
|
||||
@Override
|
||||
public IAuctionClaim[] getClaims() {
|
||||
List<AuctionClaim> result = getClaimsList();
|
||||
return result.toArray(new IAuctionClaim[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific claim by ID (internal use).
|
||||
*/
|
||||
public AuctionClaim getClaimInternal(String claimId) {
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (claim.id.equals(claimId) && !claim.claimed) {
|
||||
return claim;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific claim by ID (API).
|
||||
*/
|
||||
@Override
|
||||
public IAuctionClaim getClaim(String claimId) {
|
||||
return getClaimInternal(claimId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a claim as claimed and remove it.
|
||||
*/
|
||||
public boolean claimAndRemove(String claimId) {
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (claim.id.equals(claimId) && !claim.claimed) {
|
||||
claim.claimed = true;
|
||||
claims.remove(claim);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get count of unclaimed claims.
|
||||
*/
|
||||
@Override
|
||||
public int getClaimCount() {
|
||||
int count = 0;
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (!claim.claimed) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player has any unclaimed claims.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasClaims() {
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (!claim.claimed) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process expired claims - removes claims older than expiration days.
|
||||
* Returns number of claims removed.
|
||||
*/
|
||||
public int processExpiredClaims() {
|
||||
int expirationDays = ConfigMarket.ClaimExpirationDays;
|
||||
int removed = 0;
|
||||
|
||||
Iterator<AuctionClaim> iterator = claims.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
AuctionClaim claim = iterator.next();
|
||||
if (!claim.claimed && claim.isExpired(expirationDays)) {
|
||||
claims.remove(claim);
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// NBT Serialization
|
||||
// =========================================
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
NBTTagCompound tradeData = compound.getCompoundTag(NBT_KEY);
|
||||
if (tradeData == null || tradeData.hasNoTags()) {
|
||||
// No trade data found, use defaults
|
||||
this.balance = ConfigMarket.StartingBalance;
|
||||
this.lifetimeEarned = 0;
|
||||
this.lifetimeSpent = 0;
|
||||
claims.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// Currency
|
||||
if (tradeData.hasKey("CurrencyBalance")) {
|
||||
this.balance = tradeData.getLong("CurrencyBalance");
|
||||
} else {
|
||||
this.balance = ConfigMarket.StartingBalance;
|
||||
}
|
||||
this.lifetimeEarned = tradeData.getLong("CurrencyLifetimeEarned");
|
||||
this.lifetimeSpent = tradeData.getLong("CurrencyLifetimeSpent");
|
||||
|
||||
// Claims
|
||||
claims.clear();
|
||||
if (tradeData.hasKey("AuctionClaims")) {
|
||||
NBTTagList claimsList = tradeData.getTagList("AuctionClaims", 10);
|
||||
for (int i = 0; i < claimsList.tagCount(); i++) {
|
||||
AuctionClaim claim = AuctionClaim.fromNBT(claimsList.getCompoundTagAt(i));
|
||||
if (!claim.claimed) {
|
||||
claims.add(claim);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
NBTTagCompound tradeData = new NBTTagCompound();
|
||||
|
||||
// Currency - always save built-in currency data (preserved even when using Vault)
|
||||
tradeData.setLong("CurrencyBalance", this.balance);
|
||||
tradeData.setLong("CurrencyLifetimeEarned", this.lifetimeEarned);
|
||||
tradeData.setLong("CurrencyLifetimeSpent", this.lifetimeSpent);
|
||||
|
||||
// Claims
|
||||
NBTTagList claimsList = new NBTTagList();
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (!claim.claimed) {
|
||||
claimsList.appendTag(claim.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
tradeData.setTag("AuctionClaims", claimsList);
|
||||
|
||||
compound.setTag(NBT_KEY, tradeData);
|
||||
}
|
||||
}
|
||||
@@ -426,7 +426,7 @@ public class RoleTrader extends RoleInterface {
|
||||
|
||||
// Player balance
|
||||
PlayerData data = PlayerData.get(player);
|
||||
compound.setLong("Balance", data.currencyData.getBalance());
|
||||
compound.setLong("Balance", data.tradeData.getBalance());
|
||||
|
||||
// Stock info
|
||||
compound.setBoolean("StockEnabled", stock.enableStock);
|
||||
|
||||
@@ -5,6 +5,7 @@ import cpw.mods.fml.common.eventhandler.EventBus;
|
||||
import foxz.command.ScriptedCommand;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.TelegraphController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.command.CommandHandler;
|
||||
@@ -52,6 +53,7 @@ import noppes.npcs.api.IContainer;
|
||||
import noppes.npcs.api.IDamageSource;
|
||||
import noppes.npcs.api.INbt;
|
||||
import noppes.npcs.api.IParticle;
|
||||
import noppes.npcs.api.ITelegraph;
|
||||
import noppes.npcs.api.IPos;
|
||||
import noppes.npcs.api.ISkinOverlay;
|
||||
import noppes.npcs.api.ITileEntity;
|
||||
@@ -63,6 +65,7 @@ import noppes.npcs.api.gui.ICustomGui;
|
||||
import noppes.npcs.api.handler.IAbilityHandler;
|
||||
import noppes.npcs.api.handler.IActionManager;
|
||||
import noppes.npcs.api.handler.IAnimationHandler;
|
||||
import noppes.npcs.api.handler.IAuctionHandler;
|
||||
import noppes.npcs.api.handler.IAttributeHandler;
|
||||
import noppes.npcs.api.handler.ICloneHandler;
|
||||
import noppes.npcs.api.handler.ICustomEffectHandler;
|
||||
@@ -75,6 +78,7 @@ import noppes.npcs.api.handler.IProfileHandler;
|
||||
import noppes.npcs.api.handler.IQuestHandler;
|
||||
import noppes.npcs.api.handler.IRecipeHandler;
|
||||
import noppes.npcs.api.handler.IScriptHookHandler;
|
||||
import noppes.npcs.api.handler.ITelegraphHandler;
|
||||
import noppes.npcs.api.handler.ITransportHandler;
|
||||
import noppes.npcs.api.handler.data.IAnimation;
|
||||
import noppes.npcs.api.handler.data.IFrame;
|
||||
@@ -87,6 +91,7 @@ import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.constants.EnumAnimationPart;
|
||||
import noppes.npcs.containers.ContainerNpcInterface;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
import noppes.npcs.controllers.ChunkController;
|
||||
import noppes.npcs.controllers.CustomEffectController;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
@@ -370,6 +375,27 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
return AbilityController.Instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraphHandler getTelegraphs() {
|
||||
this.checkWorld();
|
||||
return TelegraphController.Instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraph createTelegraph(String type) {
|
||||
this.checkWorld();
|
||||
return TelegraphController.Instance.create(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAuctionHandler getAuctions() {
|
||||
this.checkWorld();
|
||||
if (!noppes.npcs.config.ConfigMarket.AuctionEnabled) {
|
||||
return null;
|
||||
}
|
||||
return AuctionController.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAllBiomeNames() {
|
||||
List<String> biomes = new ArrayList<>();
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
package noppes.npcs.scripted;
|
||||
|
||||
import kamkeel.npcs.controllers.TelegraphController;
|
||||
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.api.ITelegraph;
|
||||
import noppes.npcs.api.ITelegraphInstance;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
|
||||
/**
|
||||
* Script wrapper for Telegraph configuration.
|
||||
* Implements ITelegraph API interface.
|
||||
*/
|
||||
public class ScriptTelegraph implements ITelegraph {
|
||||
|
||||
private final Telegraph telegraph;
|
||||
|
||||
public ScriptTelegraph(Telegraph telegraph) {
|
||||
this.telegraph = telegraph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Telegraph object.
|
||||
*/
|
||||
public Telegraph getMCTelegraph() {
|
||||
return telegraph;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// TYPE
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return telegraph.getType().name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(String type) {
|
||||
if (type == null) return;
|
||||
try {
|
||||
telegraph.setType(TelegraphType.valueOf(type.toUpperCase()));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// SHAPE PARAMETERS
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public float getRadius() {
|
||||
return telegraph.getRadius();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRadius(float radius) {
|
||||
telegraph.setRadius(radius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInnerRadius() {
|
||||
return telegraph.getInnerRadius();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInnerRadius(float innerRadius) {
|
||||
telegraph.setInnerRadius(innerRadius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLength() {
|
||||
return telegraph.getLength();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLength(float length) {
|
||||
telegraph.setLength(length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWidth() {
|
||||
return telegraph.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(float width) {
|
||||
telegraph.setWidth(width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAngle() {
|
||||
return telegraph.getAngle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngle(float angle) {
|
||||
telegraph.setAngle(angle);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// TIMING
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public int getDuration() {
|
||||
return telegraph.getDurationTicks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDuration(int ticks) {
|
||||
telegraph.setDurationTicks(ticks);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// COLORS
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return telegraph.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(int argb) {
|
||||
telegraph.setColor(argb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWarningColor() {
|
||||
return telegraph.getWarningColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWarningColor(int argb) {
|
||||
telegraph.setWarningColor(argb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWarningStartTick() {
|
||||
return telegraph.getWarningStartTick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWarningStartTick(int tick) {
|
||||
telegraph.setWarningStartTick(tick);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// ANIMATION
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public boolean isAnimated() {
|
||||
return telegraph.isAnimated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnimated(boolean animated) {
|
||||
telegraph.setAnimated(animated);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// POSITIONING
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public float getHeightOffset() {
|
||||
return telegraph.getHeightOffset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeightOffset(float offset) {
|
||||
telegraph.setHeightOffset(offset);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// SPAWN METHODS
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public ITelegraphInstance spawn(IWorld world, double x, double y, double z) {
|
||||
return spawn(world, x, y, z, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraphInstance spawn(IWorld world, double x, double y, double z, float yaw) {
|
||||
if (world == null || world.getMCWorld() == null) return null;
|
||||
World mcWorld = (World) world.getMCWorld();
|
||||
TelegraphInstance instance = TelegraphController.Instance.spawn(telegraph, mcWorld, x, y, z, yaw);
|
||||
return new ScriptTelegraphInstance(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraphInstance spawn(IEntity entity) {
|
||||
return spawn(entity, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelegraphInstance spawn(IEntity entity, float yaw) {
|
||||
if (entity == null || entity.getMCEntity() == null) return null;
|
||||
Entity mcEntity = (Entity) entity.getMCEntity();
|
||||
TelegraphInstance instance = TelegraphController.Instance.spawn(telegraph, mcEntity, yaw);
|
||||
return new ScriptTelegraphInstance(instance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package noppes.npcs.scripted;
|
||||
|
||||
import kamkeel.npcs.controllers.TelegraphController;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import net.minecraft.entity.Entity;
|
||||
import noppes.npcs.api.ITelegraphInstance;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
|
||||
/**
|
||||
* Script wrapper for TelegraphInstance.
|
||||
* Implements ITelegraphInstance API interface.
|
||||
*/
|
||||
public class ScriptTelegraphInstance implements ITelegraphInstance {
|
||||
|
||||
private final TelegraphInstance instance;
|
||||
|
||||
public ScriptTelegraphInstance(TelegraphInstance instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying TelegraphInstance object.
|
||||
*/
|
||||
public TelegraphInstance getMCInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInstanceId() {
|
||||
return instance.getInstanceId();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// POSITION
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public double getX() {
|
||||
return instance.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getY() {
|
||||
return instance.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZ() {
|
||||
return instance.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYaw() {
|
||||
return instance.getYaw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(double x, double y, double z) {
|
||||
instance.setX(x);
|
||||
instance.setY(y);
|
||||
instance.setZ(z);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// ENTITY FOLLOWING
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public void followEntity(IEntity entity) {
|
||||
if (entity == null || entity.getMCEntity() == null) return;
|
||||
Entity mcEntity = (Entity) entity.getMCEntity();
|
||||
instance.setEntityIdToFollow(mcEntity.getEntityId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopFollowing() {
|
||||
instance.lockPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFollowing() {
|
||||
return instance.getEntityIdToFollow() >= 0;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// TIMING
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public int getRemainingTicks() {
|
||||
return instance.getRemainingTicks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTicks() {
|
||||
return instance.getTotalTicks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProgress() {
|
||||
return instance.getProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarning() {
|
||||
return instance.isWarning();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// CONTROL
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
TelegraphController.Instance.remove(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockPosition() {
|
||||
instance.lockPosition();
|
||||
}
|
||||
}
|
||||
@@ -901,36 +901,36 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
|
||||
@Override
|
||||
public long getCurrencyBalance() {
|
||||
return getData().currencyData.getBalance();
|
||||
return getData().tradeData.getBalance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrencyBalance(long amount) {
|
||||
getData().currencyData.setBalance(amount);
|
||||
getData().tradeData.setBalance(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean depositCurrency(long amount) {
|
||||
return getData().currencyData.deposit(amount);
|
||||
return getData().tradeData.deposit(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withdrawCurrency(long amount) {
|
||||
return getData().currencyData.withdraw(amount);
|
||||
return getData().tradeData.withdraw(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAffordCurrency(long amount) {
|
||||
return getData().currencyData.canAfford(amount);
|
||||
return getData().tradeData.canAfford(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsingVaultCurrency() {
|
||||
return getData().currencyData.isUsingVault();
|
||||
return getData().tradeData.isUsingVault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedCurrencyBalance() {
|
||||
return getData().currencyData.formatBalance();
|
||||
return getData().tradeData.formatBalance();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user