diff --git a/pom.xml b/pom.xml index 83ad705..ccd33a5 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 peacefulcraft.net Tarje - 0.0.3 + 0.0.4 Off-brand, generic, and totally not copyright infringing Super Target for Minecraft. 1.8 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 80f618e..d7599e0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ # name: Tarje main: net.peacefulcraft.tarje.Tarje -version: 0.0.3 +version: 0.0.4 api-version: 1.16 website: https://www.peacefulcraft.net/ depend: [ Vault ] diff --git a/src/net/peacefulcraft/tarje/shop/SellMenu.java b/src/net/peacefulcraft/tarje/shop/SellMenu.java index ddab777..edbc22f 100644 --- a/src/net/peacefulcraft/tarje/shop/SellMenu.java +++ b/src/net/peacefulcraft/tarje/shop/SellMenu.java @@ -1,11 +1,14 @@ package net.peacefulcraft.tarje.shop; +import java.util.HashMap; + import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import net.peacefulcraft.tarje.Tarje; @@ -13,8 +16,10 @@ public class SellMenu { private Player p; + private HashMap openViews; public SellMenu() { + this.openViews = new HashMap(); } /** @@ -22,7 +27,7 @@ public SellMenu() { * @param p The player to open the inventory for */ public void openMenu(Player p) { - p.openInventory(Bukkit.getServer().createInventory(null, 45, "Sell Items")); + this.openViews.put(p, p.openInventory(Bukkit.getServer().createInventory(null, 45, "Sell Items"))); } /** @@ -31,6 +36,7 @@ public void openMenu(Player p) { */ public void onInventoryClick(InventoryClickEvent ev) { if (ev.getCurrentItem() == null) { return; } + if (!this.openViews.containsKey((Player) ev.getView().getPlayer())) { return; } if (!Tarje._this().isItemSellable(ev.getCurrentItem().getType())) { ev.setCancelled(true); @@ -41,6 +47,8 @@ public void onInventoryClick(InventoryClickEvent ev) { public void onClose(InventoryCloseEvent ev) { Player p = (Player) ev.getPlayer(); Inventory inventory = ev.getInventory(); + if(!this.openViews.containsKey(p)) { return; } + this.openViews.remove(p); String confirmationMessage = "You sold "; double moneyDue = 0.0; diff --git a/src/net/peacefulcraft/tarje/shop/ShopMenu.java b/src/net/peacefulcraft/tarje/shop/ShopMenu.java index b0fb308..5e25ed0 100644 --- a/src/net/peacefulcraft/tarje/shop/ShopMenu.java +++ b/src/net/peacefulcraft/tarje/shop/ShopMenu.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.HashMap; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryType; @@ -119,6 +120,7 @@ public void closeShop(Player p) { * @param item The item that was clicked on */ public void onShopInventoryClick(Player p, int slotNumber, ItemStack item) { + if (!this.activeViews.containsKey(p)) { return; } ShopItem shopItem = this.config.getItems().get(slotNumber); if (!shopItem.isPurchasable()) { p.sendMessage(Tarje.messagingPrefix + "Sorry, " + shopItem.getItem() + " is not purchasable."); @@ -127,7 +129,9 @@ public void onShopInventoryClick(Player p, int slotNumber, ItemStack item) { Inventory purchaseQuantityMenu = this.generatePurchaseQuantityMenu(shopItem); this.closeShop(p); - this.activeViews.put(p, p.openInventory(purchaseQuantityMenu)); + Bukkit.getScheduler().runTask(Tarje._this(), () -> { + this.activeViews.put(p, p.openInventory(purchaseQuantityMenu)); + }); } /** @@ -166,6 +170,7 @@ private Inventory generatePurchaseQuantityMenu(ShopItem item) { * @param item The item in the inventory that was clicked */ public void onPurchaseQuantityInventoryClick(Player p, String title, ItemStack item) { + if (!this.activeViews.containsKey(p)) { return; } ShopItem shopItem = config.getItems().get(Integer.valueOf(title.split(" ")[2])); int purchaseQuantity = item.getAmount(); double purcahsePrice = shopItem.getBuyPrice() * purchaseQuantity;