From ee64ff2bf64efb4dc5e5c6ce60b8cd489731f92c Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Thu, 18 Sep 2014 17:48:35 -0500 Subject: [PATCH] Dispose of Shop if the InventoryOpenEvent gets cancelled --- .../src/mineplex/core/shop/ShopBase.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java index d912758e2..9c4b27a94 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java @@ -5,24 +5,22 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; +import org.bukkit.ChatColor; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.ChatColor; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.common.CurrencyType; import mineplex.core.common.util.NautHashMap; import mineplex.core.donation.DonationManager; -import mineplex.core.npc.NpcManager; import mineplex.core.npc.event.NpcDamageByEntityEvent; import mineplex.core.npc.event.NpcInteractEntityEvent; import mineplex.core.shop.page.ShopPageBase; @@ -159,6 +157,25 @@ public abstract class ShopBase implements Listene OpenedShop.remove(event.getPlayer().getName()); } } + + @EventHandler(priority = EventPriority.MONITOR) + public void onInventoryOpen(InventoryOpenEvent event) + { + if (!event.isCancelled()) + return; + + if (PlayerPageMap.containsKey(event.getPlayer().getName()) && PlayerPageMap.get(event.getPlayer().getName()).getTitle() != null && PlayerPageMap.get(event.getPlayer().getName()).getTitle().equalsIgnoreCase(event.getInventory().getTitle())) + { + PlayerPageMap.get(event.getPlayer().getName()).PlayerClosed(); + PlayerPageMap.get(event.getPlayer().getName()).Dispose(); + + PlayerPageMap.remove(event.getPlayer().getName()); + + CloseShopForPlayer((Player)event.getPlayer()); + + OpenedShop.remove(event.getPlayer().getName()); + } + } protected boolean CanOpenShop(Player player) {