From f66c85d5b07c3781cfb7e6fbc27d0e86abbfe6cb Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 3 Nov 2015 18:57:41 +1300 Subject: [PATCH] When clearing or getting items from player inventory, get it from player crafting as well --- .../mineplex/core/common/util/UtilInv.java | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java index bc6443777..1b1b5b775 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java @@ -12,6 +12,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -70,13 +71,13 @@ public class UtilInv public static boolean contains(Player player, String itemNameContains, Material item, byte data, int required) { - return contains(player, itemNameContains, item, data, required, true, true); + return contains(player, itemNameContains, item, data, required, true, true, true); } - public static boolean contains(Player player, String itemNameContains, Material item, byte data, int required, boolean checkArmor, boolean checkCursor) + public static boolean contains(Player player, String itemNameContains, Material item, byte data, int required, boolean checkArmor, boolean checkCursor, boolean checkCrafting) { - for (ItemStack stack : getItems(player, checkArmor, checkCursor)) + for (ItemStack stack : getItems(player, checkArmor, checkCursor, checkCrafting)) { if (required <= 0) { @@ -154,18 +155,25 @@ public class UtilInv PlayerInventory inv = player.getInventory(); inv.clear(); - inv.setArmorContents(new ItemStack[4]); - player.setItemOnCursor(new ItemStack(Material.AIR)); - + inv.setArmorContents(new ItemStack[4]); + player.setItemOnCursor(new ItemStack(Material.AIR)); + + Inventory openInventory = player.getOpenInventory().getTopInventory(); + + if (openInventory.getHolder() == player) + { + openInventory.clear(); + } + player.saveData(); } public static ArrayList getItems(Player player) { - return getItems(player, true, true); + return getItems(player, true, true, true); } - public static ArrayList getItems(Player player, boolean getArmor, boolean getCursor) + public static ArrayList getItems(Player player, boolean getArmor, boolean getCursor, boolean getCrafting) { ArrayList items = new ArrayList(); PlayerInventory inv = player.getInventory(); @@ -197,6 +205,22 @@ public class UtilInv items.add(cursorItem.clone()); } + if (getCrafting) + { + Inventory openInventory = player.getOpenInventory().getTopInventory(); + + if (openInventory.getHolder() == player && openInventory.getType() == InventoryType.CRAFTING) + { + for (ItemStack item : openInventory.getContents()) + { + if (item != null && item.getType() != Material.AIR) + { + items.add(item.clone()); + } + } + } + } + return items; } @@ -357,11 +381,12 @@ public class UtilInv return getAmount(player, mat, true); } - public static int getAmount(Player player, Material mat, boolean includeArmorAndCursor) + public static int getAmount(Player player, Material mat, boolean includeArmorAndCursorAndCrafting) { int amount = 0; - - for (ItemStack item : getItems(player, true, true)) + + for (ItemStack item : getItems(player, includeArmorAndCursorAndCrafting, includeArmorAndCursorAndCrafting, + includeArmorAndCursorAndCrafting)) { if (item.getType() == mat) {