From 491c8ec4a8d9264ea1f84889709dfbf3b6588e9a Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Tue, 6 Jun 2023 17:47:31 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20when=20closing=20the=20sell=20me?= =?UTF-8?q?nu=20(auction/bin)=20with=20a=20bundled=20listing,=20if=20the?= =?UTF-8?q?=20action=20was=20to=20rejoin,=20it=20will=20give=20the=20playe?= =?UTF-8?q?r=20the=20extracted=20bundle.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 3 minutes --- .../auctionhouse/guis/sell/GUISellAuction.java | 13 +++++++++---- .../auctionhouse/guis/sell/GUISellBin.java | 17 +++++++++++------ .../auctionhouse/listeners/PlayerListeners.java | 9 ++++++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellAuction.java b/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellAuction.java index c25ea31..693ded6 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellAuction.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellAuction.java @@ -41,6 +41,7 @@ import ca.tweetzy.core.utils.nms.NBTEditor; import lombok.NonNull; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import java.util.Arrays; import java.util.HashMap; @@ -70,10 +71,14 @@ public final class GUISellAuction extends AbstractPlaceholderGui { setRows(6); setOnClose(close -> { - if (BundleUtil.isBundledItem(this.auctionPlayer.getItemBeingListed())) - PlayerUtils.giveItem(close.player, BundleUtil.extractBundleItems(this.auctionPlayer.getItemBeingListed())); - else - PlayerUtils.giveItem(close.player, this.auctionPlayer.getItemBeingListed()); + final ItemStack itemToGive = this.auctionPlayer.getItemBeingListed(); + if (itemToGive != null) + + if (BundleUtil.isBundledItem(itemToGive)) { + PlayerUtils.giveItem(close.player, BundleUtil.extractBundleItems(itemToGive)); + } else { + PlayerUtils.giveItem(close.player, itemToGive); + } this.auctionPlayer.setItemBeingListed(null); }); diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellBin.java b/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellBin.java index d17c5e2..e05181d 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellBin.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellBin.java @@ -41,6 +41,7 @@ import ca.tweetzy.core.utils.nms.NBTEditor; import lombok.NonNull; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import java.util.Arrays; import java.util.HashMap; @@ -66,10 +67,14 @@ public final class GUISellBin extends AbstractPlaceholderGui { setRows(6); setOnClose(close -> { - if (BundleUtil.isBundledItem(this.auctionPlayer.getItemBeingListed())) PlayerUtils.giveItem(close.player, BundleUtil.extractBundleItems(this.auctionPlayer.getItemBeingListed())); - else { - PlayerUtils.giveItem(close.player, this.auctionPlayer.getItemBeingListed()); - } + final ItemStack itemToGive = this.auctionPlayer.getItemBeingListed(); + if (itemToGive != null) + + if (BundleUtil.isBundledItem(itemToGive)) { + PlayerUtils.giveItem(close.player, BundleUtil.extractBundleItems(itemToGive)); + } else { + PlayerUtils.giveItem(close.player, itemToGive); + } this.auctionPlayer.setItemBeingListed(null); @@ -166,7 +171,7 @@ public final class GUISellBin extends AbstractPlaceholderGui { setItem(1, 4, createListingItem().getDisplayStack(AuctionStackType.LISTING_PREVIEW)); - setButton(getRows() - 1, 4, ConfigurationItemHelper.createConfigurationItem(this.player, + setButton(getRows() - 1, 4, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_SELL_BIN_ITEM_ITEMS_CONTINUE_ITEM.getString(), Settings.GUI_SELL_BIN_ITEM_ITEMS_CONTINUE_NAME.getString(), Settings.GUI_SELL_BIN_ITEM_ITEMS_CONTINUE_LORE.getStringList(), @@ -213,7 +218,7 @@ public final class GUISellBin extends AbstractPlaceholderGui { private void drawQtyPurchase() { if (Settings.ALLOW_PURCHASE_OF_SPECIFIC_QUANTITIES.getBoolean()) { - setButton(3, 7, ConfigurationItemHelper.createConfigurationItem(this.player, + setButton(3, 7, ConfigurationItemHelper.createConfigurationItem(this.player, this.allowPartialBuy ? Settings.GUI_SELL_BIN_ITEM_ITEMS_PARTIAL_ENABLED_ITEM.getString() : Settings.GUI_SELL_BIN_ITEM_ITEMS_PARTIAL_DISABLED_ITEM.getString(), this.allowPartialBuy ? Settings.GUI_SELL_BIN_ITEM_ITEMS_PARTIAL_ENABLED_NAME.getString() : Settings.GUI_SELL_BIN_ITEM_ITEMS_PARTIAL_DISABLED_NAME.getString(), this.allowPartialBuy ? Settings.GUI_SELL_BIN_ITEM_ITEMS_PARTIAL_ENABLED_LORE.getStringList() : Settings.GUI_SELL_BIN_ITEM_ITEMS_PARTIAL_DISABLED_LORE.getStringList(), diff --git a/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java b/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java index 5edc420..650f539 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java +++ b/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java @@ -108,7 +108,14 @@ public class PlayerListeners implements Listener { if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) != null && instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()).getItemBeingListed() != null) { - player.getInventory().addItem(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()).getItemBeingListed()); + final ItemStack toGiveRaw = instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()).getItemBeingListed(); + + if (BundleUtil.isBundledItem(toGiveRaw)) { + PlayerUtils.giveItem(player, BundleUtil.extractBundleItems(toGiveRaw)); + } else { + PlayerUtils.giveItem(player, toGiveRaw); + } + instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()).setItemBeingListed(null); instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()).setPlayer(null); }