package com.yaohun.demonskills.component;

import com.yaohun.demonskills.SkillsMain;
import com.yaohun.demonskills.api.SkillComponent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.List;

public class DelayComponent implements SkillComponent {
    private final long delayTicks;
    private final List<SkillComponent> children;

    public DelayComponent(long delayTicks, List<SkillComponent> children) {
        this.delayTicks = delayTicks;
        this.children = children;
    }

    @Override
    public void execute(Player caster) {
        Bukkit.getScheduler().runTaskLater(SkillsMain.inst(), () -> {
            for (SkillComponent child : children) {
                child.execute(caster);
            }
        }, delayTicks);
    }
}
