Solved Get a list of objects from config

Discussion in 'Spigot Plugin Development' started by joeleoli, May 12, 2016.

  1. my config.yml:
    Code (Text):
    groups:
      admin:
        permissions:
        - admin.permission
        - admin.ban
        what:
        - admin.hi
        - admin.test
    users:
      c5b5fe6c-4abb-4c21-9093-fa7c640a3955:
        group: admin
     
    my getGroupList method:
    Code (Text):
        public static List<?> getGroupList() {
            ConfigurationSection section = getConfig().getConfigurationSection("groups");
            Set<String> keys = section.getKeys(true);
            List<String> groupList = new ArrayList<String>();
           
            for(String key : keys) {
                groupList.add(key);
            }
           
            Bukkit.getServer().getLogger().severe("done finding groups - found: " + groupList.size());
           
            return groupList;
        }
    I need this to return a List<String> and need it to list all of the groups (only group in config is admin), but I've tried several ways (get the config section and get each keys but it gets ALL keys in the whole section, so it included "permissions" and "what"), (trying to getList() the path but it just returns null).

    Any help appreciated. thanks.
     
  2. It is including all keys because you have passed true to the 'deep' parameter on getKeys() which includes everything below the keys as well. Try getKeys(false).
     
    • Agree Agree x 1