Last active
August 29, 2015 14:01
-
-
Save MarinusLeeuwerik/a5374d916c8663f4ef38 to your computer and use it in GitHub Desktop.
Get amount of the specified item in one's inventory. Simple, but efficient.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package code.MarinusLeeuwerik.utils | |
public class GetItemAmount { | |
public int getItemAmount(Inventory inventory, Material... search) { | |
List<Material> wanted = Arrays.asList(search); | |
int amount = 0; | |
for(ItemStack item : inventory.getContents()) { | |
if(item != null && wanted.contains(item.getType())) | |
amount += item.getAmount(); | |
} | |
return amount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment