getKeys() from a ConfigurationSection does not works.

Discussion in 'Plugin Development' started by Uniclaw, Dec 11, 2012.

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

    Uniclaw

    Hi!

    I'm trying to acces to all keys from a configuration section, with that:
    plugin.getConfig().getConfigurationSection("---").getKeys(false);
    Problem: There is no error, but my plugin doesnt found any key! If id do:
    getConfig().getKeys(false);, he give me all the keys correctly - but how can i access too the keys from "---"?

    Greet
     
  2. Offline

    brord

    Does "---"exist in your config? (I disrecommend using it though)
     
  3. Offline

    Uniclaw

    Yes. And it's not "---" (And in the real config its not this^^)
    What i tryed:
    Code:
    System.out.println("Started");
    for(String s: plugin.getConfig().getKeys(false);){System.ou.println(s);}
    
    Output:
    Started
    key1
    key2
    ---
    etc

    And with this:
    Code:
    System.out.println("Started");
    for(String s: plugin.getConfig().getConfigurationSection("---").getKeys(false);){System.out.println(s);}
    
    Output:
    Started



    But - why?

    In my config its so:

    Code:
    otherkeys: blabla
    otherkeys: blabla
    ---:
      underkey: blabla
      underkey: blabla
     
  4. Offline

    brord

    IF im not mistaking, getConfigurationSection doesnt do that, but does this:
    Code:
    key1:
      nr1:
      nr2:
    
    So plugin.getConfig().getConfigurationSection("key1").getKeys(false); would return with nr1 and nr2.
    Could be wrong though
     
  5. Offline

    Uniclaw

    it's what i would. But its doesn't works - its return nothing..
     
  6. Offline

    gomeow

    I know that I use config section, here is an implementation I used:
    Code:
    Set<String> messageKeys = this.getConfig().getConfigurationSection("Messages").getKeys(false);
    ArrayList<String> messageValues = new ArrayList<String>();
    for(String messageKey : messageKeys) {
        messageValues.add(this.getConfig().get("Messages."+messageKey));
    }
     
  7. Offline

    Uniclaw

    I've make a thing like that, but doesnÄt works.. Here the real code:

    Code:
    System.out.println("Start");
    for(String s: plugin.getConfig().getConfigurationSection("SchematicSpawning").getKeys(false)){
    schematics.add(s);
    System.out.println(s);
    }
    Config:
    Code:
    SchematicSpawning:
      castle:
        Testing: test
    Output is just "Start"..
     
  8. Offline

    Stevenpcc

    I'm having the exact same problem. It's been doing this since 1.4.2. It seems to only find the top level keys.

    I think I've solved it. You need to save the config file to disk before the getKeys method will work as expected. I was just working off the default one because it was easier during development.

    saveDefaultConfig();

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
Thread Status:
Not open for further replies.

Share This Page