Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- public class Cooldown<T> {
- protected final HashMap<T, Long> cooldowns = new HashMap<>();
- private final long cooldownTime;
- public Cooldown(long cooldownTimeMillis) {
- this.cooldownTime = cooldownTimeMillis;
- }
- public boolean isOnCooldown(T t) {
- if (!cooldowns.containsKey(t)) return false;
- return getTimeRemaining(t) > 0;
- }
- public long getTimeRemaining(T t) {
- if (!cooldowns.containsKey(t)) return -1;
- return cooldownTime - (System.currentTimeMillis() - cooldowns.get(t));
- }
- public void addToCooldown(T t) {
- cooldowns.put(t, System.currentTimeMillis());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement