0

configuration file

This commit is contained in:
2019-08-26 19:33:16 +03:00
parent e5816809e0
commit 9625b324d5
4 changed files with 85 additions and 5 deletions

View 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;
}
}