|
|
|
# BungeeUtilisals API #
|
|
|
|
The new BungeeUtilisals has been designed to be highly configurable & to have a good, easy-to-use API.
|
|
|
|
|
|
|
|
Unlike most of my projects, BungeeUtilisals has a fairly high documentation (at least the API does).
|
|
|
|
[For documentation you can check out our javadoc!](https://docs.dbsoftwares.eu/BungeeUtilisals/)
|
|
|
|
|
|
|
|
## Table of content: ##
|
|
|
|
* [How to create a BossBar](#how-to-create-a-bossbar)
|
|
|
|
* [Configuration API](#configuration-api)
|
|
|
|
|
|
|
|
## How to create a BossBar ##
|
|
|
|
For all IBossBar methods, please check [our Javadoc](https://docs.dbsoftwares.eu/BungeeUtilisals/com/dbsoftwares/bungeeutilisals/api/bossbar/IBossBar.html).
|
|
|
|
```java
|
|
|
|
BUAPI api = BUCore.getApi();
|
|
|
|
|
|
|
|
// Creating BossBar: api.createBossBar(BarColor color, BarStyle style, float progress, BaseComponent[] message)
|
|
|
|
IBossBar bossBar = api.createBossBar(BarColor.YELLOW, BarStyle.SOLID, 0.0F, Utils.format("&aExample Message ..."));
|
|
|
|
|
|
|
|
// Adding all online users | this basically broadcasts the BossBar
|
|
|
|
api.getUsers().forEach(bossBar::addUser);
|
|
|
|
```
|
|
|
|
|
|
|
|
**IMPORTANT:**
|
|
|
|
If a Bossbar instance is not being used, then **unregister the bossbar**!
|
|
|
|
The Bossbar API registers a EventExecutor for every BossBar instance, so that on user unload, the user gets removed from the BossBar (to prevent memory leaks).
|
|
|
|
In order to unregister the eventexecutor, the following code should be executed:
|
|
|
|
```java
|
|
|
|
bossBar.unregister();
|
|
|
|
```
|
|
|
|
## Configuration API ##
|
|
|
|
The Bukkit Configuration API is a very useful & easy to use API for YML files. Sadly enough it didn't exist for JSON, so you still had to use libraries such as Gson for this.
|
|
|
|
|
|
|
|
Which is why the BungeeUtilisals Configuration API was made, you can use both YML & JSON with this API.
|
|
|
|
|
|
|
|
For all Configuration methods, please check [our Javadoc](https://docs.dbsoftwares.eu/BungeeUtilisals/com/dbsoftwares/bungeeutilisals/api/configuration/package-summary.html).
|
|
|
|
|
|
|
|
**Example Configuration Usage:**<br />
|
|
|
|
JSON:
|
|
|
|
```java
|
|
|
|
// Creating new configuration instance
|
|
|
|
IConfiguration jsonExample = IConfiguration.loadJsonConfiguration(new File(getDataFolder(), "jsonExample.json"));
|
|
|
|
|
|
|
|
// Loading configuration defaults from plugin resources
|
|
|
|
try {
|
|
|
|
jsonExample.copyDefaults(IConfiguration.loadJsonConfiguration(getResourceAsStream("jsonExample.json")));
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Could not load configuration defaults: ");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a String from the config
|
|
|
|
String test = jsonExample.getString("test");
|
|
|
|
|
|
|
|
// Set a value in the config
|
|
|
|
jsonExample.set("test.test2", 16);
|
|
|
|
|
|
|
|
// Save the config
|
|
|
|
try {
|
|
|
|
jsonExample.save();
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Could not save configuration: ");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reload config (for when something manually got changed in the configuration)
|
|
|
|
// Reloading is NOT REQUIRED AFTER SAVING
|
|
|
|
try {
|
|
|
|
jsonExample.reload();
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Could not reload configuration: ");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
YAML:
|
|
|
|
```java
|
|
|
|
// Creating new configuration instance
|
|
|
|
IConfiguration yamlExample = IConfiguration.loadYamlConfiguration(new File(getDataFolder(), "yamlExample.yml"));
|
|
|
|
|
|
|
|
// Loading configuration defaults from plugin resources
|
|
|
|
try {
|
|
|
|
yamlExample.copyDefaults(IConfiguration.loadYamlConfiguration(getResourceAsStream("yamlExample.yml")));
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Could not load configuration defaults: ");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a String from the config
|
|
|
|
String test = yamlExample.getString("test");
|
|
|
|
|
|
|
|
// Set a value in the config
|
|
|
|
yamlExample.set("test.test2", 16);
|
|
|
|
|
|
|
|
// Save the config
|
|
|
|
try {
|
|
|
|
yamlExample.save();
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Could not save configuration: ");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reload config (for when something manually got changed in the configuration)
|
|
|
|
// Reloading is NOT REQUIRED AFTER SAVING
|
|
|
|
try {
|
|
|
|
yamlExample.reload();
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Could not reload configuration: ");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
``` |
|
|
|
\ No newline at end of file |