package me.km.scheduler;

public class SnuviTask {
    private final long rtimer;
    private final Runnable r;
    private long timer;

    public SnuviTask(Runnable r, long delay, long rtimer) {
        this.rtimer = rtimer;
        this.timer = delay;
        this.r = r;
    }

    public long getRepeatTimer() {
        return rtimer;
    }

    public boolean isRepeating() {
        return rtimer > 0;
    }

    public boolean tick(int ticks, boolean noRepeat) {
        timer -= ticks;
        if(timer <= 0) {
            r.run();
            if(rtimer <= 0 || noRepeat) {
                return true;
            }
            timer = rtimer;
        }
        return false;
    }
}
