From 7c49d17d163628b00ec10cc08b555aee283a7560 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Fri, 28 Apr 2023 13:27:39 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=B2=20Fixed=20bug=20where=20when=20can?= =?UTF-8?q?celling=20a=20listing=20confirmation=20for=20bundled=20items,?= =?UTF-8?q?=20it=20will=20give=20the=20bundle=20item=20rather=20than=20the?= =?UTF-8?q?=20individual=20items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 16 minutes --- .../auctionhouse/guis/GUIBundleCreation.java | 9 ++++++++- .../guis/confirmation/GUIListingConfirm.java | 7 ++++++- .../guis/sell/GUISellPlaceItem.java | 20 +++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIBundleCreation.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIBundleCreation.java index 0daac80..85d0f0c 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIBundleCreation.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIBundleCreation.java @@ -20,6 +20,7 @@ package ca.tweetzy.auctionhouse.guis; import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.ahv3.api.ListingResult; +import ca.tweetzy.auctionhouse.ahv3.model.BundleUtil; import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.auction.AuctionedItem; @@ -128,11 +129,17 @@ public final class GUIBundleCreation extends AbstractPlaceholderGui { auctionedItem.setInfinite(false); auctionedItem.setAllowPartialBuy(false); + auctionPlayer.setItemBeingListed(bundle); + if (Settings.ASK_FOR_LISTING_CONFIRMATION.getBoolean()) { instance.getGuiManager().showGUI(auctionPlayer.getPlayer(), new GUIListingConfirm(auctionPlayer.getPlayer(), auctionedItem, result -> { if (!result) { auctionPlayer.getPlayer().closeInventory(); - PlayerUtils.giveItem(auctionPlayer.getPlayer(), auctionedItem.getItem()); + + if (BundleUtil.isBundledItem(auctionedItem.getItem())) PlayerUtils.giveItem(auctionPlayer.getPlayer(), BundleUtil.extractBundleItems(auctionedItem.getItem())); + else PlayerUtils.giveItem(auctionPlayer.getPlayer(), auctionedItem.getItem()); + + auctionPlayer.setItemBeingListed(null); return; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIListingConfirm.java b/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIListingConfirm.java index f3113ee..6dcdea9 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIListingConfirm.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIListingConfirm.java @@ -19,6 +19,7 @@ package ca.tweetzy.auctionhouse.guis.confirmation; import ca.tweetzy.auctionhouse.AuctionHouse; +import ca.tweetzy.auctionhouse.ahv3.model.BundleUtil; import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.auction.AuctionedItem; import ca.tweetzy.auctionhouse.auction.enums.AuctionStackType; @@ -63,7 +64,11 @@ public final class GUIListingConfirm extends AbstractPlaceholderGui { final AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(close.player.getUniqueId()); if (auctionPlayer.getItemBeingListed() != null) { - PlayerUtils.giveItem(close.player, auctionedItem.getItem()); + if (BundleUtil.isBundledItem(auctionedItem.getItem())) PlayerUtils.giveItem(close.player, BundleUtil.extractBundleItems(auctionedItem.getItem())); + else { + PlayerUtils.giveItem(close.player, auctionedItem.getItem()); + } + auctionPlayer.setItemBeingListed(null); } diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellPlaceItem.java b/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellPlaceItem.java index 2f87414..73b3bca 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellPlaceItem.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/sell/GUISellPlaceItem.java @@ -26,9 +26,12 @@ import ca.tweetzy.auctionhouse.auction.enums.AuctionSaleType; import ca.tweetzy.auctionhouse.guis.AbstractPlaceholderGui; import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper; import ca.tweetzy.auctionhouse.settings.Settings; +import ca.tweetzy.core.compatibility.XMaterial; +import ca.tweetzy.core.gui.events.GuiClickEvent; import ca.tweetzy.core.utils.PlayerUtils; import lombok.NonNull; import org.bukkit.Material; +import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; @@ -58,6 +61,8 @@ public final class GUISellPlaceItem extends AbstractPlaceholderGui { if (viewMode == ViewMode.SINGLE_ITEM) { setUnlocked(1, 4); setItem(1, 4, AIR); + + } else { setUnlockedRange(0, 35); setItems(0, 35, AIR); @@ -65,9 +70,24 @@ public final class GUISellPlaceItem extends AbstractPlaceholderGui { setOnClose(close -> gatherSellableItems().forEach(item -> PlayerUtils.giveItem(close.player, item))); + setPlayerInventoryAction(this::handleBlockedItemClick); + setDefaultAction(click -> { + if (click.clickType == ClickType.NUMBER_KEY) + click.event.setCancelled(true); + }); + draw(); } + private void handleBlockedItemClick(GuiClickEvent click) { + final ItemStack clicked = click.clickedItem; + if (clicked == null || clicked.getType() == XMaterial.AIR.parseMaterial()) return; + + if (!AuctionAPI.getInstance().meetsListingRequirements(click.player, clicked)) { + click.event.setCancelled(true); + } + } + private void draw() { setButton(getRows() - 1, 0, getBackButtonItem(), click -> {