diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUISellItem.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUISellItem.java index 1d4623c..346d03c 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUISellItem.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUISellItem.java @@ -17,6 +17,7 @@ import ca.tweetzy.core.input.PlayerChatInput; import ca.tweetzy.core.utils.NumberUtils; import ca.tweetzy.core.utils.PlayerUtils; import ca.tweetzy.core.utils.TextUtils; +import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.event.inventory.ClickType; @@ -160,6 +161,10 @@ public class GUISellItem extends AbstractPlaceholderGui { put("%remaining_seconds%", times[3]); }}), ClickType.LEFT, e -> { e.gui.close(); + + // work-around to clicking closeable item with item on cursor + handleClosableCursorItem(e); + PlayerChatInput.PlayerChatInputBuilder builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player); builder.isValidInput((p, str) -> { String[] parts = ChatColor.stripColor(str).split(" "); @@ -193,8 +198,12 @@ public class GUISellItem extends AbstractPlaceholderGui { }}), ClickType.LEFT, e -> { setTheItemToBeListed(); setAllowClose(true); + e.gui.close(); + // work-around to clicking closeable item with item on cursor + handleClosableCursorItem(e); + PlayerChatInput.PlayerChatInputBuilder builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player); builder.isValidInput((p, str) -> { if (validateChatNumber(str, Settings.MIN_AUCTION_PRICE.getDouble(), false) && validateChatNumber(str, Settings.MAX_AUCTION_PRICE.getDouble(), true)) { @@ -225,8 +234,12 @@ public class GUISellItem extends AbstractPlaceholderGui { }}), ClickType.LEFT, e -> { setTheItemToBeListed(); setAllowClose(true); + e.gui.close(); + // work-around to clicking closeable item with item on cursor + handleClosableCursorItem(e); + PlayerChatInput.PlayerChatInputBuilder builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player); builder.isValidInput((p, str) -> { return validateChatNumber(str, Settings.MIN_AUCTION_START_PRICE.getDouble(), false) && validateChatNumber(str, Settings.MAX_AUCTION_START_PRICE.getDouble(), true); @@ -253,8 +266,12 @@ public class GUISellItem extends AbstractPlaceholderGui { }}), ClickType.LEFT, e -> { setTheItemToBeListed(); setAllowClose(true); + e.gui.close(); + // work-around to clicking closeable item with item on cursor + handleClosableCursorItem(e); + PlayerChatInput.PlayerChatInputBuilder builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player); builder.isValidInput((p, str) -> { return validateChatNumber(str, Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble(), false) && validateChatNumber(str, Settings.MAX_AUCTION_INCREMENT_PRICE.getDouble(), true); @@ -453,10 +470,20 @@ public class GUISellItem extends AbstractPlaceholderGui { AuctionHouse.getInstance().getAuctionPlayerManager().getUsingSellGUI().remove(e.player.getUniqueId()); setAllowClose(true); e.gui.close(); + + if (e.cursor != null) + e.player.getInventory().addItem(e.cursor); }); } + 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 validateChatNumber(String input, double requirement, boolean checkMax) { String val = ChatColor.stripColor(input); if (checkMax)