getConfigurationSection

Discussion in 'Spigot Plugin Development' started by iYgoR, Apr 23, 2017.

  1. Hello, how are you? Well, I wanted to know what I do for when the player types a command (/ test for example) it come with pre-defined items in the config.
    This item will come with enchantment and name edited.
    I would like to know how to use the method "getConfig (). GetConfigurationSection (" formats "). GetKeys (false); for this I'm starting, so please send me the code.
    Sorry my bad English, I'm Brazilian.
     
  2. What are you exactly confused on? If you use getCongfigurationSection("formats).getKeys(false), then you will get a set of all the keys at the highest level of that section.

    For example, a config file which looks like this:
    Code (YAML):
    section:
        number
    : 234
        anotherNumber
    : 1453
        subsection
    :
            string
    : 'Hello World'
    anotherSection
    :
        aList
    : [entryOne, entryTwo]
        subNumber
    : 1337
    If you do getConfigurationSection("section").getKeys(false), then the string set it would return is {"number", "anotherNumber"}.


    By passing false into getKeys, getKeys will only return the highest level keys, and not look down other subsections for more keys.
     
    • Informative Informative x 1