Hi im looking to check to see if there is space in a players inventory for a certain amount of items say {9} if there isn't 9 slots free it will cancel the command and send out a message if there is 9 slots available for the kit it will go ahead with the rest if i have to i don't mind adding so the players inventory must be empty to use a command i'd prefer the other way do thanks please tahg in reply
Arrxzon Loop through the player's inventory and check if the slot is equal to null. Then add 1 to a count. After going through all the slots, compare the value to the slots needed. (To loop through the inventory run a foreach on player.getImventory().getContents()
mrkirby153 thanks im trying this way right now as it's way simpler only problem is sends a message for every slot..? i know player.getInventory().firstEmpty() or player.getInventory().getFirstEmpty() (or something) but not sure on how to implement were functional This is the working method that spams the message Thanks for(ItemStack item : player.getInventory().getContents()){ if(item != null){ player.sendMessage("Please clear your inventory first."); }else{ //do stuff } }
If you're doing what I think you're doing. You might want to consider dropping the items at the players feet if they inventory is full. Overflow items don't get added, and then people compain for refunds. My method suggested above could also help with the problem.
zzienzz aiming to use the above "Please clear your inventory first" message at the moment to push a release to our server. As it's working only thing is the message spams
Arrxzon for(ItemStack item : player.getInventory().getContents()){ if(item == null){ player.sendMessage("Please clear your inventory first."); break; } }
Arrxzon my approach ? Does it still send messages? Have you altered what i gave u? tahg me if u wan me pls
Pizza371 ye did not send message-took away coins- i have it like if (cmd.getName().equalsIgnoreCase("rankkit")) { if (args.length == 1) { if (args[0].equalsIgnoreCase("recruit")) { for(ItemStack item : player.getInventory().getContents()){ if(item == null){ player.sendMessage("Please clear your inventory first."); break; } } the rest doing stuff that it should if inventory is empty } } } then altered it a couple of times with no luck
Arrxzon Try Code:java int openSlots = 0;for(ItemStack item : player.getInventory.getContents(){If(item=null)openSlots++;}If(openSlots < slotsNeeded /* The slots in the inventory that you need to fill with items */){player.sendMessage("Please remove "+(slotsNeeded - openSlots)+" items from your inventory!");return;}// Put your code here.
mrkirby153 Beautiful man thanks for this slight modification below got it working thanks again Code:java private static final int slotsNeeded = 10; //command args int openSlots = 0; for(ItemStack item : player.getInventory().getContents()){ if(item == null) openSlots++; } if(openSlots < slotsNeeded){ player.sendMessage("Please remove "+(slotsNeeded - openSlots)+" items from your inventory!"); return false; }// code here.