I have had a lot of trouble with configs in the past, and apparently today is no exception. All i'm trying to do is get the "Events" from the config example below. Basically I want to send the player a message containing the names of all the Events from this config. So in this case, the player should have a message containing "Test, Test2". However no matter what I try, it refuses to work. I have tried using these methods: Code (Java): List<String> events = ec.getConfig().getStringList("Events"); Code (Java): for (String key : ec.getConfig().getConfigurationSection("Events").getKeys(false)) { p.sendMessage("" + key); } Code (Text): Events: Test: - Head1 - Head2 Test2: - Head1 - Head2 They either return nothing in the player's message, or in the case of the second method, gives me a nullpointerexception. I have never been good with configs, even after reading the configuration API multiple times. If anyone can help me out, it would be much appreciated! Note: ec.getConfig() is my custom config file specifically for the "Events".
What I would probably do is something kinda like how you're doing it, but I would get the keys then get the values. Ex: Code (Text): for(String key : ec.getConfig().getConfigurationSection("Events").getKeys(true)){ if(!key.contains("."){ List<String> list = ec.getConfig().getStringList("Events."+key); //Do thing with list } }
Consider the difference between list and config section. Code (Java): List<String> List : - string1 - string2 Code (Java): Set<String> sets = //getConfigSection List: String1: value: true String2: value: false // add for loop statement for(String s : sets) { #Player.sendMessage(s); // String 1 and 2 }