When clearing or getting items from player inventory, get it from player crafting as well
This commit is contained in:
parent
975ad9e6ea
commit
f66c85d5b0
@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.inventory.InventoryAction;
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
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)
|
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)
|
if (required <= 0)
|
||||||
{
|
{
|
||||||
@ -157,15 +158,22 @@ public class UtilInv
|
|||||||
inv.setArmorContents(new ItemStack[4]);
|
inv.setArmorContents(new ItemStack[4]);
|
||||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||||
|
|
||||||
|
Inventory openInventory = player.getOpenInventory().getTopInventory();
|
||||||
|
|
||||||
|
if (openInventory.getHolder() == player)
|
||||||
|
{
|
||||||
|
openInventory.clear();
|
||||||
|
}
|
||||||
|
|
||||||
player.saveData();
|
player.saveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<ItemStack> getItems(Player player)
|
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>();
|
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
PlayerInventory inv = player.getInventory();
|
PlayerInventory inv = player.getInventory();
|
||||||
@ -197,6 +205,22 @@ public class UtilInv
|
|||||||
items.add(cursorItem.clone());
|
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;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,11 +381,12 @@ public class UtilInv
|
|||||||
return getAmount(player, mat, true);
|
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;
|
int amount = 0;
|
||||||
|
|
||||||
for (ItemStack item : getItems(player, true, true))
|
for (ItemStack item : getItems(player, includeArmorAndCursorAndCrafting, includeArmorAndCursorAndCrafting,
|
||||||
|
includeArmorAndCursorAndCrafting))
|
||||||
{
|
{
|
||||||
if (item.getType() == mat)
|
if (item.getType() == mat)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user