Looping through yamlConfig

Discussion in 'Plugin Development' started by ThrustLP, May 25, 2016.

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

    ThrustLP

    Hey guys I got (for example) the following config:

    Code:
    Marrys:
      b742f7a2-7588-3ebz-ae2b-229f3e41de49:
        isMarried: true
        Partner: Player2
      da8f2145-c066-33fb-937c-37f984et9c6t:
        isMarried: true
        Partner: Player1
      zu8f2145-c066-33fb-937c-37f984et9c6t:
        isMarried: false
    
    Now I want to loop through the config and get all Players that are married (isMarried=true) and their partners (Partner)

    and every loop I want to print Bukkit.braodcastMessage(p + " " + pa); <<-- p= Player pa = players Partner


    How would I do it?

    Thanks!
     
  2. Offline

    Zombie_Striker

    @ThrustLP
    1. Get the ConfigurationSection "Marrys". Do this by using Config#getConfigurationSection("Marrys")
    2. Get the keylist by using ConfigurationSection#keylist. This should return all those UUIDs.
    3. Using each uuid from the keylist, get the isMarried variable to test if the player has partner. If so, return the partner.
    Since you're using the UUIDs as part of the path to each player, I would highly recommend you store the partner's UUID instead of their name. Doing so would mean that name changes would be supported.
     
  3. Offline

    MadMaxCookie

    // so you can use it on future
    Code:
    Set<String> uuid = getConfig().getConfigurationSection("Marrys").getKeys(false);
     
    Last edited: May 25, 2016
  4. Offline

    timtower Administrator Administrator Moderator

    @MadMaxCookie Please try that, pretty sure that you are missing .getKeys(false)
     
  5. Offline

    MadMaxCookie

    @timtower oh yeah sorry for missing some code :D
     
  6. Offline

    DoggyCode™

    ConfigurationSection section = getConfig().getConfigurationSection("Marrys");
    for (String uuid : section.getKeys(false)) {
    //you can now get the is married and player
    }
     
Thread Status:
Not open for further replies.

Share This Page