70 lines
1.6 KiB
Java
70 lines
1.6 KiB
Java
package cc.fascinated.config;
|
|
|
|
import cc.fascinated.Aetheria;
|
|
import lombok.Getter;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
@Getter
|
|
public enum Config {
|
|
|
|
INFLUXDB_URL("influxdb.url"),
|
|
INFLUXDB_TOKEN("influxdb.token"),
|
|
INFLUXDB_ORG("influxdb.org"),
|
|
INFLUXDB_BUCKET("influxdb.bucket");
|
|
|
|
/**
|
|
* The path of the lang in the lang.yml file.
|
|
*/
|
|
private final String path;
|
|
|
|
Config(String path) {
|
|
this.path = path;
|
|
}
|
|
|
|
/**
|
|
* Cache of the config values.
|
|
*/
|
|
private final HashMap<String, Object> cache = new HashMap<>();
|
|
|
|
/**
|
|
* The configuration.
|
|
*/
|
|
private final cc.fascinated.utils.io.Config config = new cc.fascinated.utils.io.Config(Aetheria.INSTANCE, "config.yml", null);
|
|
|
|
/**
|
|
* Gets as an object.
|
|
*
|
|
* @return the string
|
|
*/
|
|
public Object get() {
|
|
return cache.computeIfAbsent(path, key -> {
|
|
FileConfiguration configuration = config.getFileConfiguration();
|
|
if (configuration.get(path) == null) {
|
|
throw new IllegalArgumentException("Path " + path + " does not exist in the config.yml file.");
|
|
}
|
|
return configuration.get(path);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Gets as a string.
|
|
*
|
|
* @return the string
|
|
*/
|
|
public String getAsString() {
|
|
return (String) get();
|
|
}
|
|
|
|
/**
|
|
* Gets as a string list.
|
|
*
|
|
* @return the string list
|
|
*/
|
|
public List<String> getAsStringList() {
|
|
return (List<String>) get();
|
|
}
|
|
}
|