package com.yaohun.storyline.network;

import com.yaohun.gpsaddon.api.GPSAPI;
import com.yaohun.storyline.Storyline;
import com.yaohun.storyline.core.Quest;
import com.yaohun.storyline.data.PlayerData;
import com.yaohun.storyline.manage.PlayerManager;
import com.yaohun.storyline.manage.QuestManager;
import eos.moe.dragoncore.DragonCore;
import eos.moe.dragoncore.api.CoreAPI;
import eos.moe.dragoncore.api.easygui.EasyScreen;
import eos.moe.dragoncore.api.gui.event.CustomPacketEvent;
import eos.moe.dragongps.dy;
import eos.moe.dragongps.gq;
import me.Demon.DemonPlugin.DemonAPI;
import me.Demon.DemonPlugin.Util.CDTimeAPI;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class DragonChannel implements Listener {

    @EventHandler
    public void message(CustomPacketEvent e) {
        // 此处名称尽量独特,避免与其他人的插件相同导致冲突问题
        if (!"Storyline".equals(e.getIdentifier())) {
            return;
        }
        Player player = e.getPlayer();
        UUID uuid = player.getUniqueId();
        String playerName = player.getName();
        if(e.getData().contains("gps")) { // 导航
            if(CDTimeAPI.isCD(uuid,"gps_cd")){
                return;
            }
            PlayerManager playerManager = Storyline.getPlayerManager();
            PlayerData playerData = playerManager.getPlayerData(playerName);
            if(playerData == null) return;
            int questID = playerData.getCurrentQuest();
            Quest quest = QuestManager.getQuest(questID);
            if (quest != null) {
                Location location = quest.getStartingPoint();
                if(location != null) {
                    player.teleport(location.clone().add(0,1.5,0));
                }
                if(questID == 1){
                    GPSAPI.enable(player,"初到斗魂帝国");
                } else if(questID == 2){
                    GPSAPI.enable(player,"拜访村落长者");
                } else if(questID == 3){
                    GPSAPI.enable(player,"老铁匠的考验");
                } else if(questID == 4){
                    GPSAPI.enable(player,"再见老铁匠");
                } else if(questID == 5){
                    GPSAPI.enable(player,"器魂的觉醒");
                } else if(questID == 6){
                    GPSAPI.enable(player,"首次狩猎行动");
                }else if(questID == 7){
                    GPSAPI.enable(player,"唐门绝学速成");
                }else if(questID == 8){
                    GPSAPI.enable(player,"唐门绝学速成");
                }else if(questID == 9){
                    GPSAPI.enable(player,"器魂的进阶");
                }else if(questID == 10){
                    GPSAPI.enable(player,"器魂的进阶");
                }else if(questID == 11){
                    GPSAPI.enable(player,"百年灵兽讨伐");
                }else if(questID == 12){
                    GPSAPI.enable(player,"废物再利用");
                }else if(questID == 13){
                    GPSAPI.enable(player,"废物再利用");
                }else if(questID == 14){
                    GPSAPI.enable(player,"器魂进阶觉醒");
                }else if(questID == 15){
                    GPSAPI.enable(player,"器魂进阶觉醒");
                }else if(questID == 16){
                    GPSAPI.enable(player,"萌新福利官");
                }else if(questID == 17){
                    GPSAPI.enable(player,"萌新福利官");
                }else if(questID == 18){
                    GPSAPI.enable(player,"千年灵兽讨伐");
                }else if(questID == 21){
                    GPSAPI.enable(player,"唐门暗器制作");
                }else if(questID == 23){
                    GPSAPI.enable(player,"万年灵兽讨伐");
                }
                CDTimeAPI.setPlayerCD(uuid,"gps_cd",1000 * 5);
            }
        }
    }
}
