diff --git a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java index ae1b3f4..072562c 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java @@ -25,10 +25,7 @@ import ca.tweetzy.auctionhouse.auction.AuctionedItem; import ca.tweetzy.auctionhouse.commands.*; import ca.tweetzy.auctionhouse.database.DataManager; import ca.tweetzy.auctionhouse.database.migrations.*; -import ca.tweetzy.auctionhouse.listeners.AuctionListeners; -import ca.tweetzy.auctionhouse.listeners.CMIListener; -import ca.tweetzy.auctionhouse.listeners.ChestShopListener; -import ca.tweetzy.auctionhouse.listeners.PlayerListeners; +import ca.tweetzy.auctionhouse.listeners.*; import ca.tweetzy.auctionhouse.managers.*; import ca.tweetzy.auctionhouse.settings.LocaleSettings; import ca.tweetzy.auctionhouse.settings.Settings; @@ -183,6 +180,7 @@ public class AuctionHouse extends TweetyPlugin { // listeners Bukkit.getServer().getPluginManager().registerEvents(new PlayerListeners(), this); + Bukkit.getServer().getPluginManager().registerEvents(new MeteorClientListeners(), this); Bukkit.getServer().getPluginManager().registerEvents(new AuctionListeners(), this); if (getServer().getPluginManager().isPluginEnabled("ChestShop")) diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java index 4023c39..1063613 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java @@ -318,12 +318,15 @@ public final class CommandSell extends AbstractCommand { AuctionHouse.getInstance().getAuctionPlayerManager().addToSellProcess(player); if (Settings.ASK_FOR_LISTING_CONFIRMATION.getBoolean()) { + player.getInventory().setItemInHand(CompMaterial.AIR.parseItem()); + auctionPlayer.setItemBeingListed(auctionedItem.getItem()); + instance.getGuiManager().showGUI(player, new GUIListingConfirm(player, auctionedItem, result -> { if (!result) { AuctionHouse.getInstance().getAuctionPlayerManager().processSell(player); player.closeInventory(); -// PlayerUtils.giveItem(player, auctionedItem.getItem()); + PlayerUtils.giveItem(player, auctionedItem.getItem()); auctionPlayer.setItemBeingListed(null); return; } @@ -333,8 +336,6 @@ public final class CommandSell extends AbstractCommand { return; } - player.getInventory().setItemInHand(CompMaterial.AIR.parseItem()); - AuctionCreator.create(auctionPlayer, auctionedItem, (auction, listingResult) -> { AuctionHouse.getInstance().getAuctionPlayerManager().processSell(player); 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 72b2a55..693c73e 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIListingConfirm.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/confirmation/GUIListingConfirm.java @@ -19,10 +19,12 @@ package ca.tweetzy.auctionhouse.guis.confirmation; import ca.tweetzy.auctionhouse.AuctionHouse; +import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.auction.AuctionedItem; import ca.tweetzy.auctionhouse.auction.enums.AuctionStackType; import ca.tweetzy.auctionhouse.guis.AbstractPlaceholderGui; import ca.tweetzy.auctionhouse.settings.Settings; +import ca.tweetzy.core.utils.PlayerUtils; import ca.tweetzy.core.utils.TextUtils; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -58,6 +60,13 @@ public final class GUIListingConfirm extends AbstractPlaceholderGui { setOnClose(close -> { close.player.removeMetadata("AuctionHouseConfirmListing", AuctionHouse.getInstance()); + final AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(close.player.getUniqueId()); + + if (auctionPlayer.getItemBeingListed() != null) { + PlayerUtils.giveItem(close.player, auctionedItem.getItem()); + auctionPlayer.setItemBeingListed(null); + } + AuctionHouse.getInstance().getAuctionPlayerManager().processSell(close.player); }); diff --git a/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java b/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java index 62e9867..9abb2f7 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java +++ b/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java @@ -35,19 +35,18 @@ import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.block.Block; import org.bukkit.block.Chest; -import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.PrepareAnvilEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; -import org.bukkit.event.player.*; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataType; @@ -72,7 +71,8 @@ public class PlayerListeners implements Listener { Bukkit.getServer().getScheduler().cancelTask(auctionPlayer.getAssignedTaskId()); if (auctionPlayer.getItemBeingListed() != null && player.getLocation().getWorld() != null) { - player.getLocation().getWorld().dropItemNaturally(player.getLocation(), auctionPlayer.getItemBeingListed()); + if (!AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) + player.getLocation().getWorld().dropItemNaturally(player.getLocation(), auctionPlayer.getItemBeingListed()); auctionPlayer.setItemBeingListed(CompMaterial.AIR.parseItem()); } } @@ -176,61 +176,6 @@ public class PlayerListeners implements Listener { PlayerUtils.giveItem(player, items); } - @EventHandler - public void onItemDropDuringSell(final PlayerDropItemEvent event) { - final Player player = event.getPlayer(); - - if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) - event.setCancelled(true); - } - - @EventHandler - public void onHotbarSwapDuringSell(final PlayerItemHeldEvent event) { - final Player player = event.getPlayer(); - - if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) - event.setCancelled(true); - } - - @EventHandler - public void onOffhandSwap(final PlayerSwapHandItemsEvent event) { - final Player player = event.getPlayer(); - - if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) { - event.setCancelled(true); - } - } - - @EventHandler - public void onItemRemove(final InventoryClickEvent event) { - final HumanEntity clicker = event.getWhoClicked(); - if (!(clicker instanceof Player)) return; - - final Player player = (Player) clicker; - if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) { - event.setCancelled(true); - } - } - - - @EventHandler - public void onCommandDuringSell(final PlayerCommandPreprocessEvent event) { - final Player player = event.getPlayer(); - - if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) - event.setCancelled(true); - } - - @EventHandler - public void onBuildDuringSell(final BlockPlaceEvent event) { - final Player player = event.getPlayer(); - - if (AuctionHouse.getInstance().getAuctionPlayerManager().isInSellProcess(player)) { - event.setBuild(false); - event.setCancelled(true); - } - } - @EventHandler public void onInventoryClick(PrepareAnvilEvent event) { ItemStack stack = event.getResult();