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 = "grace-period"infection-time", description = "TheHow gracelong perioda ofplayer theshould game"be infected once hit.")
private Duration gracePeriodinfectionTime = Duration.ofMinutes(ofSeconds(5);
}
In this example, aan graceinfection periodtime option has been added which can now be pulled from the myarena.yml:
name: MyArena
mode: MyArena
type: Match
grace-period:infection-time: 3m3s
...
In this example, if no graceinfection periodtime if specified, then the default value of 5 minutesseconds 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 aan graceinfection periodtime 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.