Help with config thing? (I dunno how to word it)

Discussion in 'Plugin Development' started by PluginStudios, Jun 16, 2014.

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

    PluginStudios

    Hi Bukkit. This may sound nooby, but I need help. I really dont know how to say this, so I will just show you.

    This involves configs. So basically lets say I have a Create-Your-Own-Gui plugin. In the config, I want people to be able to have as many guis as you want. So, the config comes like this:
    '0':
    thing_here
    '1':
    Thing_here

    Say somebody wants more than 2. So they add it. How do I handle every single one, like how do I know how many guis I actually need to create?

    I hope that made sense?
     
  2. Offline

    mythbusterma

    Use JavaPlugin#getConfig().getKeys(false) to return a list of the keys in the config file, for example:

    1: something
    2: something

    Would be a list containing 1 and 2 as strings.
     
  3. Offline

    cs475x

    Put all of your keys under a single key ("guis" for example), and then do something like this:
    Code:java
    1. for (String key : getConfig().getConfigurationSection("guis").getKeys(false)) {
    2. ConfigurationSection gui = getConfig().getConfigurationSection("guis." + key);
    3. // Add GUI handling here
    4. }
     
  4. Offline

    mythbusterma


    You don't need a parent key, as FileConfiguration implements ConfigurationSection and therefore has a method getKeys(boolean).
     
  5. Offline

    cs475x

    True, but I always assume that there will be other settings in the config.yml, so to ignore those you would put them under a parent key.
     
    mythbusterma likes this.
  6. Offline

    PluginStudios

    Im confused..
    mythbusterma so getKeys(false) returns the list, should I use substring to split the string and find the last number, then create that number of guis?
     
  7. Offline

    unrealdesign

    PluginStudios


    FileConfiguration#getConfigurationSection(String s).getKeys(boolean b)
    If b is true, then it selects all strings that are children of the selected section and all their children.
    if b is false, then it selects just the children of the given configuration section.

    EX --

    Config file
    Code:java
    1. Tree:
    2. Of:
    3. Stuff:
    4. One:
    5. Two:
    6. Three:
    7. Other:
    8. Ha:
    9. Haha:


    Code:java
    1. FileConfiguration#getConfigurationSection("Of").getKeys(true)

    would return a Set<String> with values: "Stuff", "One", "Two", "Three", "Other", "Ha", and "Haha".

    Code:java
    1. FileConfiguration#getConfigurationSection("Of").getKeys(false)

    would return a Set<String> with values: "Stuff" and "Other".
     
    mythbusterma likes this.
  8. Offline

    mythbusterma

    Good point, I always make a couple separate configs for things like this.
     
Thread Status:
Not open for further replies.

Share This Page