package cn.handyplus.chat.util;

import cn.handyplus.lib.util.HandyConfigUtil;
import org.bukkit.configuration.file.FileConfiguration;

import java.util.Arrays;
import java.util.Collections;

/**
 * 配置
 *
 * @author handy
 */
public class ConfigUtil {
    public static FileConfiguration CONFIG, LANG_CONFIG;
    public static FileConfiguration CHAT_CONFIG, LB_CONFIG, ITEM_CONFIG;

    /**
     * 加载全部配置
     */
    public static void init() {
        CONFIG = HandyConfigUtil.loadConfig();
        LANG_CONFIG = HandyConfigUtil.loadLangConfig(CONFIG.getString("language"), true);
        CHAT_CONFIG = HandyConfigUtil.load("chat.yml");
        LB_CONFIG = HandyConfigUtil.load("lb.yml");
        ITEM_CONFIG = HandyConfigUtil.load("gui/item.yml");
        upConfig();
    }

    /**
     * 升级节点处理
     *
     * @since 1.0.7
     */
    public static void upConfig() {
        // 1.0.7 添加聊天频率提醒
        HandyConfigUtil.setPathIsNotContains(LANG_CONFIG, "chatTime", "&7你必须等待 &a${chatTime} &7秒后 才可以继续发言.", null, "languages/" + CONFIG.getString("language") + ".yml");
        HandyConfigUtil.setPathIsNotContains(LANG_CONFIG, "itemNotFoundMsg", "&8[&c✘&8] &7展示物品超过可查看时间", null, "languages/" + CONFIG.getString("language") + ".yml");
        LANG_CONFIG = HandyConfigUtil.loadLangConfig(CONFIG.getString("language"), true);

        // 1.0.7 添加聊天频率配置和黑名单配置
        HandyConfigUtil.setPathIsNotContains(CONFIG, "blacklist", Arrays.asList("操", "草", "cao"), Collections.singletonList("黑名单,关键字替换成*"), "config.yml");
        HandyConfigUtil.setPathIsNotContains(CONFIG, "chatTime.default", 0, Collections.singletonList("聊天冷却时间(单位秒)(可无限扩展和修改子节点，权限格式: playerChat.chatTime.vip1)"), "config.yml");
        HandyConfigUtil.setPathIsNotContains(CONFIG, "chatTime.vip1", 0, null, "config.yml");
        HandyConfigUtil.setPathIsNotContains(CONFIG, "chatTime.vip2", 0, null, "config.yml");
        HandyConfigUtil.setPathIsNotContains(CONFIG, "chatTime.vip3", 0, null, "config.yml");
        CONFIG = HandyConfigUtil.load("config.yml");

        // 1.0.9 at功能
        HandyConfigUtil.setPathIsNotContains(CHAT_CONFIG, "at.enable", true, Collections.singletonList("是否开启"), "chat.yml");
        HandyConfigUtil.setPathIsNotContains(CHAT_CONFIG, "at.sound", "BLOCK_ANVIL_LAND", Collections.singletonList("音效列表 https://bukkit.windit.net/javadoc/org/bukkit/Sound.html"), "chat.yml");
        // 1.1.2 展示物品支持配置格式
        HandyConfigUtil.setPathIsNotContains(CHAT_CONFIG, "item.content", "&5[&a展示了一个 &6${item} &a点击查看&5]", Collections.singletonList("内容格式"), "chat.yml");
        CHAT_CONFIG = HandyConfigUtil.load("chat.yml");
    }

}