Getting material / type / block / itemstack from config??

Discussion in 'Spigot Plugin Development' started by NaJated, May 3, 2015.

Thread Status:
Not open for further replies.
  1. Hey all, I have no clue what I'm supposed to loop for in the config. Do I get a material from a string or what idk.

    I have tried this:

    Code (Text):
                    for (String mats : getConfig().getStringList("items"))  {
                        if (e.getClickedBlock().getType().equals(mats)) {
    Doesn't work XD thx :D
  2. gigosaurus


    Your .equals is comparing a Material with a string, so naturally will always return false.
    Code (Java):
    if (e.getClickedBlock().getType().name().equals(mats)) {
    Would be better, but even then it'll still only match the names bukkit gives them, and i'm assuming you are actually storing a material name in the config.
    Vault has a class that contains each material and all their commonly called names. That might be of use to you.

    If you're not storing material names in the config, would you mind showing your config?
    #2 gigosaurus, May 3, 2015
    Last edited: May 3, 2015
  3. I'm using a config to check if they're breaking a specified block.


    - STONE
    - COAL_ORE

    EDIT: Couldn't I just use toString() ?
  4. gigosaurus


    Yeah so if the config only contains names of items like how they are defined in bukkit (STONE, COAL_ORE, SULPHUR, not "stone", "coal ore" or "gunpowder") then the code I provided will do the job (I edited it since you last saw it because I got the wrong method name).
  5. I edited mine to and mine works too :) Thanks <3
Thread Status:
Not open for further replies.