New configuration - getMaterial?

Discussion in 'Plugin Development' started by Richard Robertson, Oct 26, 2011.

Thread Status:
Not open for further replies.
  1. I see that I can get and store ItemStacks, but what if I just wanted a material? Is there a way to do that or do I have to manually read the string for material data/id number?
     
  2. Offline

    nickrak

    ItemStack_obj.getData() returns a Material.
     
  3. I know that much, but what if I want the user to just be able to enter a material into their configuration file? That won't load as an ItemStack.

    Like this:

    Code:
    my-block: cobblestone
     
  4. Offline

    enjikaka

    Why don't you just use a the ID of the item/block?
    It will be easier 'cus of possible miss-spelling on the user-end.
     
  5. Offline

    nickrak

    I'm not really sure what you mean, the string can be turned into a Material, using Material.matchMaterial(String)
     
  6. Offline

    nickrak

    Users shouldn't need to pull out a list of material IDs to use a plugin, matchMaterial works just fine with Strings (with a few odd ones). Be nice to your users, let them use Strings.
     
  7. @nickrak @Richard Robertson
    Then use getString() and Material.matchMaterial().
     
  8. That's what I did on the old configuration system. I was just confused as to why there wasn't a way to automatically get a material.
     
  9. Offline

    Windwaker

    What's wrong with getString()?
     
  10. Offline

    md_5

    Or getInt for both data and id
     
  11. Offline

    Taien

    Code:
    public Material parseMaterialString(String s)
        {
            Material m = null;
            if (Material.getMaterial(s.toUpperCase()) != null) m = Material.getMaterial(s.toUpperCase());
            else
            {
                try
                {
                    m = Material.getMaterial(Integer.parseInt(s));
                }
                catch (NumberFormatException e)
                {
                    return null;
                }
            }
            return m;
        }
     
  12. Nothing is wrong with it. I just don't understand why material isn't considered one of the commonly stored data-types for the new configuration.
     
  13. Offline

    ItsHarry

    I guess they just didn't think of it? Maybe if you suggest the feature they will implement it
     
  14. I did suggest it during Dinnerbone's "What do you store in configuration files?"
     
Thread Status:
Not open for further replies.

Share This Page