pull/6/head
parent
6736f94a0a
commit
319b29c56e
9 changed files with 206 additions and 26 deletions
@ -0,0 +1,32 @@ |
|||||||
|
package xyz.soukup.ecoCraftCore.utilities; |
||||||
|
|
||||||
|
import org.bukkit.inventory.Inventory; |
||||||
|
import org.bukkit.inventory.ItemStack; |
||||||
|
|
||||||
|
public class InventoryUtils { |
||||||
|
public static Integer getCount(Inventory inventory, ItemStack item){ |
||||||
|
int count = 0; |
||||||
|
for (ItemStack itemStack : inventory.getContents()){ |
||||||
|
if (itemStack != null && itemStack.isSimilar(item)){ |
||||||
|
count += itemStack.getAmount(); |
||||||
|
} |
||||||
|
} |
||||||
|
return count; |
||||||
|
} |
||||||
|
public static Integer getSpaceLeft(Inventory inventory, ItemStack item){ |
||||||
|
int count = 0; |
||||||
|
int stackSize = item.getMaxStackSize(); |
||||||
|
|
||||||
|
for (ItemStack itemStack : inventory.getContents()){ |
||||||
|
if(itemStack == null){ |
||||||
|
count += stackSize; |
||||||
|
continue; |
||||||
|
} |
||||||
|
if (itemStack.isSimilar(item)){ |
||||||
|
count += stackSize - itemStack.getAmount(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return count; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue