How to get configuration section on Sponge

Hello, I’m new on Sponge and I need to the same think here with a configuration file like using getConfigurationSection on spigot. Here is an example:

test{
“text1” {
balance= 0
}
"text2 {
balance= 10
}
“text3” {
balance= 20
}
}

how I can get a list with [text1, text2, text3] ?


ConfigurationNode root;
List<String> childrenKeys = root.childrenMap().keySet().stream().map(nodeKey -> nodeKey.toString()).collect(Collectors.toList());

why this works

First your getting the configuration nodes that are a child of root as well as the key name, your then getting the key set of them, your then streaming over them getting the key of that child name and then streaming them into a list.

If you wanted to, you could use this same technique to create a map of the key with the balance like so

Map<String, Double> balances = root.childrenMap().entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue().node("balance").getDouble());
1 Like