Hot answers tagged bukkit
4
You could try to accomplish it by looping through player's inventor and checking if Nth slot in his inventory is empty, if it isn't -- the function returns false.
private boolean hasItems(ItemStack item) {
for (int i=0; i<=thePlayer.inventory.getSizeInventory()-5; i++) {
if (thePlayer.inventory.mainInventory[i].itemId != NULL) {
...
4
The objects in collections in Java are usually indexed starting with zero. Also, the method .size() returns the numbers of elements inside the collection.
So, if the size is 1, you can only access the element 0. Not 0 and 1 like you're doing, because the element 1 do not exist.
Try this:
for(int i = 0; i < staffOnline.size(); i++) { // changed here
...
2
I have seen this before and I am pretty sure that its because you are getting every item in inventory including the empty ones which return null. inv.getContents() gets everything. Add an if statement inside your for loop to check that they arent null before doing anything with the item.
Only top voted, non community-wiki answers of a minimum length are eligible