Command Arguments/Strings error message is 'wrong'!

Discussion in 'Plugin Development' started by Skrarity, Nov 9, 2014.

Thread Status:
Not open for further replies.
  1. Code:java
    1. if(args.length == 1) {
    2.  
    3. ItemStack hat = new ItemStack(Material.getMaterial(args[0].toUpperCase()));
    4. if(args[0].equalsIgnoreCase(hat.getType().toString())) {
    5. p.getInventory().setHelmet(hat);
    6. ItemStack gotHat = p.getInventory().getHelmet();
    7. p.getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 6);
    8. p.sendMessage(ChatColor.GREEN + "You've changed your hat to " + ChatColor.RED + gotHat.getType());
    9.  
    10. } else {
    11. p.sendMessage(ChatColor.RED + "'" +args[0] + "' isn't a Material!");
    12. }
    13. }


    So my question is , the error message or when I'm typing in "/hat sdfkj" it isn't a material and you can see I've written an error message when you typed in something else what isn't a command and yeah that doesn't works!
    The error message isn't "sdfkj isn't a Material!" its (typical)
    "An internal error occured while attempting to perform this command"

    :( :( :( What did I wrong? And yes my english is bad but i hope its understandable
     
  2. Offline

    leon3001

    Skrarity You are trying to create an ItemStack before you check if the material exists. That's causing your error.
     
  3. I'm confused HOW I can check if the material exists???
     
Thread Status:
Not open for further replies.

Share This Page