Configuration
Configuration is a key part of plugins; they allow the user to customize messages, behaviour, or even make their own mechanics. Of course, since configuration is such a vital part of plugin development, like everything else, Quartz provides first-class support for it.
Configuration should always be stateless; there are no exceptions.
Since configuration is stateless, there must be a no-args constructor in the class annotated with @Configuration.
Let’s create a simple Config class:
@Configuration("cool")public class Config { @ConfigurationValue("join") public String join = "<player> has joined!";}Now let’s use it:
final Config config = ConfigLoader.load(Config.class, FileExtension.YML);
EventNode.global().addListener(PlayerJoinEvent.class, event -> { final Player player = event.getPlayer(); event.joinMessage(MiniMessage.miniMessage().deserialize(config.join, TagResolver.resolver("player", Tag.selfClosingInserting(player.displayName())))); });Just like that, we have created a simple config for our plugin.
@ConfigurationValue puts the given name in the configuration file.
However, if the name contains any .s, the path will become nested in the
file. For example:
@Configuration("cool")public class Config { @ConfigurationValue("messages.join") public String join = "<player> has joined!";}In the configuration file, assuming it is using YAML, it turns into this:
messages: join: "<player> has joined!"If
EventNodeis an unfamiliar concept, please refer to Events.