When clearing or getting items from player inventory, get it from player crafting as well

This commit is contained in:
libraryaddict 2015-11-03 18:57:41 +13:00
parent 975ad9e6ea
commit f66c85d5b0

View File

@ -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<ItemStack> getItems(Player player)
{
return getItems(player, true, true);
return getItems(player, true, true, true);
}
public static ArrayList<ItemStack> getItems(Player player, boolean getArmor, boolean getCursor)
public static ArrayList<ItemStack> getItems(Player player, boolean getArmor, boolean getCursor, boolean getCrafting)
{
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
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)
{