From 0d3da74f9464e6545d9e80e5fbe0a742a9f6885e Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Wed, 13 Nov 2024 14:00:06 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=8E=20fixed=20filter=20cycle=20bug,=20?= =?UTF-8?q?and=20listing=20confirmation=20when=20player=20doesn't=20have?= =?UTF-8?q?=20enough=20money?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 2 minutes --- .../auction/enums/AuctionItemCategory.java | 24 +++++++++++++++---- .../auctionhouse/commands/CommandSell.java | 3 ++- .../guis/confirmation/GUIListingConfirm.java | 4 ++-- .../guis/core/GUIAuctionHouse.java | 4 +++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/ca/tweetzy/auctionhouse/auction/enums/AuctionItemCategory.java b/src/main/java/ca/tweetzy/auctionhouse/auction/enums/AuctionItemCategory.java index a51509d..e8cd142 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/auction/enums/AuctionItemCategory.java +++ b/src/main/java/ca/tweetzy/auctionhouse/auction/enums/AuctionItemCategory.java @@ -140,13 +140,29 @@ public enum AuctionItemCategory { return getType(); } +// public AuctionItemCategory next() { +// int currentIndex = this.ordinal(); +// int nextIndex = currentIndex + 1; +// while (!values()[nextIndex %= values().length].isEnabled()) { +// nextIndex++; +// } +// +// return values()[nextIndex]; +// } + public AuctionItemCategory next() { int currentIndex = this.ordinal(); - int nextIndex = currentIndex + 1; - while (!values()[nextIndex %= values().length].isEnabled()) { - nextIndex++; + int nextIndex = currentIndex; + int totalCategories = values().length; + + for (int i = 1; i <= totalCategories; i++) { + nextIndex = (currentIndex + i) % totalCategories; + if (values()[nextIndex].isEnabled()) { + return values()[nextIndex]; + } } - return values()[nextIndex]; + // If no enabled categories are found, return the current category + return this; } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java index 2daae76..3392674 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java @@ -426,8 +426,9 @@ public final class CommandSell extends Command { AuctionHouse.getAuctionPlayerManager().processSell(player); if (listingResult != ListingResult.SUCCESS) { -// PlayerUtils.giveItem(player, auction.getCleanItem()); + PlayerUtils.giveItem(player, auction.getCleanItem()); auctionPlayer.setItemBeingListed(null); + AuctionHouse.newChain().sync(player::closeInventory).execute(); 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 14b7cac..c43aa88 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIListingConfirm.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIListingConfirm.java @@ -59,7 +59,7 @@ public final class GUIListingConfirm extends AuctionBaseGUI { }); setOnClose(close -> { - final AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(close.player.getUniqueId()); + final AuctionPlayer auctionPlayer = AuctionHouse.getAuctionPlayerManager().getPlayer(close.player.getUniqueId()); if (!this.resulted.contains(close.player.getUniqueId())) { if (auctionPlayer.getItemBeingListed() != null) { @@ -73,7 +73,7 @@ public final class GUIListingConfirm extends AuctionBaseGUI { } close.player.removeMetadata("AuctionHouseConfirmListing", AuctionHouse.getInstance()); - AuctionHouse.getInstance().getAuctionPlayerManager().processSell(close.player); + AuctionHouse.getAuctionPlayerManager().processSell(close.player); }); draw(); } diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/core/GUIAuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/guis/core/GUIAuctionHouse.java index 2efdbd2..5d75307 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/core/GUIAuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/core/GUIAuctionHouse.java @@ -665,7 +665,7 @@ public final class GUIAuctionHouse extends AuctionUpdatingPagedGUI