From e68029d4447d3c0a6f9f5e3be09f18fe0c9e716d Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Sat, 19 Mar 2022 00:15:12 -0400 Subject: [PATCH] patch for duplication bug related to purchasing specific quantities of items Took 4 minutes --- .../ca/tweetzy/auctionhouse/database/DataManager.java | 5 +++-- .../guis/confirmation/GUIConfirmPurchase.java | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java index c04e49b..58f1033 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java @@ -414,7 +414,7 @@ public class DataManager extends DataManagerAbstract { connection.setAutoCommit(false); SQLException err = null; - PreparedStatement statement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "auctions SET owner = ?, owner_name = ?, highest_bidder = ?, highest_bidder_name = ?, base_price = ?, bid_start_price = ?, bid_increment_price = ?, current_price = ?, expires_at = ?, expired = ? WHERE id = ?"); + PreparedStatement statement = connection.prepareStatement("UPDATE " + this.getTablePrefix() + "auctions SET owner = ?, owner_name = ?, highest_bidder = ?, highest_bidder_name = ?, base_price = ?, bid_start_price = ?, bid_increment_price = ?, current_price = ?, expires_at = ?, expired = ?, item = ? WHERE id = ?"); for (AuctionedItem item : items) { try { statement.setString(1, item.getOwner().toString()); @@ -427,7 +427,8 @@ public class DataManager extends DataManagerAbstract { statement.setDouble(8, item.getCurrentPrice()); statement.setLong(9, item.getExpiresAt()); statement.setBoolean(10, item.isExpired()); - statement.setString(11, item.getId().toString()); + statement.setString(11, AuctionAPI.encodeItem(item.getItem())); + statement.setString(12, item.getId().toString()); statement.addBatch(); } catch (SQLException e) { err = e; diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIConfirmPurchase.java b/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIConfirmPurchase.java index 98be31e..de0284f 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIConfirmPurchase.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIConfirmPurchase.java @@ -99,6 +99,7 @@ public class GUIConfirmPurchase extends Gui { setActionForRange(this.buyingSpecificQuantity ? 14 : 5, this.buyingSpecificQuantity ? 17 : 8, ClickType.LEFT, e -> { e.gui.close(); }); + setActionForRange(this.buyingSpecificQuantity ? 9 : 0, this.buyingSpecificQuantity ? 12 : 3, ClickType.LEFT, e -> { // Re-select the item to ensure that it's available try { @@ -134,17 +135,19 @@ public class GUIConfirmPurchase extends Gui { } if (this.buyingSpecificQuantity) { - ItemStack item = auctionItem.getItem(); + // the original item stack + ItemStack item = auctionItem.getItem().clone(); + ItemStack toGive = auctionItem.getItem().clone(); if (item.getAmount() - this.purchaseQuantity >= 1) { item.setAmount(item.getAmount() - this.purchaseQuantity); + toGive.setAmount(this.purchaseQuantity); if (!located.isInfinite()) { located.setItem(item); located.setBasePrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(located.getBasePrice() - buyNowPrice) : located.getBasePrice() - buyNowPrice); } - item.setAmount(this.purchaseQuantity); transferFunds(e.player, buyNowPrice); } else { transferFunds(e.player, buyNowPrice); @@ -152,7 +155,7 @@ public class GUIConfirmPurchase extends Gui { AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(located); } - PlayerUtils.giveItem(e.player, item); + PlayerUtils.giveItem(e.player, toGive); sendMessages(e, located, true, buyNowPrice); } else {