Skip to content

Instantly share code, notes, and snippets.

@MarinusLeeuwerik
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarinusLeeuwerik/a5374d916c8663f4ef38 to your computer and use it in GitHub Desktop.
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.
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