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;
|
||||
}
|
||||
}
|
||||
133
src/main/java/de/serverpulse/utils/MessageUtil.java
Normal file
133
src/main/java/de/serverpulse/utils/MessageUtil.java
Normal file
@@ -0,0 +1,133 @@
|
||||
package de.serverpulse.utils;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* Hilfsmethoden für Nachrichten und Formatierung.
|
||||
*/
|
||||
public class MessageUtil {
|
||||
|
||||
private static final DecimalFormat TPS_FORMAT = new DecimalFormat("##.##");
|
||||
private static final DecimalFormat MSPT_FORMAT = new DecimalFormat("##.##");
|
||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss");
|
||||
|
||||
private MessageUtil() {}
|
||||
|
||||
/**
|
||||
* Konvertiert Farb-Codes (&x) in Minecraft-Farben
|
||||
*/
|
||||
public static String colorize(String message) {
|
||||
if (message == null) return "";
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sendet eine formatierte Nachricht an einen CommandSender
|
||||
*/
|
||||
public static void send(CommandSender sender, String message) {
|
||||
sender.sendMessage(colorize(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sendet eine Nachricht mit Prefix
|
||||
*/
|
||||
public static void sendWithPrefix(CommandSender sender, String prefix, String message) {
|
||||
sender.sendMessage(colorize(prefix + message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert TPS-Wert mit Farbe
|
||||
*/
|
||||
public static String formatTps(double tps) {
|
||||
String formatted = TPS_FORMAT.format(Math.min(20.0, tps));
|
||||
if (tps >= 18.0) return "&a" + formatted;
|
||||
if (tps >= 15.0) return "&e" + formatted;
|
||||
return "&c" + formatted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert MSPT-Wert mit Farbe
|
||||
*/
|
||||
public static String formatMspt(double mspt) {
|
||||
String formatted = MSPT_FORMAT.format(mspt) + "ms";
|
||||
if (mspt <= 40.0) return "&a" + formatted;
|
||||
if (mspt <= 50.0) return "&e" + formatted;
|
||||
return "&c" + formatted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert RAM-Auslastung mit Farbe
|
||||
*/
|
||||
public static String formatRam(long usedMB, long maxMB) {
|
||||
double percent = (double) usedMB / maxMB * 100;
|
||||
String formatted = usedMB + "MB / " + maxMB + "MB (" + (int) percent + "%)";
|
||||
if (percent <= 75) return "&a" + formatted;
|
||||
if (percent <= 90) return "&e" + formatted;
|
||||
return "&c" + formatted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert einen Entity-Wert gegen einen Grenzwert
|
||||
*/
|
||||
public static String formatEntityCount(int count, int warning, int critical) {
|
||||
if (count >= critical) return "&c" + count;
|
||||
if (count >= warning) return "&e" + count;
|
||||
return "&a" + count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt eine visuelle Fortschrittsleiste
|
||||
*/
|
||||
public static String progressBar(double value, double max, int length) {
|
||||
int filled = (int) Math.round((value / max) * length);
|
||||
filled = Math.min(filled, length);
|
||||
StringBuilder bar = new StringBuilder();
|
||||
|
||||
double percent = (value / max) * 100;
|
||||
String color = percent <= 50 ? "&a" : (percent <= 75 ? "&e" : "&c");
|
||||
|
||||
bar.append(color);
|
||||
for (int i = 0; i < filled; i++) bar.append("█");
|
||||
bar.append("&7");
|
||||
for (int i = filled; i < length; i++) bar.append("░");
|
||||
|
||||
return colorize(bar.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt aktuellen Timestamp zurück
|
||||
*/
|
||||
public static String getTimestamp() {
|
||||
return LocalDateTime.now().format(DATE_FORMAT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatiert Bytes in lesbare Einheiten
|
||||
*/
|
||||
public static String formatBytes(long bytes) {
|
||||
if (bytes < 1024) return bytes + " B";
|
||||
if (bytes < 1024 * 1024) return String.format("%.1f KB", bytes / 1024.0);
|
||||
if (bytes < 1024 * 1024 * 1024) return String.format("%.1f MB", bytes / (1024.0 * 1024));
|
||||
return String.format("%.2f GB", bytes / (1024.0 * 1024 * 1024));
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt eine Trennlinie
|
||||
*/
|
||||
public static String separator() {
|
||||
return colorize("&8&m" + "─".repeat(50));
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt einen Header
|
||||
*/
|
||||
public static String header(String title) {
|
||||
int padding = (48 - title.length()) / 2;
|
||||
return colorize("&8&m" + "─".repeat(padding) + "&r &b" + title + " &8&m" + "─".repeat(padding));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user