How to create nodes using configurate

I apologize in advance for a question that has undoubtedly been answered in the docs but was incomprehensible to me.

In short: How do I create more nodes in configurate?

I want to be able to save data to a file in order to store the location of arena “spawns” between server runs. By doing this my plugin should be able to store data when the server is shut down and retrieve the data when the server turns on. It is my understanding that the best way to do so is through the configurate api described on the sponge docs. If I am already in error feel free to correct me on the best way to do this.

I have successfully created the file using this tutorial. However my question is how do I create additional nodes? I have seen the method createEmptyNode(ConfigurationOptions.defaults), however when I tried this the file remained blank. how do I add nodes so that I can later set and get the data to and from them?

Thank you for your time,
-Tomas

Call getNode("newNode") to get any node. The node may be not real, it may be getVirtual() which means it wasn’t saved yet to the file. After setting a value to the node you have to save the file with your configuration loader save(...).
You can also serialize a lists and maps.

I also recommend to look at object mapping(annotations @ConfigSerialzable and @Setting) which serializes a whole class to a config file.

1 Like