-
Notifications
You must be signed in to change notification settings - Fork 5
Modifiers
ConfigAPI makes use of the transient
modifier as the Java serializer does, if the modifier is applied to the field, it is ignored in all serialization.
If @RequiredField is applied to any field and it does not exist in the config file, the API will throw InvalidConfigurationException
thus interrupting code execution.
This annotation can only be applied to String
fields. When applied, it will convert traditional & colouring in Bukkit to the colour character when loading, and when saving, it will convert all colour characters to traditional &.
This annotation can only be applied to fields which have types that have ConfigurationSection
as a superclass. If applied to a field with a type that does not meet this condition, ConfigAPI will throw a ClassStructureException
. The field this annotation is applied on may only be used once in an object.
@Self is used to modify fields of the object itself abstractly. When saving an object with a field that has this annotation:
- if the
ConfigurationSection
saved in the object contains any fields that the serialized version does not:- save them
- otherwise, ignore it
This section covers the annotations @Comment
, @Comments
, @HeaderComment
, @HeaderComments
This annotation will add a comment to the config above the field or file as a whole. Comments are only managed for the root config, otherwise, they will be ignored. HeaderComment(s) are comments for the config file as a whole. Comment(s) are for individual fields. Note that the comments are not escaped, therefore if you put \n
the ConfigAPI will add a new line.
Take the following as an example:
@HeaderComments({"Configure this special little plugin", "Made by Mazen, with love <3", ""})
public class MyConfig {
@Comment("This message is displayed when a player runs /cat")
private String message = "You have a cute cat!";
@Comments({"This is the part where it gets special",
"This is the amount of money that's taken from the player",
"when they run /cat ;)"})
private int price = 3;
}
If we were to save this with its default values, we would get this:
# Configure this special little plugin
# Made by Mazen, with love <3
#
# This message is displayed when a player runs /cat
message: 'You have a cute cat!'
# This is the part where it gets special
# This is the amount of money that's taken from the player
# when they run /cat ;)
price: 3