Solved get the string below a string

Discussion in 'Plugin Development' started by Lucien2406, Jul 30, 2014.

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

    Lucien2406

    Hello.

    In my test file, I have:
    Code:
    random:
      randomword:
        uuid: random uuid
      randword:
        uuid: random uuid
      world:
        uuid: random uuid
      tree:
        uuid: random uuid
     
    ...
    And I want to get all uuids's string without getting their parent string ...

    Like:
    Code:java
    1.  
    2. String s = getConfig().getString("random");
    3.  
    4. for (int i = 0; i < s ~ size /* how to get the size ? */ ;i++){
    5.  
    6. s.getBelow(i); // if i = 0, return randomword, if 1 return randword etc...
    7. // then + ".uuids" etc I know how to
    8. }
    9.  

    I don't want to pass by a List<String> ...


    An idea ?


    Sorry if my english isn't very good.
     
  2. Offline

    Stealth2800

    If you want to iterate over all of the UUIDs in that YAML snippet, you could do something like this:
    Code:java
    1. FileConfiguration config = getConfig().getConfigurationSection("random");
    2. for (String key : config.getKeys(false)) { // This will be 'randomword', 'randword', 'world', 'tree' in the YAML snippet you posted
    3. String rawUuid = config.getString(key + ".uuid");
    4. // Do whatever with the UUID
    5. }
     
    Lucien2406 likes this.
  3. Offline

    Lucien2406

    It works thanks !

    small correction:

    Code:java
    1. FileConfiguration config = getConfig().getConfigurationSection("random");

    become
    Code:java
    1. ConfigurationSection config = getConfig().getConfigurationSection("random");
     
  4. Offline

    Stealth2800

    Lucien2406 Glad to help! And ah, yes, you're correct. I had it as 'FileConfiguration config = getConfig()' but changed it and forgot to change FileConfiguration to ConfigurationSection, but you figured it out. :)
     
Thread Status:
Not open for further replies.

Share This Page