Solved Material.getMaterial(a string) not working

Discussion in 'Plugin Development' started by Shadow_tingBRO, Mar 11, 2019.

  1. Offline

    Shadow_tingBRO

    Ok, You probably realized that I just posted yesterday and this is going to be another stupid mistake like the last time.... but still.

    I am working on a buy command for a plugin, and I don't want to have to write if(playersargument == "idk wood"){ block = Material.Wood} millions of times
    (but i am going to do for all the item id's seen in the code below as they will used to get the prices from, but they are in the config so its fine ill just take half and hour and do it).

    So I found this way to use Material.getMaterial(String item) which returns the Material from the string. God that helps.... But I get a null pointer here:

    Code:
    @SuppressWarnings("deprecation")
        public int getPrice(Material m) {
            if(blockpriceExsits(m.getId())) { // ERROR ON THIS LINE
                return (int) config.get("block-id-prices." + m.getId());
            }
            return 0;
        } 
    blockpriceExsists (i cant spell) ->

    Code:
    public boolean blockpriceExsits(int blockID) {
            if(config.get("block-id-prices." + blockID) == null) {
                return false;
            }
            return true;
        }
    Do you know what Im doing wrong or my stupid mistake i probably made?
     
  2. Offline

    Eccentric_Gamer

    First of all, try Material.matchMaterial() for whatever you are doing. I think it adds more flexibility to the options and I think the other methods require the minecraft: before it, though I'm not sure.
    Feel free to look at them here: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html

    EDIT: Here's what I found on that page:
    That's how I let users enter in their own items; I didn't understand exactly what you were doing with them but I hope that helps. :D
     
  3. Offline

    Shadow_tingBRO

    Thanks that worked perfectly! :)

    But It might have been working the whole time as when i tried to test it with acacia_boat as that was the only price I had implemented, It still gave a null pointer, do you know why?
     

Share This Page