Solved Material form Config doesnt work

Discussion in 'Plugin Development' started by Ganga, Jan 10, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Ganga

    Hey guys! I have a question again :D

    I solved the problem with saving blocks to a config! Thx to those helpers first of all.

    My new problem is:

    When I save the Type.toString() of a Block to my Config everything seems to work fine.

    Code:
    getConfig().set("BlockLocations." + manyblocks+ ".type", event.getBlock().getType().toString());
    My new value in the config:
    Code:
     type: BOOKSHELF
    This works.

    But now I try to set the block from the config:
    Code:
    Material mat = Material.getMaterial(getConfig().getString("BlockLocations." + manyblocks+ ".type"));
            targetLoc0.getBlock().setType(mat);
    What the heck am I doing wrong that a NullPointerException in my console appears? [sheep]

    Thanks for any suggestions! :rolleyes:
     
  2. Offline

    ColaCraft

    You are trying to set a Material from a String, which is making "mat" null.
     
    Ganga likes this.
  3. Offline

    Ganga

    HAHA I solved it :)
    It works you only need to convert it to a string again!

    For other users:

    CHANGE IT TO:
    Code:
            Material mat = Material.getMaterial((getConfig().getString("BlockLocations." + manyblocks+ ".type").toString()));
            targetLoc0.getBlock().setType(mat);
     
Thread Status:
Not open for further replies.

Share This Page