configuration file
This commit is contained in:
63
src/main/java/ru/dmitriymx/minecraft/globalchat/Config.java
Normal file
63
src/main/java/ru/dmitriymx/minecraft/globalchat/Config.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package ru.dmitriymx.minecraft.globalchat;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
@AllArgsConstructor
|
||||
class Config {
|
||||
|
||||
private JavaPlugin plugin;
|
||||
private FileConfiguration config;
|
||||
|
||||
String getHosts() {
|
||||
String hosts;
|
||||
List<String> hostList = config.getStringList("kafka.hosts");
|
||||
if (hostList.size() == 0) {
|
||||
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
|
||||
throw new RuntimeException("Empty field 'kafka.hosts'!");
|
||||
} else if (hostList.size() == 1) {
|
||||
hosts = hostList.get(0);
|
||||
} else {
|
||||
StringJoiner sj = new StringJoiner(",");
|
||||
hostList.forEach(sj::add);
|
||||
hosts = sj.toString();
|
||||
}
|
||||
|
||||
return hosts;
|
||||
}
|
||||
|
||||
String getTopic() {
|
||||
String topic = config.getString("kafka.topic");
|
||||
if (topic == null || topic.trim().isEmpty()) {
|
||||
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
|
||||
throw new RuntimeException("Empty field 'kafka.topic'!");
|
||||
}
|
||||
|
||||
return topic;
|
||||
}
|
||||
|
||||
long getDuration() {
|
||||
long duration = config.getLong("kafka.duration");
|
||||
if (duration == 0L) {
|
||||
plugin.getLogger().warning("Field 'kafka.duration' is verry low. Set default value 1000.");
|
||||
duration = 1000L;
|
||||
}
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
||||
String getFormat() {
|
||||
String format = config.getString("message_format");
|
||||
if (format.trim().isEmpty()) {
|
||||
plugin.getLogger().warning("Field 'message_format' is empty. Set default value '{0}: {1}'.");
|
||||
format = "{0}: {1}";
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user