Hello to anyone reading this! I have a simple issue that I would like to solve, and if anyone could help me out it would be awesome. Basically I'm going to have a config that either looks like this: Code (YAML): players: gavinepic123: red beastman777: blue imtoolazytomakeupanothername: red or like this: Code (YAML): players: red: - gavinepic123 - imtoolazytomakeupanothername blue: - beastman777 Every time the server starts up I will use that list to assign each player to a team. I have no issue adding new players to this list, but my issue is that I need to figure out how to get each player from this list and run the code to add them to a team. If anyone could help me out, it would be awesome. If you need me to elaborate, I will be happy too. Just explain what you want me to elaborate on.
You could store all of them in a List (Set) like this: Set<String> colors = yourConfig.getConfigurationSection("players").getKeys(false); and then loop through them, and store the players in a List and do whatever Code (Java): for(String color : colors) { List<String> players = config.getStringList("yourpath." + color); //do whatever }
the method you are looking for is something like ConfigurationSection.getKeys(false). This will give you all the keys under that section so that you can do something like for(String key : myConfigSection.getKeys(false)) { myConfigSection.get(key); //do something }