Material.getMaterial(String): Problem for me

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

Thread Status:
Not open for further replies.
  1. I have got a hat plugin (selfmade) and when I'm doing /hat SPONGE its working but when I'm doing /hat Sponge , /hat sPonGe etc. it won't work so my question is how I can change it that its able to "compile" sPonGe or a "custom" method to write sponge or another material like obsidian because its real shit when you have to write every material in capslock

    for better understanding here is a part of my code
    Code:java
    1. if(args.length == 1) {
    2. ItemStack hat = new ItemStack(Material.getMaterial(args[0]));
    3. p.getInventory().setHelmet(hat);
    4.  
    5.  
    6. }


    Thanks for help! Sorry for bad english but I think its understandable
     
  2. Skrarity
    Loop through Material.values(), then check if Material.name() equalsIgnoreCase args[0].
     
  3. Offline

    adam753

    args[0].toUpperCase()
     
  4. I can't understand sorry, can you give me an example? When you meant I can check if Material.name() equalsIgnoreCase my args[0] than I can tell you: It won't work

    But whatever thanks for help

    Didn't red adam73 so TY ITS WORKING

    Code:java
    1. ItemStack hat = new ItemStack(Material.getMaterial(args[0].toUpperCase()));


    I'm so happy now :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
Thread Status:
Not open for further replies.

Share This Page