Getting the parent from a value in config

Discussion in 'Plugin Development' started by PiggerCast, Jul 30, 2019.

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

    PiggerCast

    I'm working on a sign shop plugin, and the way I am storing the data is in a separate config file which I call with "cfgm.shopscfg"
    I have the data stored like this:
    Code:
    Shopnumber:
        Location: x, y, z
        Item: <itemname>
        Price: <price>
        Owner: <name of shop owner>
    I set it up like this with the idea that when people click the sign, it checks the location, and from that I can tell the shop number. I have made a string with x, y, z where its stored, and I have tried a code that I used on another plugin I made a while back but it doesn't seem to work the way I want it to.

    Here's my current code:
    Code:
                Block b = event.getClickedBlock();
                Player p = event.getPlayer();
                Location l = b.getLocation();
                int x = l.getBlockX();
                int y = l.getBlockY();
                int z = l.getBlockZ();
                String coords = x + "," + y + "," + z;
                String s1 = "";
                for(String parent : cfgm.shopscfg.getKeys(true))
                {
                    if(cfgm.shopscfg.getString(parent + ".Location").equals(coords))
                    {
                        s1 = parent;
                    }
                    p.sendMessage("shop number " + s1);
                }
            }
    This in my mind should work out, but I keep getting the error:
    Caused by: java.lang.NullPointerException
    at me.adddis.cash.Main.onClick(Main.java:217) ~[?:?]

    (line 217 is "if(cfgm.shopscfg.getString(parent + ".Location").equals(coords))")

    I'd love to get some help on this, as im quite new to working with config files, and am very eager to learn more.
     
    Last edited by a moderator: Jul 30, 2019
  2. Online

    timtower Administrator Administrator Moderator

    @PiggerCast Does the location value exist? Could you print the values?
     
  3. Offline

    PiggerCast

    @timtower yeah the location value exists. if I change the code to just msg me the coords it says the exact same coords as I have in the config.

    The config atm look liks this, if thats what you were asking.
    0:
    Location: 92,71,-114
    Item: GOLD_ORE
    Price: '1'
    Owner: AdddisCraft
     
Thread Status:
Not open for further replies.

Share This Page