Adding Configurable Values to Your Arena
Now that you have a custom Arena instance and a corresponding YML file, you are now ready to add some configurable options to your game!
The Configuration System - in a nutshell
One of the main features BattleArena includes a fully custom configuration system. This allows for very easy loading of data from config files. The Arena instance and YML file go hand-in-hand, so adding configurable options is very simple.
@ArenaOption annotation
This is an annotation that lets you load a value from the config. It has the following options
- name: The name of the option
- description: The description of the option
- required: Whether the option is required to be specified
- contextProvider: A provider to allow for more complex loading of an option (this option is covered in a more advanced page)
MyArena example
public class MyArena extends Arena {
@ArenaOption(name = "infection-time", description = "How long a player should be infected once hit.")
private Duration infectionTime = Duration.ofSeconds(5);
}
In this example, an infection time option has been added which can now be pulled from the myarena.yml:
name: MyArena
mode: MyArena
type: Match
infection-time: 3s
...
In this example, if no infection time if specified, then the default value of 5 seconds will be used as set in the code. However, if a config value with the same name from the ArenaOption is set, it will override the default value. In the case that a value should be required in order to load the arena, the required option can be set in the ArenaOption annotation.
On its own, this game will still do nothing. While we have an infection time option set that if referenced, will pull from the corresponding arena YML, we don't have any game logic. Before we dive into that, the next page in this tutorial will discuss the event system which is the heart of BattleArena and how you will deal with the vast majority of your game logic.