package com.yaohun.demonskills.component.effects;

import com.yaohun.demonskills.SkillsMain;
import com.yaohun.demonskills.api.SkillComponent;
import com.yaohun.demonskills.api.TargetSelector;
import eos.moe.dragoncore.network.PacketSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

public class StunPlayerComponent implements SkillComponent {

    private final long stunTicks;
    private final TargetSelector selector;

    public StunPlayerComponent(TargetSelector targetSelector, long stunTicks) {
        this.selector = targetSelector;
        this.stunTicks = stunTicks;
    }

    @Override
    public void execute(Player caster) {
        for (Entity target : selector.selectTargets(caster)) {
            if (target instanceof Player) {
                Player player = (Player) target;
                PacketSender.sendOpenGui(player,"禁止操作");
                new BukkitRunnable() {
                    @Override
                    public void run() {
                        player.closeInventory();
                        cancel();
                    }
                }.runTaskLater(SkillsMain.inst(), stunTicks);
            }
        }
    }

}
