package com.yaohun.storyline.manage;

import com.yaohun.storyline.Storyline;
import com.yaohun.storyline.quest.*;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

public class ExternalManager {

    private Storyline plugin;

    public ExternalManager(Storyline plugin) {
        this.plugin = plugin;
    }

    public void registerAll(){
        Bukkit.getConsoleSender().sendMessage("§e[主线任务] §f正在注册外部插件监听:");
        registerMythicMobsListener();
        registerCommandNpcListener();
        registerDemonSkillsListener();
        registerAuItemConvertListener();
        registerDemonHunHuanSXListener();
        registerDemonFenJieListener();
        registerWuHunJueXingListener();
        registerLevelRewardListener();
        registerDemonWarpsListener();
        registerDemonLevelsListener();


 /*       registerDemonMmKillsStatsListener();
        registerAuMorefishListener();
        registerAuOnlineRewardListener();
        registerDemonPetsListener();

        registerDemonLevelsListener();
        registerDemonIntensifyListener();
        registerDemonQuenchListener();*/
    }

    private void registerMythicMobsListener() {
        String pluginName = "MythicMobs";
        if (isPluginPresent(pluginName, "io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent")) {
            Bukkit.getPluginManager().registerEvents(new MythicMobsListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

    private void registerCommandNpcListener() {
        String pluginName = "CitizensCMD";
        if (isPluginPresent(pluginName, "me.messageofdeath.commandnpc.event.NpcInteractEvent")) {
            Bukkit.getPluginManager().registerEvents(new NpcInteractListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

    private void registerDemonSkillsListener() {
        String pluginName = "DemonSkills";
        if (isPluginPresent(pluginName, "com.yaohun.demonskills.event.SkillCastEvent")) {
            Bukkit.getPluginManager().registerEvents(new SkillCastListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

    private void registerAuItemConvertListener() {
        String pluginName = "AuItemConvert";
        if (isPluginPresent(pluginName, "com.yaohun.itemconvert.event.ItemConvertEvent")) {
            Bukkit.getPluginManager().registerEvents(new ItemConvertListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

    private void registerDemonHunHuanSXListener() {
        String pluginName = "DemonHunHuanSX";
        if (isPluginPresent(pluginName, "me.Demon.DemonHunHuanSX.Event.HhXiruEvent")) {
            Bukkit.getPluginManager().registerEvents(new HunHuanSXListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

    private void registerDemonFenJieListener() {
        String pluginName = "DemonFenJie";
        if (isPluginPresent(pluginName, "com.io.yaohun.fenjie.event.ResolveItemEvent")) {
            Bukkit.getPluginManager().registerEvents(new FenJieListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

    private void registerWuHunJueXingListener() {
        String pluginName = "WuHunJueXing";
        if (isPluginPresent(pluginName, "me.Demon.WuHunJueXing.Event.WhJueXingEvent")) {
            Bukkit.getPluginManager().registerEvents(new WuHunWakeListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

    private void registerLevelRewardListener() {
        String pluginName = "DemonLevelReward";
        if (isPluginPresent(pluginName, "me.Demon.DemonLevelReward.Event.LevelRewardReceiveEvent")) {
            Bukkit.getPluginManager().registerEvents(new LevelRewardListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }


    private void registerDemonWarpsListener() {
        String pluginName = "DemonWarps";
        if (isPluginPresent(pluginName, "me.Demon.DemonWarps.event.SendWarpEvent")) {
            Bukkit.getPluginManager().registerEvents(new WarpSendListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

    private void registerDemonLevelsListener() {
        String pluginName = "DemonLevels";
        if (isPluginPresent(pluginName, "me.Demon.DemonLevels.event.ShareExpEvent")) {
            Bukkit.getPluginManager().registerEvents(new LevelExpListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

/*    private void registerDemonMmKillsStatsListener() {
        String pluginName = "DemonMmKillsStats";
        if (isPluginPresent(pluginName, "me.Demon.DemonMmKillsStats.Event.KillsMobsStatsEvent")) {
            Bukkit.getPluginManager().registerEvents(new MythicMobsKillsStatsListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

    private void registerAuMorefishListener() {
        String pluginName = "AuMoreFish";
        if (isPluginPresent(pluginName, "com.yaohun.morefish.event.FishTopEvent")) {
            Bukkit.getPluginManager().registerEvents(new MorefishListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

    private void registerAuOnlineRewardListener() {
        String pluginName = "AuOnlineReward";
        if (isPluginPresent(pluginName, "com.yaohun.onlinereward.event.OnlineRewardEvent")) {
            Bukkit.getPluginManager().registerEvents(new OnlineRewardListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }

    private void registerDemonPetsListener() {
        String pluginName = "DemonPets";
        if (isPluginPresent(pluginName, "me.Demon.DemonPets.Event.PetsBuZhuoEvent")) {
            Bukkit.getPluginManager().registerEvents(new PetsListener(), plugin);
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §f监听器成功");
        }
    }
*/


    private boolean isPluginPresent(String pluginName, String className) {
        Plugin target = Bukkit.getPluginManager().getPlugin(pluginName);
        if (target == null) return false;
        try {
            Class.forName(className);
            return true;
        } catch (ClassNotFoundException e) {
            Bukkit.getConsoleSender().sendMessage("§7 - §f注册 §b"+pluginName+" §c但缺失类 "+className);
            return false;
        }
    }
}
