From d3f3af0b20e046eef1019cf7876e577fdd2ff106 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Tue, 18 Oct 2022 20:16:42 -0400 Subject: [PATCH] fix bug where switching prices in sell menu will cause item to disappear Took 12 minutes --- .../auctionhouse/guis/GUISellItem.java | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUISellItem.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUISellItem.java index 346d03c..535598c 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUISellItem.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUISellItem.java @@ -163,7 +163,9 @@ public class GUISellItem extends AbstractPlaceholderGui { e.gui.close(); // work-around to clicking closeable item with item on cursor - handleClosableCursorItem(e); + if (handleClosableCursorItem(e)) { + return; + } PlayerChatInput.PlayerChatInputBuilder builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player); builder.isValidInput((p, str) -> { @@ -202,7 +204,9 @@ public class GUISellItem extends AbstractPlaceholderGui { e.gui.close(); // work-around to clicking closeable item with item on cursor - handleClosableCursorItem(e); + if (handleClosableCursorItem(e)) { + return; + } PlayerChatInput.PlayerChatInputBuilder builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player); builder.isValidInput((p, str) -> { @@ -238,7 +242,9 @@ public class GUISellItem extends AbstractPlaceholderGui { e.gui.close(); // work-around to clicking closeable item with item on cursor - handleClosableCursorItem(e); + if (handleClosableCursorItem(e)) { + return; + } PlayerChatInput.PlayerChatInputBuilder builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player); builder.isValidInput((p, str) -> { @@ -270,7 +276,9 @@ public class GUISellItem extends AbstractPlaceholderGui { e.gui.close(); // work-around to clicking closeable item with item on cursor - handleClosableCursorItem(e); + if (handleClosableCursorItem(e)) { + return; + } PlayerChatInput.PlayerChatInputBuilder builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player); builder.isValidInput((p, str) -> { @@ -477,11 +485,20 @@ public class GUISellItem extends AbstractPlaceholderGui { } - private void handleClosableCursorItem(@NonNull final GuiClickEvent e) { - if (e.cursor != null) { - AuctionHouse.getInstance().getAuctionPlayerManager().addItemToSellHolding(player.getUniqueId(), e.cursor); - this.itemToBeListed = e.cursor.clone(); + private boolean handleClosableCursorItem(@NonNull final GuiClickEvent e) { + if (e.cursor != null && getItem(1, 4) == null) { +// AuctionHouse.getInstance().getAuctionPlayerManager().addItemToSellHolding(player.getUniqueId(), e.cursor); +// this.itemToBeListed = e.cursor.clone(); + PlayerUtils.giveItem(e.player, e.cursor.clone()); + return true; } + + return false; + } + + private void setTheItemToBeListed() { + this.itemToBeListed = getItem(1, 4); + this.auctionPlayer.setItemBeingListed(this.itemToBeListed); } private boolean validateChatNumber(String input, double requirement, boolean checkMax) { @@ -492,12 +509,7 @@ public class GUISellItem extends AbstractPlaceholderGui { } private void reopen(GuiClickEvent e) { - e.manager.showGUI(e.player, new GUISellItem(this.auctionPlayer, this.itemToBeListed, this.buyNowPrice, this.bidStartPrice, this.bidIncrementPrice, this.isBiddingItem, this.isAllowingBuyNow, this.auctionTime)); - } - - private void setTheItemToBeListed() { - this.itemToBeListed = getItem(1, 4); - this.auctionPlayer.setItemBeingListed(this.itemToBeListed); + e.manager.showGUI(e.player, new GUISellItem(this.auctionPlayer, this.auctionPlayer.getItemBeingListed(), this.buyNowPrice, this.bidStartPrice, this.bidIncrementPrice, this.isBiddingItem, this.isAllowingBuyNow, this.auctionTime)); } private void makeMess() {