Get the file of config and make an iterator of it?

Discussion in 'Plugin Development' started by FTWin01Gurl, Feb 8, 2013.

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

    FTWin01Gurl

    I'm trying to make a plugin in which during onEnable, I want to iterate through a file. However, I've used FileConfiguration with this.getConfig() but I can't find a get file method anywhere. How would I do that and make an iterator instance of it?
     
  2. Offline

    RealDope

    You want to iterate through all the keys? Use getConfig().getKeys(boolean);
    The boolean is whether or not the set is recursive (does it contain keys under keys)
     
    FTWin01Gurl likes this.
  3. Offline

    FTWin01Gurl

    Thank you RealDope! I did not know about .getKeys() nor I have ever used it.
     
    RealDope likes this.
  4. Offline

    RainoBoy97

    If you want to, lets say get all players from config, and their nick name and save to a HashMap you would do this:
    Code:
    HashMap<String, String> nicks = new HashMap<>();
    for(String key : getConfig().getKeys(false)){
      nicks.put(key, getConfig().getString(key));
    }
    
    I think this should work :)
     
Thread Status:
Not open for further replies.

Share This Page