Multiple configuration files

Is there any way to use an array of configuration files? I saw this in the plugin VirtuaChest, but I do not understand how implemented.

I want to make a GUI shop, for this I need to keep each inventory in a separate config. In this case, you need to work with an array. In the main config, you can assign configuration file IDs to the inventory.

Read this

There is also another way, the way I personally do it and thats loading the configuration from a file that you either created or copy from inside your jar

I know how to create a configuration file through the plugin code when the server starts. But I can not understand how to do this when executing a command and give the file a name by the command itself. The configuration file should work after this, and there can be many such files.

So due to the fact your creating/loading the file not on runtime. I would advise the copying the file from inside your jar to the outside (many tutorials from google. P.S the code will likely use
getResource()) and then load the configuration using the code shown in the spongedocs

1 Like

But I do not need to copy the file from jar, but create it in the process of configuring the plugin.

I dont see why you cannot create it using the snake api that is included in sponge? You can create it whenever, just create a blank file, then load it using HCon and then use the “set” method to create it and then save it.

The code to create a configuration and load it is the same code regardless of where in the plugin lifecycle it is used. Meanwhile I would strongly recommend against storing live data in configuration files. If you must use a human readable format, use JSON at least because it is far faster to read, but my recommendation would be that you use DataContainer instead of ConfigurationNode and store it via DataFormats.NBT.
Also, why do you need one file per store? Why not just have one file with a list of stores?

The file can turn out to be too large, and hence the time of its reading will be large.

The problem is not with creation, but with loading. If I am at each opening of the menu players will re-define the config, it is logical to assume that only the last menu will be active, and all the previous ones will be unloaded.