patch for duplication bug related to purchasing specific quantities of items

Took 4 minutes
This commit is contained in:
Kiran Hart 2022-03-19 00:15:12 -04:00
parent baf5fdd84b
commit e68029d444
2 changed files with 9 additions and 5 deletions

View File

@ -414,7 +414,7 @@ public class DataManager extends DataManagerAbstract {
connection.setAutoCommit(false); connection.setAutoCommit(false);
SQLException err = null; 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) { for (AuctionedItem item : items) {
try { try {
statement.setString(1, item.getOwner().toString()); statement.setString(1, item.getOwner().toString());
@ -427,7 +427,8 @@ public class DataManager extends DataManagerAbstract {
statement.setDouble(8, item.getCurrentPrice()); statement.setDouble(8, item.getCurrentPrice());
statement.setLong(9, item.getExpiresAt()); statement.setLong(9, item.getExpiresAt());
statement.setBoolean(10, item.isExpired()); 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(); statement.addBatch();
} catch (SQLException e) { } catch (SQLException e) {
err = e; err = e;

View File

@ -99,6 +99,7 @@ public class GUIConfirmPurchase extends Gui {
setActionForRange(this.buyingSpecificQuantity ? 14 : 5, this.buyingSpecificQuantity ? 17 : 8, ClickType.LEFT, e -> { setActionForRange(this.buyingSpecificQuantity ? 14 : 5, this.buyingSpecificQuantity ? 17 : 8, ClickType.LEFT, e -> {
e.gui.close(); e.gui.close();
}); });
setActionForRange(this.buyingSpecificQuantity ? 9 : 0, this.buyingSpecificQuantity ? 12 : 3, ClickType.LEFT, e -> { setActionForRange(this.buyingSpecificQuantity ? 9 : 0, this.buyingSpecificQuantity ? 12 : 3, ClickType.LEFT, e -> {
// Re-select the item to ensure that it's available // Re-select the item to ensure that it's available
try { try {
@ -134,17 +135,19 @@ public class GUIConfirmPurchase extends Gui {
} }
if (this.buyingSpecificQuantity) { 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) { if (item.getAmount() - this.purchaseQuantity >= 1) {
item.setAmount(item.getAmount() - this.purchaseQuantity); item.setAmount(item.getAmount() - this.purchaseQuantity);
toGive.setAmount(this.purchaseQuantity);
if (!located.isInfinite()) { if (!located.isInfinite()) {
located.setItem(item); located.setItem(item);
located.setBasePrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(located.getBasePrice() - buyNowPrice) : located.getBasePrice() - buyNowPrice); located.setBasePrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(located.getBasePrice() - buyNowPrice) : located.getBasePrice() - buyNowPrice);
} }
item.setAmount(this.purchaseQuantity);
transferFunds(e.player, buyNowPrice); transferFunds(e.player, buyNowPrice);
} else { } else {
transferFunds(e.player, buyNowPrice); transferFunds(e.player, buyNowPrice);
@ -152,7 +155,7 @@ public class GUIConfirmPurchase extends Gui {
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(located); AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(located);
} }
PlayerUtils.giveItem(e.player, item); PlayerUtils.giveItem(e.player, toGive);
sendMessages(e, located, true, buyNowPrice); sendMessages(e, located, true, buyNowPrice);
} else { } else {