package com.yutian.minerwar.liveevent;

import com.io.yutian.mclive.event.LiveLikeEvents;
import com.yutian.minerwar.MinerWar;
import com.yutian.minerwar.data.LikeData;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import tools.GameUtil;
import tools.RandomUtil;

import java.util.HashMap;

public class LikeListener implements Listener {

    @EventHandler//点赞
    public void onDianZan(LiveLikeEvents e) {
        Player zhubo = e.getPlayer();
        String userName = ""+ RandomUtil.getRandomInt(999,10000);
        if(e.getUser().nickName() != null) {
            userName = e.getUser().nickName();
        }
        long add_amount = e.getCount();
        HashMap<String, LikeData> likeDataMap = MinerWar.getGameManager().getLikeDataMap();
        for (String key : likeDataMap.keySet()){
            LikeData likeData = likeDataMap.get(key);
            likeData.addNowAmount((int)add_amount);
            if(likeData.meetTheQuantityRequirement()){
                String eventName = likeData.getEffectKey();
                String title = "§c"+eventName;
                String subtitle = "§9双击屏幕x"+likeData.getNeedAmount();
                likeData.OutPlaySoundsEvent();
                zhubo.sendTitle(title, subtitle,0, 30, 10);
                GiftEventHandler.SendHandLer(zhubo,userName,eventName);
                likeData.setNowAmount(0);
            }
        }
    }
}
