Ajouter un élément a une liste en conf

Bonjour,
Je veux stocker des bloc de cette façon:

conf {
    blocs=[
        [
            "minecraft:air",
            "minecraft:air",
            "minecraft:air",
            "minecraft:air",
            "minecraft:air",
            "minecraft:air",
            "minecraft:air",
            "minecraft:air"
        ],
        [
            "minecraft:air",
            "minecraft:stone[variant=stone]",
            "minecraft:torch[facing=west]",
            "minecraft:stone[variant=stone]",
            "minecraft:stone[variant=stone]",
            "minecraft:stone[variant=stone]",
            "minecraft:stone[variant=andesite]",
            "minecraft:stone[variant=stone]"
        ]
    ]
}

Pour tester je fais:

List<BlockState> bloc1 = new ArrayList<>();
List<BlockState> bloc2 = new ArrayList<>();
List<List<BlockState>> liste = new ArrayList<>();

// Code

liste.add(bloc1);
liste.add(bloc2);

et je sauvegarde:

try {
    conf.getConfig().getNode("conf", "blocs").setValue(new TypeToken<List<List<BlockState>>>() {}, liste);
} catch (ObjectMappingException e) {
    e.printStackTrace();
}
conf.save();

J’arrive a récupérer ma liste de bloc de cette façon:

List<? extends List<? extends ConfigurationNode>> test = conf.getConfig().getNode("conf", "blocs").getChildrenList().stream().map(ConfigurationNode::getChildrenList).collect(Collectors.toList());

// Test:
Tool.getLogger().debug("test.get(0): " + test.get(0).toString());

Tool.getLogger().debug("test.get(0).get(1): " + test.get(0).get(0).getString());
Tool.getLogger().debug(" test.get(0).get(1): " + test.get(0).get(1).getString());

Donc jusqu’ici aucun problème.

Par contre je ne sais pas comment faire pour rajouter un élément a cette liste, comment je dois faire ?

List<BlockState> bloc2 = new ArrayList<>();
// Code
test.add(bloc3);

PS: je parle pas anglais, j’espère que les exemples seront clair, car je suis pas sur que google trad traduise bien


{Google TRAD}
Hello,
I want to store block this way:

conf {
    blocs=[
        [
            "minecraft:air",
            "minecraft:air",
            "minecraft:air",
            "minecraft:air",
            "minecraft:air",
            "minecraft:air",
            "minecraft:air",
            "minecraft:air"
        ],
        [
            "minecraft:air",
            "minecraft:stone[variant=stone]",
            "minecraft:torch[facing=west]",
            "minecraft:stone[variant=stone]",
            "minecraft:stone[variant=stone]",
            "minecraft:stone[variant=stone]",
            "minecraft:stone[variant=andesite]",
            "minecraft:stone[variant=stone]"
        ]
    ]
}

To test I do:

List<BlockState> bloc1 = new ArrayList<>();
List<BlockState> bloc2 = new ArrayList<>();
List<List<BlockState>> liste = new ArrayList<>();

// Code

liste.add(bloc1);
liste.add(bloc2);

and I backup:

try {
    conf.getConfig().getNode("conf", "blocs").setValue(new TypeToken<List<List<BlockState>>>() {}, liste);
} catch (ObjectMappingException e) {
    e.printStackTrace();
}
conf.save();

I can recover my block list this way:

List<? extends List<? extends ConfigurationNode>> test = conf.getConfig().getNode("conf", "blocs").getChildrenList().stream().map(ConfigurationNode::getChildrenList).collect(Collectors.toList());

// Test:
Tool.getLogger().debug("test.get(0): " + test.get(0).toString());

Tool.getLogger().debug("test.get(0).get(1): " + test.get(0).get(0).getString());
Tool.getLogger().debug(" test.get(0).get(1): " + test.get(0).get(1).getString());

So far no problem.

By cons I do not know how to add an item to this list, how should I do?

List<BlockState> bloc2 = new ArrayList<>();
// Code
test.add(bloc3);

Up

Personne a de réponse ?

I’m not entirely sure what you’re asking. If you want to add an item to a list in a config file, I think you can simply add an item to a List<> then call node.setValue(list) to set the new list in the config.

Edit: Also, I just looked at configurate’s ListConfigValue.putChild and it seems that you can use a path of -1 to append to a list. Something like this: listNode.getNode(-1).setValue(value)

J’ai réussi:

               try {
                @Nullable List<List<BlockState>> t = conf.getConfig().getNode("conf", "blocs").getValue(new TypeToken<List<List<BlockState>>>() {});
                t.add(bloc3);

                conf.getConfig().getNode("conf", "blocs").setValue(new TypeToken<List<List<BlockState>>>() {}, t);

            } catch (ObjectMappingException e) {
                e.printStackTrace();
            }