Getting all values from a path

Discussion in 'Plugin Development' started by Tamir, Apr 29, 2015.

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

    Tamir

    Hi everyone.
    So I have a config path, and I want to get (and prob set) every value there, like get the whole thing
    For instance:
    Code:
    Players:
       Ninjas:
           Tamir: 3
           Notch: 5
    So I want to set "Tamir" and "Notch". How do I do that?
    I also need to get every value of it, for instance:
    Code:
    getConfig().set(getConfig().getInt("Tamir") + 1));
    but I need it in this method, for every single thing that "Ninjas" contain.
    Thanks in advance.
     
  2. Loop through the "Players.Ninjas" ConfigurationSection:
    Code:java
    1. for (String key : getConfig().getConfigurationSection("Players.Ninjas").getKeys(false)) {
    2.  
    3. }

    The String key will be everything under "Players.Ninjas".
    If you want to get the value of it, use:
    Code:java
    1. int example = getConfig().getInt("Players.Ninjas." + key);
     
  3. Offline

    timtower Administrator Administrator Moderator

    To all.
    Keep it nice, keep it on topic, keep it relevant.
     
  4. Offline

    Tamir

    @FisheyLP Thanks, I'll try.

    EDIT: @FisheyLP I tried something but it seems to not be working
    Code:
                              getConfig().set("Players.Ninjas." + key, getConfig().getInt("Players.Ninjas." + key) + 1);
    
    EDIT2: Sorry, forgot to save config, works fine, thanks :D
     
    Last edited: Apr 29, 2015
    timtower likes this.
  5. What do you mean? There was only one answer by me and no offtopic things .. ?
     
  6. Offline

    timtower Administrator Administrator Moderator

    Removed some posts before I posted that.
    Nothing wrong with your post.
     
  7. Offline

    Tamir

    @timtower Can you lock the thread for no necro please?
     
  8. Offline

    timtower Administrator Administrator Moderator

    @Tamir Will happen on its own when that time is reached.
     
Thread Status:
Not open for further replies.

Share This Page