Get the path in config?

Discussion in 'Plugin Development' started by adde, Jan 4, 2014.

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

    adde

    Hey!
    If I have this path in my config:
    Code:
    Test:
      test1:
        Members:
        - testmember1
      test2:
        Members:
        - testmember2
    
    How would I get the path (the test1.blabla path)?
    I want to do a command where you invite people to join the "test1", but to get what "test group" they are in, I need to get the path. It's hard to explain.

    I want to get what is in red when you do a command:
    Test:
    test1:
    Members:
    - testmember
     
  2. Offline

    valon750

    adde

    Assuming you want to check what list contains a player, you'd need to set up a for loop for the ConfigurationSections, and getting the "Members" list, for each of them.
     
  3. Offline

    adde

    How would I do this? I want to get the path to the where it says test1. Like, the path to it is "Test.test1" but how would I get it when they do a command? Check through the whole config, get the player name, remove the members tab? Done?

    Edit:

    Never mind, I used getKeys(boolean).
     
  4. Offline

    adde

    Okay, I managed to do it yesterday.. And then suddenly today when testing the code, getKeys only gets the first section below "Test"?
    Anyone?
     
  5. Offline

    Dablakbandit

    adde
    Code:java
    1. Set<String> keys = config.getKeys(false);
     
  6. Offline

    bigteddy98

    adde for every key in the section "Test", use getKeys(boolean) again, so for example, now on "test1". Then you get keys in the "test1" section (In your case, this will return "Members").
     
  7. Offline

    adde

    Already tested.

    What do you mean? If I do getConfig().getGetConfigureSection("Test").getKeys(false) in a for String loop it will still give me only the first after Test. So if I have like test2 and test3 they won't print out.
     
  8. Offline

    bigteddy98

    Well, I don't really know how to explain this... xD I am trying to say, that if you do getKeys(boolean) on "test1", it will return "members";
     
  9. Offline

    adde

    I know, but I need to check the whole "Test" (the main node)
    Code:
    Node:
      test1:
        Members:
        - testuser1
        Home:
          X: 135.97026507341664
          Y: 80.0
          Z: -63.72998146720581
          Set: false
      test2:
        Members:
        - testuser2
        Home:
          X: 135.97026507341664
          Y: 80.0
          Z: -63.72998146720581
          Set: false
    
    This is an example.
    If I do /testcommand
    I want it to print in the console with System.out.println(key);
    The code looks like:
    Code:java
    1.  
    2. for(String key : getConfig().getConfigurationSection("Node").getKeys(false))
    3. {
    4. System.out.println(key);
    5. }
    6.  

    It should print BOTH test1 AND test2. Now it only prints test1.
    If I do
    Code:
    System.out.println(getConfig().getStringList("Node." + key + ".Members");
    
    it will only print the test1 member list.

    Hope you understand what I am trying to do.
    I need it to check BOTH.
     
Thread Status:
Not open for further replies.

Share This Page