question in title... Code: Code (Text): for(ItemStack slot:player.getInventory().getContents()){ if(slot !=null){ if(slot.getType() == Material.SKULL_ITEM){ }else{ player.sendmessage("test"); } } And i get the message 4 times? Why?
because you got 4 skulls in your inventory? ^^ or the whole loop getts called 4 times, we will need for context then
If you're saying that you have an inventory full of skulls yet it still sends the message 4 times, I'm assuming that either the crafting table or armour contents are included in the Inventory#getContents()
Code (Text): public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { Player player = (Player) sender; if(sender instanceof Player){ if(player.hasPermission("MobHeads.sellall")){ for(ItemStack slot:player.getInventory().getContents()){ if(slot !=null){ if(slot.getType() == Material.SKULL_ITEM){ }else{ player.sendMessage("Test"); } } } } } There is the code?..
No i'm saying when i DONT have any skulls in my inventory AND when i have i get the message... it should only give me when i dont have... + it gives me it 4 times?
oop misread that. That empty if case tho... add + slot.getType() to your test message to see what item there is. My guess would be its AIR, so you gotta ignore that case
can't see that image, I am behind a company proxy. Go gotta embedd it into the img tags using the direct link so that I can see it (or just tell we what you are seeing)
Not sure what is surprising there? From your code, whenever an item is not a skull it sends you that message.
In your hotbar, you have 4 items that are not skulls. In your code, you send a message whenever an item is not a skull. I don't see what the problem is, the code does exactly what it is supposed to do (as you are iterating over your inventory contents). What did you expect it would be doing?
No i dont!? Code (Text): if(slot.getType().equals(Material.SKULL_ITEM)){ //Do something but don't wanna show it.. }else{ player.sendmessage("You don't have any heads!");
Did you want it to message you once if you have no skulls in your inventory? if so, you are sending the message after every checking every item. This is how your code is running: 1) Looks at item 1, 2) Checks if the item is a skull 2a) if it is, do nothing 2b) else, send the player a message. 3) Looks at item 2, 4) Checks if the item is a skull 4a) if it is, do nothing 4b) else, send the player a message etc. and repeats this for every item in your inventory
@redstonebiten you made a mistake that a crap ton of people make. For EACH single item in the inv, you check if the type is a skull, and if it's not you print. You do this for EACH item, the else doesn't make it only do it if there are no skulls at all