How can I get only the direct children nodes for a config node?

I’m making a plugin that needs to be able to have potion effects when items are used that users can configure. The best way I figured out to load this information was in a Map<String, List<Map<PotionEffectType, int[]>>>. I know this will work, but I can’t get every item or effect node without including their children.

For example, the config is formatted like this:

Effects: { "minecraft:golden_apple": { "minecraft:absorbtion": { amplifier: 1 duration: 6000 } "minecraft:regeneration": { amplifier: 2 duration: 100 } } }

So initially I only want to know that “minecraft:golden_apple” is included, and then I only want to know that it has the effects “minecraft:absorbtion” and “minecraft:regeneration”, but it will give me “{minecraft:golden_apple{minecraft:absorbtion{amplifer, duration}}}”.

First of all, replace <> with &lt;&gt; in your post because otherwise they’re interpreted as HTML markup, and the full generic isn’t visible.
Second, I’m not sure what the problem here is. You have data; you then get the data. What prevents you from getting the key of the data and ignoring the rest?
Third, a much better format to store directly would be a Map<ItemType, PotionEffect>. Cuts out 100% of the middleman, including whatever your problem was.

Well I need to be able to have the amplifier and duration of the potion effect stored in the config which is why I am using Map<String, List<Map<PotionEffectType, int[]>>>. I’m not sure how else I am supposed to do that. I want the config to be readable and editable by a human.

And I can’t just get every individual node because I don’t know what exactly is going to be included in the config. I don’t know how to ignore the rest of the data.

Maybe I am approaching this the wrong way. How would you get the items and effects from config?

I tried some stuff and I can’t just put a potion effect into the configuration anyway, it says that Configuration does not accept PotionEffect objects.

Something along the lines of this should work with Configurate:

public class EffectConfig {
    public List<ItemEffectConfig> itemConfigs;

public class ItemEffectConfig {
  public ItemType itemType;
  public List<PotionEffect> effects;  

It would change out how the whole structure looks, but it’s far easier to read and structurally sound, let alone that it takes advantage of existing serialization stuff provided by Sponge’s implementations.

I figured out how to save potion effects to config because I’m an idiot, and with gabizou’s suggestion I now have this in my config:

Effects { itemType="minecraft:golden_apple" potion-effects { Ambiance=false Amplifier=0 ContentVersion=1 Duration=6000 PotionType="effect.absorption" ShowsParticles=false } }
But I’m not sure what to do after setting up those classes as gabizou showed (I know the effects aren’t in a list as well).

Annotate any classes like that with @ConfigSerializable, and then call getValue() on the root node with a TypeToken<EffectConfig>. My way of doing it would be slightly different:

public class Config {
    @Setting public Map<ItemType, List<PotionEffect>> effects;

Saves some effort and nearly uses the original structure.

By the way, the reason it didn’t work the first time was because you didn’t use a TypeToken.

Edit: And, after rereading your post, to fully answer your original question:

Map<Object, ? extends ConfigurationNode> map = node.getMapChildren();

The primary reason why I avoided a flat Map was so that you can show how custom objects can be created simply, and if in the future some additions need to be made, it’s already expandable.