Loop through Configuration Section

Discussion in 'Spigot Plugin Development' started by Kiwanga, Apr 29, 2017.

  1. So I am trying to loop through a ConfigurationSection like this:
    Code (Text):
        public static ArrayList<String> getNicknames() {
            ArrayList<String> list = new ArrayList<>();
            ConfigurationSection section = plugin.getConfig().getConfigurationSection("nicknames");
            Set<String> nicks = section.getKeys(false);
            for (String s: nicks) {
            return list;
    //also tried just: for (String s : section.getKeys(false))
    And my Config looks like this:
    Code (Text):
        nick: '&6Test'
        perm: nick.use.test
        item: 1:0
        nick: '&cTest'
        perm: nick.use.test2
        item: 3:0
    And my debugmessage in the first code also sends "true" -> section.contains "test"
    But if i want to get the size of the arraylist it says 0 but it should be 2...

    Thank you
  2. Hey,

    Instead of for (String s :nicks) do
    for (String s : section.getString("nick"))

    This should work
    • Agree Agree x 1