Upload folder via GUI - src
This commit is contained in:
347
src/main/java/de/serverpulse/utils/ConfigManager.java
Normal file
347
src/main/java/de/serverpulse/utils/ConfigManager.java
Normal file
@@ -0,0 +1,347 @@
|
||||
package de.serverpulse.utils;
|
||||
|
||||
import de.serverpulse.ServerPulse;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Verwaltet alle Konfigurationsdateien von ServerPulse.
|
||||
*/
|
||||
public class ConfigManager {
|
||||
|
||||
private final ServerPulse plugin;
|
||||
private FileConfiguration config;
|
||||
|
||||
public ConfigManager(ServerPulse plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt alle Konfigurationsdateien
|
||||
*/
|
||||
public void loadAll() {
|
||||
plugin.saveDefaultConfig();
|
||||
plugin.reloadConfig();
|
||||
this.config = plugin.getConfig();
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────
|
||||
// ALLGEMEINE EINSTELLUNGEN
|
||||
// ──────────────────────────────────────────
|
||||
|
||||
public boolean isDebugMode() {
|
||||
return config.getBoolean("general.debug", false);
|
||||
}
|
||||
|
||||
public int getMetricsInterval() {
|
||||
return Math.max(10, config.getInt("general.metrics-interval", 30));
|
||||
}
|
||||
|
||||
public int getEntityInterval() {
|
||||
return Math.max(10, config.getInt("general.entity-interval", 60));
|
||||
}
|
||||
|
||||
public int getDataRetentionDays() {
|
||||
return config.getInt("general.data-retention-days", 90);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────
|
||||
// DATENBANK
|
||||
// ──────────────────────────────────────────
|
||||
|
||||
public boolean isDatabaseEnabled() {
|
||||
return config.getBoolean("database.enabled", true);
|
||||
}
|
||||
|
||||
public String getDbHost() {
|
||||
return config.getString("database.host", "localhost");
|
||||
}
|
||||
|
||||
public int getDbPort() {
|
||||
return config.getInt("database.port", 3306);
|
||||
}
|
||||
|
||||
public String getDbName() {
|
||||
return config.getString("database.database", "serverpulse");
|
||||
}
|
||||
|
||||
public String getDbUsername() {
|
||||
return config.getString("database.username", "root");
|
||||
}
|
||||
|
||||
public String getDbPassword() {
|
||||
return config.getString("database.password", "");
|
||||
}
|
||||
|
||||
public int getPoolMaxSize() {
|
||||
return config.getInt("database.pool.maximum-pool-size", 10);
|
||||
}
|
||||
|
||||
public int getPoolMinIdle() {
|
||||
return config.getInt("database.pool.minimum-idle", 2);
|
||||
}
|
||||
|
||||
public long getPoolConnectionTimeout() {
|
||||
return config.getLong("database.pool.connection-timeout", 30000);
|
||||
}
|
||||
|
||||
public long getPoolIdleTimeout() {
|
||||
return config.getLong("database.pool.idle-timeout", 600000);
|
||||
}
|
||||
|
||||
public long getPoolMaxLifetime() {
|
||||
return config.getLong("database.pool.max-lifetime", 1800000);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────
|
||||
// DISCORD
|
||||
// ──────────────────────────────────────────
|
||||
|
||||
public boolean isDiscordEnabled() {
|
||||
return config.getBoolean("discord.enabled", false);
|
||||
}
|
||||
|
||||
public String getDiscordWebhookUrl() {
|
||||
return config.getString("discord.webhook-url", "");
|
||||
}
|
||||
|
||||
public String getDiscordReportWebhookUrl() {
|
||||
String url = config.getString("discord.report-webhook-url", "");
|
||||
return (url == null || url.isEmpty()) ? getDiscordWebhookUrl() : url;
|
||||
}
|
||||
|
||||
public String getDiscordBotName() {
|
||||
return config.getString("discord.bot-name", "ServerPulse");
|
||||
}
|
||||
|
||||
public String getDiscordBotAvatar() {
|
||||
return config.getString("discord.bot-avatar", "");
|
||||
}
|
||||
|
||||
public boolean isDailyReportEnabled() {
|
||||
return config.getBoolean("discord.daily-report.enabled", true) && isDiscordEnabled();
|
||||
}
|
||||
|
||||
public String getDailyReportTime() {
|
||||
return config.getString("discord.daily-report.time", "08:00");
|
||||
}
|
||||
|
||||
public int getDiscordColorInfo() {
|
||||
return config.getInt("discord.colors.info", 3447003);
|
||||
}
|
||||
|
||||
public int getDiscordColorWarning() {
|
||||
return config.getInt("discord.colors.warning", 16776960);
|
||||
}
|
||||
|
||||
public int getDiscordColorCritical() {
|
||||
return config.getInt("discord.colors.critical", 16711680);
|
||||
}
|
||||
|
||||
public int getDiscordColorSuccess() {
|
||||
return config.getInt("discord.colors.success", 65280);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────
|
||||
// PERFORMANCE-GRENZWERTE
|
||||
// ──────────────────────────────────────────
|
||||
|
||||
public double getTpsWarning() {
|
||||
return config.getDouble("thresholds.performance.tps-warning", 18.0);
|
||||
}
|
||||
|
||||
public double getTpsCritical() {
|
||||
return config.getDouble("thresholds.performance.tps-critical", 15.0);
|
||||
}
|
||||
|
||||
public double getMsptWarning() {
|
||||
return config.getDouble("thresholds.performance.mspt-warning", 40.0);
|
||||
}
|
||||
|
||||
public double getMsptCritical() {
|
||||
return config.getDouble("thresholds.performance.mspt-critical", 50.0);
|
||||
}
|
||||
|
||||
public int getRamWarning() {
|
||||
return config.getInt("thresholds.performance.ram-warning", 75);
|
||||
}
|
||||
|
||||
public int getRamCritical() {
|
||||
return config.getInt("thresholds.performance.ram-critical", 90);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────
|
||||
// ENTITY-GRENZWERTE (global)
|
||||
// ──────────────────────────────────────────
|
||||
|
||||
public int getEntityTotalWarning() {
|
||||
return config.getInt("thresholds.entities.total-warning", 1000);
|
||||
}
|
||||
|
||||
public int getEntityTotalCritical() {
|
||||
return config.getInt("thresholds.entities.total-critical", 2000);
|
||||
}
|
||||
|
||||
public int getMonstersWarning() {
|
||||
return config.getInt("thresholds.entities.monsters-warning", 300);
|
||||
}
|
||||
|
||||
public int getMonstersCritical() {
|
||||
return config.getInt("thresholds.entities.monsters-critical", 600);
|
||||
}
|
||||
|
||||
public int getAnimalsWarning() {
|
||||
return config.getInt("thresholds.entities.animals-warning", 200);
|
||||
}
|
||||
|
||||
public int getAnimalsCritical() {
|
||||
return config.getInt("thresholds.entities.animals-critical", 400);
|
||||
}
|
||||
|
||||
public int getVillagersWarning() {
|
||||
return config.getInt("thresholds.entities.villagers-warning", 100);
|
||||
}
|
||||
|
||||
public int getVillagersCritical() {
|
||||
return config.getInt("thresholds.entities.villagers-critical", 200);
|
||||
}
|
||||
|
||||
public int getItemsWarning() {
|
||||
return config.getInt("thresholds.entities.items-warning", 150);
|
||||
}
|
||||
|
||||
public int getItemsCritical() {
|
||||
return config.getInt("thresholds.entities.items-critical", 300);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────
|
||||
// WELTBEZOGENE GRENZWERTE
|
||||
// ──────────────────────────────────────────
|
||||
|
||||
public int getWorldMonstersWarning(String worldName) {
|
||||
String path = "worlds." + worldName + ".thresholds.monsters-warning";
|
||||
return config.getInt(path, getMonstersWarning());
|
||||
}
|
||||
|
||||
public int getWorldMonstersCritical(String worldName) {
|
||||
String path = "worlds." + worldName + ".thresholds.monsters-critical";
|
||||
return config.getInt(path, getMonstersCritical());
|
||||
}
|
||||
|
||||
public int getWorldTotalWarning(String worldName) {
|
||||
String path = "worlds." + worldName + ".thresholds.total-warning";
|
||||
return config.getInt(path, getEntityTotalWarning());
|
||||
}
|
||||
|
||||
public int getWorldTotalCritical(String worldName) {
|
||||
String path = "worlds." + worldName + ".thresholds.total-critical";
|
||||
return config.getInt(path, getEntityTotalCritical());
|
||||
}
|
||||
|
||||
public String getWorldDisplayName(String worldName) {
|
||||
String path = "worlds." + worldName + ".display-name";
|
||||
return config.getString(path, worldName);
|
||||
}
|
||||
|
||||
public boolean isWorldMonitored(String worldName) {
|
||||
String path = "worlds." + worldName + ".enabled";
|
||||
// Wenn nicht explizit konfiguriert, wird die Welt standardmäßig überwacht
|
||||
return config.getBoolean(path, true);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────
|
||||
// TREND-ANALYSE
|
||||
// ──────────────────────────────────────────
|
||||
|
||||
public boolean isTrendAnalysisEnabled() {
|
||||
return config.getBoolean("trend-analysis.enabled", true);
|
||||
}
|
||||
|
||||
public int getTrendDataPoints() {
|
||||
return config.getInt("trend-analysis.data-points", 10);
|
||||
}
|
||||
|
||||
public double getTrendIncreaseThreshold() {
|
||||
return config.getDouble("trend-analysis.increase-threshold", 20.0);
|
||||
}
|
||||
|
||||
public int getTrendCheckInterval() {
|
||||
return config.getInt("trend-analysis.check-interval", 5);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────
|
||||
// NOTFALLMASSNAHMEN
|
||||
// ──────────────────────────────────────────
|
||||
|
||||
public boolean isItemClearEnabled() {
|
||||
return config.getBoolean("emergency-actions.item-clear.enabled", false);
|
||||
}
|
||||
|
||||
public boolean isItemClearBroadcast() {
|
||||
return config.getBoolean("emergency-actions.item-clear.broadcast", true);
|
||||
}
|
||||
|
||||
public String getItemClearBroadcastMessage() {
|
||||
return config.getString("emergency-actions.item-clear.broadcast-message",
|
||||
"&c[ServerPulse] Automatischer Item-Clear in {seconds} Sekunden!");
|
||||
}
|
||||
|
||||
public int getItemClearCountdown() {
|
||||
return config.getInt("emergency-actions.item-clear.countdown-seconds", 30);
|
||||
}
|
||||
|
||||
public boolean isMobClearEnabled() {
|
||||
return config.getBoolean("emergency-actions.mob-clear.enabled", false);
|
||||
}
|
||||
|
||||
public boolean isMobClearHostileOnly() {
|
||||
return config.getBoolean("emergency-actions.mob-clear.hostile-only", true);
|
||||
}
|
||||
|
||||
public boolean isAutoDiagnosisEnabled() {
|
||||
return config.getBoolean("emergency-actions.auto-diagnosis.enabled", true);
|
||||
}
|
||||
|
||||
public int getAutoDiagnosisTriggerCount() {
|
||||
return config.getInt("emergency-actions.auto-diagnosis.trigger-count", 3);
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────
|
||||
// REST API
|
||||
// ──────────────────────────────────────────
|
||||
|
||||
public boolean isRestApiEnabled() {
|
||||
return config.getBoolean("rest-api.enabled", false);
|
||||
}
|
||||
|
||||
public int getRestApiPort() {
|
||||
return config.getInt("rest-api.port", 8080);
|
||||
}
|
||||
|
||||
public String getRestApiHost() {
|
||||
return config.getString("rest-api.host", "0.0.0.0");
|
||||
}
|
||||
|
||||
public String getRestApiKey() {
|
||||
return config.getString("rest-api.api-key", "");
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────
|
||||
// NACHRICHTEN
|
||||
// ──────────────────────────────────────────
|
||||
|
||||
public String getPrefix() {
|
||||
return MessageUtil.colorize(config.getString("messages.prefix", "&8[&bServerPulse&8] &r"));
|
||||
}
|
||||
|
||||
public String getMessage(String key) {
|
||||
return MessageUtil.colorize(config.getString("messages." + key, ""));
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user