From e3a41dd64c11ff9ca61f079cce9b08cd07cc18b0 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Tue, 14 Feb 2023 13:30:07 -0500 Subject: [PATCH] =?UTF-8?q?=E2=8C=9A=20Add=20slight=20delay=20to=20auction?= =?UTF-8?q?=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 7 minutes --- .../auctionhouse/commands/CommandSell.java | 46 +++++++++++++------ .../auctionhouse/helpers/Validate.java | 26 +++++++++++ .../listeners/PlayerListeners.java | 1 + .../auctionhouse/settings/Settings.java | 1 + 4 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 src/main/java/ca/tweetzy/auctionhouse/helpers/Validate.java diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java index 83399ba..06105ff 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java @@ -338,9 +338,9 @@ public final class CommandSell extends AbstractCommand { auctionedItem.setInfinite(isInfinite); auctionedItem.setAllowPartialBuy(partialBuy); - player.getInventory().setItemInHand(CompMaterial.AIR.parseItem()); - if (Settings.ASK_FOR_LISTING_CONFIRMATION.getBoolean()) { + player.getInventory().setItemInHand(CompMaterial.AIR.parseItem()); + instance.getGuiManager().showGUI(player, new GUIListingConfirm(player, auctionedItem, result -> { if (!result) { player.closeInventory(); @@ -349,9 +349,36 @@ public final class CommandSell extends AbstractCommand { return; } + Bukkit.getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> { + if (auctionPlayer.getPlayer() == null || !auctionPlayer.getPlayer().isOnline()) { + return; + } + + player.getInventory().setItemInHand(CompMaterial.AIR.parseItem()); + + AuctionCreator.create(auctionPlayer, auctionedItem, (auction, listingResult) -> { + if (listingResult != ListingResult.SUCCESS) { + PlayerUtils.giveItem(player, auction.getItem()); + auctionPlayer.setItemBeingListed(null); + return; + } + + if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) + instance.getGuiManager().showGUI(player, new GUIAuctionHouse(auctionPlayer)); + }); + + }, Settings.INTERNAL_CREATE_DELAY.getInt()); + })); + } else { + Bukkit.getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> { + if (auctionPlayer.getPlayer() == null || !auctionPlayer.getPlayer().isOnline()) { + return; + } + + player.getInventory().setItemInHand(CompMaterial.AIR.parseItem()); + AuctionCreator.create(auctionPlayer, auctionedItem, (auction, listingResult) -> { if (listingResult != ListingResult.SUCCESS) { - player.closeInventory(); PlayerUtils.giveItem(player, auction.getItem()); auctionPlayer.setItemBeingListed(null); return; @@ -360,18 +387,9 @@ public final class CommandSell extends AbstractCommand { if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) instance.getGuiManager().showGUI(player, new GUIAuctionHouse(auctionPlayer)); }); - })); - } else { - AuctionCreator.create(auctionPlayer, auctionedItem, (auction, listingResult) -> { - if (listingResult != ListingResult.SUCCESS) { - PlayerUtils.giveItem(player, auction.getItem()); - auctionPlayer.setItemBeingListed(null); - return; - } - if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) - instance.getGuiManager().showGUI(player, new GUIAuctionHouse(auctionPlayer)); - }); + }, Settings.INTERNAL_CREATE_DELAY.getInt()); + } return ReturnType.SUCCESS; diff --git a/src/main/java/ca/tweetzy/auctionhouse/helpers/Validate.java b/src/main/java/ca/tweetzy/auctionhouse/helpers/Validate.java new file mode 100644 index 0000000..de416c7 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/helpers/Validate.java @@ -0,0 +1,26 @@ +/* + * Auction House + * Copyright 2023 Kiran Hart + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package ca.tweetzy.auctionhouse.helpers; + +import lombok.experimental.UtilityClass; + +@UtilityClass +public final class Validate { + +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java b/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java index 197da76..b3acc9e 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java +++ b/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java @@ -101,6 +101,7 @@ public class PlayerListeners implements Listener { player.getInventory().addItem(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()).getItemBeingListed()); instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()).setItemBeingListed(null); + instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()).setPlayer(null); } diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java index 496ba1d..c866ee9 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java @@ -54,6 +54,7 @@ public class Settings { * ===============================*/ public static final ConfigSetting DEFAULT_BIN_LISTING_TIME = new ConfigSetting(config, "auction setting.listings times.bin item", 86400, "The default listing time for bin items (buy only items) before they expire"); public static final ConfigSetting DEFAULT_AUCTION_LISTING_TIME = new ConfigSetting(config, "auction setting.listings times.auction item", 604800, "The default listing time for auction items before they expire"); + public static final ConfigSetting INTERNAL_CREATE_DELAY = new ConfigSetting(config, "auction setting.internal create delay", 3, "How many ticks should auction house wait before actually creating the item."); public static final ConfigSetting MAX_AUCTION_PRICE = new ConfigSetting(config, "auction setting.pricing.max auction price", 1000000000, "The max price for buy only / buy now items"); public static final ConfigSetting MAX_AUCTION_START_PRICE = new ConfigSetting(config, "auction setting.pricing.max auction start price", 1000000000, "The max price starting a bidding auction"); public static final ConfigSetting MAX_AUCTION_INCREMENT_PRICE = new ConfigSetting(config, "auction setting.pricing.max auction increment price", 1000000000, "The max amount for incrementing a bid.");