package com.bitnix.dirtcryptostore.util;

import com.bitnix.dirtcryptostore.DirtCryptoStorePlugin;
import org.bukkit.command.CommandSender;

public final class MessageUtil {

    private MessageUtil() {
    }

    public static void send(DirtCryptoStorePlugin plugin, CommandSender sender, String path, String fallback) {
        String prefix = plugin.getConfig().getString("messages.prefix", "&8[&6DirtCryptoStore&8] ");
        String message = plugin.getConfig().getString(path, fallback);
        sender.sendMessage(ColorUtil.color(prefix + message));
    }

    public static void send(DirtCryptoStorePlugin plugin, CommandSender sender, String path, String fallback, String... replacements) {
        String prefix = plugin.getConfig().getString("messages.prefix", "&8[&6DirtCryptoStore&8] ");
        String message = plugin.getConfig().getString(path, fallback);

        if (replacements != null) {
            for (int i = 0; i + 1 < replacements.length; i += 2) {
                String key = replacements[i];
                String value = replacements[i + 1];
                message = message.replace(key, ColorUtil.color(value));
            }
        }

        sender.sendMessage(ColorUtil.color(prefix + message));
    }
}
