Solved ConfigurationSection problem

Discussion in 'Plugin Development' started by sipsi133, Dec 29, 2014.

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

    sipsi133

    Lets say I have config like this:
    Code:
    Someconfig:
      A:
        something: somevalue
        somethingtwo: 
            somethingelse:
                something: value
      B:
        something: somevalue
    How I can get the "somethingelse" (Someconfig.A.somethingtwo.somethingelse)?

    I have tried following, but it throws a nullpointerexception on line 2
    Code:
    List<String> stringList = new ArrayList<String>();
    for(String strings : this.getConfig().getConfigurationSection("Someconfig.A.somethingtwo").getKeys(false)) {
    stringList.add(strings)
     
  2. This probably isn't it but on first glance somethingelse: seems to be tabbed instead of properly spaced in the config?
     
  3. Offline

    sipsi133

    @WD_MUFFINFLUFFER That was just an example config but the structure is the same as mine. They aren't tabbed in my config.
     
  4. Offline

    1Rogue

    I'm curious, how does your code magically know that there is an "A" value in there?
     
  5. Offline

    sipsi133

    @1Rogue I dont want to copy-paste my config so I made example config in the post that looks the same as my plugins config.
    My plugin saves data to config and when I load it, I need to get the string "somethingelse" (in my actual config its not "somethingelse")

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
  6. Offline

    1Rogue

    Weird, my post didn't... post.

    My point being that it looks like you have a list of things that are arbitrary when you could be using the .getKeys() on that, rather than "somethingelse" which seems to be a constant key. But if you missed the hint in the last sentence then it's this:

    • Use .getKeys() for dynamic, unknown values
    • Use .getConfigurationSection() for known values

    And work your way down the tree from there in your config. There's also a useful method for you which would be Config#getConfigSectionValue (you can copy/paste for yourself) which will convert any ConfigurationSection (or other implementation) into a Map<String, Object> for ease of use.
     
  7. Offline

    sipsi133

    SOLVED
     
    Last edited: Dec 30, 2014
Thread Status:
Not open for further replies.

Share This Page