Configs
A config will be a class that extends VitalConfig and is annotated with @VitalConfig.Info.
@VitalConfig.Info(name = "myconfig.yaml", processor = VitalYAMLConfigProcessor.class)
public class MyConfig extends VitalConfig {
}
For every config, you define the name (path to your config, relative to your server.jar file) and the processor that should be used for your config.
Vital currently supports two types of configs and provides a processor for each: YAML files and Properties files.
Based on what data you want to store and how you want to store it, you can choose the appropriate processor in your info annotation.
Storing data
To store data, simply create a new field in your config class and annotate it with @Property.
@VitalConfig.Info(name = "myconfig.yaml", processor = VitalYAMLConfigProcessor.class)
public class MyConfig extends VitalConfig {
@Property(types = {String.class})
private String myCustomString;
}
The @Property(types = Class<?>...) annotation is used to explicitly specify the type that you want to store.
Vital CAN implicitly guess the type if you omit the parameter, but generally this isn't recommended.
The annotation is especially relevant if you need to store more complex types, like a list, a map, or your own custom type.
Simply write to your field (via a setter, or directly).
If you want to save your data to your config file, simply call save().
Vital will automatically convert all of your fields annotated with @Property to a serialized object and save it to your config file.
Custom types
You can also store your own custom data types in your configs.
Simply add your custom data type to your config as a new field.
@VitalConfig.Info(name = "myconfig.yaml", processor = VitalYAMLConfigProcessor.class)
public class MyConfig extends VitalConfig {
@Property(types = {MyCustomObject.class})
private MyCustomObject myCustomObject;
}
And then make sure that your custom object type has a default constructor (a constructor without any parameters), so that Vital can create a new instance of your type when it needs to load your config.
Additionally, all fields that you also want to store in your config on your custom object need to be annotated with @Property as well.
public class MyCustomObject {
@Property(types = {String.class})
private String myCustomObjectString;
}
Note that some config types, like properties, don't support such complex data structures and can only store simple data like strings, booleans and numbers.
If you need to store more complex data, you might want to use a YAML file.