I got a problem. I'm developing a "hat"-plugin, which allows you to add the ItemInHand to the your helmet. Problem was, that an internal server error occures :/ Can someone help me? My code Console
You my friend got a nullpointer exeption, so something in your code returns null, let me have a look...
You should do a null check on it, like if(item != null){ if(item == what you want{//Your code here} }
@XbannisherX Thanks your help! I changed the code but... Code http://prntscr.com/g1603 Error http://prntscr.com/g164e
Here I had an old hat command and I updated to your needs. Code: private boolean handleHat(CommandSender sender, String[] args) { Player player = (Player) sender; if (player.getItemInHand().getType() != Material.AIR) { ItemStack itemHand = player.getItemInHand(); PlayerInventory inventory = player.getInventory(); ItemStack itemHead = inventory.getHelmet(); inventory.removeItem(itemHand); inventory.setHelmet(itemHand); inventory.setItemInHand(itemHead); player.sendMessage(ChatColor.GREEN + "Item successfuly put on your head."); player.sendMessage(ChatColor.AQUA + "Remember to check your helment slot to make sure you didnt put more then 1 of that item!"); return true; } else { player.sendMessage(ChatColor.RED + "You must have something to put on your head!"); return true; } } Remember to check if it is a player by checking if instanceof Player. If you try do to it in the console you will get an error saying you cant cast entity player to the console.