Question about getChildrenList()

Hey guys,

I have a config file like this:

mobs {
    skeleton {
        damageMultiplier=1
        experience=5
        health=20
        name="Common Skeleton"
        weapon=bow
    }
    peter {
        damageMultiplier=1
        experience=5
        health=20
        name="Peter Skeleton"
        weapon=sword
    }
}
version=1

Now I want to read this config file with those code snippets:

skeleton = manager.load();
System.out.println(skeleton.getNode("mobs").getChildrenList().size());

Output is 0. Why? I’m really stucked.

Cheers

I haven’t done any testing, but it might be worth checking #hasListChildren() and/or #hasMapChildren().

From the looks of it, I am with you in that it looks right.

Here’s the doc for ConfigurationNode#getChildrenList(): https://github.com/zml2008/configurate/blob/master/configurate-core/src/main/java/ninja/leaping/configurate/ConfigurationNode.java#L322

So the reason its size is 0, is one of two things from what I can find.

  1. The value is not of a list type and therefore returns an empty list.
    ListConfigValue: https://github.com/zml2008/configurate/blob/master/configurate-core/src/main/java/ninja/leaping/configurate/ListConfigValue.java
    This is determined here: https://github.com/zml2008/configurate/blob/master/configurate-core/src/main/java/ninja/leaping/configurate/SimpleConfigurationNode.java#L457
  2. The list is actually empty.

Doesn’t really answer your question but hopefully it gives a little more information. Good luck! Will definitely keep an eye on this in-case I need this functionality in the future.

The way you could do it if you are unable to solve the issue is instead just using recursion to load the values.

EDIT: Maybe @zml can shine a little light on this?

Hey,

#hasListChildren() = false
#hasMapChildren() = true

So I will try to use the map :smiley:

1 Like

It’s because getChildrenList() is actually looking for an array such as this node

config {
    List [
        "First Item",
        "Second Item",
        "Third Item"
    ]
}
2 Likes

Hey,

yeah … blame me … Braindead … :blush: