Hub / src / main / java / com / lifeknight / relaymchub / miscellaneous / Cooldown.java
Cooldown.java
Raw
package com.lifeknight.relaymchub.miscellaneous;

import java.util.concurrent.TimeUnit;

public enum Cooldown {
    HIDE_SHOW_PLAYERS("hide_show_players", 3),
    SHARE_KIT("share_kit", 120),
    SHARE_MAP("share_map", 120),
    MORPH_PROJECTILE("morph_projectile", 5);

    public final String codeName;
    public final long time;

    Cooldown(String codeName, long time, TimeUnit timeUnit) {
        this.codeName = codeName;
        this.time = timeUnit.toMillis(time);
    }

    Cooldown(String codeName, long time) {
        this(codeName, time, TimeUnit.SECONDS);
    }

    public boolean enoughTimeHasPassed(long lastTime) {
        if (lastTime == 0) {
            return true;
        }

        return System.currentTimeMillis() - lastTime >= this.time;
    }
}