Solved Iterating through FileConfiguration?

Discussion in 'Plugin Development' started by TheDiamond06, Jan 19, 2018.

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

    TheDiamond06

    The Bukkit API contains FileConfiguration#save(File) to save a FileConfiguration variable to a file. However, this deletes all '#' comments that are in this FileConfiguration?

    Does the FileConfiguration class store the entire contents of the file, including the '#' comments, or does it only store the variables?

    Assuming that it stores the '#' comments as well as the variables, a simple solution would be to mutate the FileConfiguration#save(File) in my own way. However, how would I be able to iterate through the contents of FileConfiguration?

    Assuming that it does not store the '#' comments, how would I be able to preserve these comments?
     
    Last edited: Jan 19, 2018
  2. Offline

    Zombie_Striker

  3. Offline

    TheDiamond06

  4. Offline

    Colinus999

    That's what your Title said
    Iterating through Config:
    See org.bukkit.configuration.ConfigurationSection#getKeys
    This method is inherited by FileConfiguration
    Code Snippet (open)

    Code:
    // Your config
    FileConfiguration config;
    
    // Lists all direct keys from the root config
    // You can also do this in any other ConfigurationSection instance
    for(String key : config.getKeys(false))
        System.out.println("Found key: "+key);
    
    // List every path in the config
    for(String key : config.getKeys(true))
        System.out.println("Found path: "+key);
     
    Last edited: Jan 23, 2018
Thread Status:
Not open for further replies.

Share This Page