Configuration Library
| GitHub |
The Configuration Library is an assorted mix of classes and tools to make it easier to work with Configurate. This is by no means a fully fleshed-out library, but has been helpful nonetheless.
This was one of the initial libraries in TeslaLibs and added by Simon_Flash.
ConfigHolder
The ConfigHolder
[link] class is a wrapper around a ConfigurationLoader
and it’s root ConfigurationNode
. A ConfigHolder
can be created with the following.
Path path;
HoconConfigurationLoader loader = HoconConfigurationLoader.builder().setPath(path).build();
try {
ConfigHolder<CommentedConfigurationNode> config = ConfigHolder.of(loader);
} catch (IOException e) {
//an exception occurred reading/parsing the configuration file
}
ConfigurationNodeException
In many cases, Configurate’s ObjectMappingException
doesn’t quite cut it - you want to know exactly what node caused an error so you can report it to the user. In these cases, the ConfigurationNodeException
[link] contains a ConfigurationNode
for when these cases occur, and because it extends ObjectMappingException
it can be thrown inside a TypeSerializer
. There are times however when it becomes useful to throw this as an unchecked exception, and the methods ConfigurationNodeException#asUnchecked
and ConfigurationNodeException.Unchecked#getCause()
can be used to convert between the two.
NodeUtils
This utility class contains a number of methods that contain relatively simple (but useful) functions for working with ConfigurationNodes
. The majority of the methods are made clear from the code and Javadocs, but some highlights include #ifAttached
, #ifVirtual
, #getOrDefault
, #copy
, and #tryComment
.