package de.teleportsuite;

import org.bukkit.ChatColor;

public class ConfigManager {
    private final TeleportSuite plugin;

    public ConfigManager(TeleportSuite plugin) { this.plugin = plugin; }

    public boolean isBungeeEnabled() { return plugin.getConfig().getBoolean("bungee.enabled", false); }
    public String getServerName() { return plugin.getConfig().getString("bungee.server-name", "local"); }
    public int getTeleportDelay() { return plugin.getConfig().getInt("teleport.delay", 3); }
    public int getTeleportCooldown() { return plugin.getConfig().getInt("teleport.cooldown", 5); }
    public boolean cancelOnMove() { return plugin.getConfig().getBoolean("teleport.warmup-cancel-on-move", true); }
    public int getRequestTimeout() { return plugin.getConfig().getInt("teleport.request-timeout", 60); }
    public int getMaxHomes(String group) { return plugin.getConfig().getInt("homes.max-homes-" + group, 3); }
    public boolean allowPlayerWarps() { return plugin.getConfig().getBoolean("warps.allow-player-warps", false); }
    public boolean firstJoinTeleport() { return plugin.getConfig().getBoolean("spawn.first-join-teleport", true); }
    public boolean deathRespawnToSpawn() { return plugin.getConfig().getBoolean("spawn.death-respawn-to-spawn", false); }

    public String getMessage(String key) {
        String prefix = plugin.getConfig().getString("messages.prefix", "&8[&6TP&8] &r");
        String msg = plugin.getConfig().getString("messages." + key, "&cNachricht nicht gefunden: " + key);
        return ChatColor.translateAlternateColorCodes('&', prefix + msg);
    }

    public String getMessage(String key, String... replacements) {
        String msg = getMessage(key);
        for (int i = 0; i < replacements.length - 1; i += 2) {
            msg = msg.replace("{" + replacements[i] + "}", replacements[i+1]);
        }
        return msg;
    }
}
