Updated Cooldown.java

This commit is contained in:
Németh Noel 2021-06-30 01:07:38 +02:00
parent 580509c420
commit 30abfce554

View File

@ -5,7 +5,6 @@ import org.jetbrains.annotations.NotNull;
import java.time.Duration; import java.time.Duration;
import java.time.temporal.TemporalUnit; import java.time.temporal.TemporalUnit;
@SuppressWarnings("removal")
public final class Cooldown { public final class Cooldown {
private final Duration duration; private final Duration duration;
@ -14,14 +13,15 @@ public final class Cooldown {
/** /**
* @deprecated Replaced by {@link #Cooldown(Duration)} * @deprecated Replaced by {@link #Cooldown(Duration)}
*/ */
@SuppressWarnings("removal")
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public Cooldown(@NotNull UpdateOption updateOption) { public Cooldown(@NotNull UpdateOption updateOption) {
this.duration = Duration.ofMillis(updateOption.toMilliseconds()); this(updateOption.toDuration());
this.lastUpdate = System.currentTimeMillis();
} }
public Cooldown(Duration duration) { public Cooldown(Duration duration) {
this.duration = duration; this.duration = duration;
this.lastUpdate = System.currentTimeMillis();
} }
public Duration getDuration() { public Duration getDuration() {
@ -36,23 +36,6 @@ public final class Cooldown {
return !hasCooldown(time, lastUpdate, duration); return !hasCooldown(time, lastUpdate, duration);
} }
/**
* Gets if something is in cooldown based on the current time.
*
* @param currentTime the current time in milliseconds
* @param lastUpdate the last update in milliseconds
* @param timeUnit the time unit of the cooldown
* @param cooldown the value of the cooldown
* @return true if the cooldown is in progress, false otherwise
*
* @deprecated Replaced by {@link #hasCooldown(long, long, TemporalUnit, long)}
*/
@Deprecated(forRemoval = true)
public static boolean hasCooldown(long currentTime, long lastUpdate, @NotNull TimeUnit timeUnit, long cooldown) {
final long cooldownMs = timeUnit.toMilliseconds(cooldown);
return currentTime - lastUpdate < cooldownMs;
}
/** /**
* Gets if something is in cooldown based on the current time. * Gets if something is in cooldown based on the current time.
* *
@ -76,9 +59,10 @@ public final class Cooldown {
* *
* @deprecated Replaced by {@link #hasCooldown(long, long, Duration)} * @deprecated Replaced by {@link #hasCooldown(long, long, Duration)}
*/ */
@SuppressWarnings("removal")
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public static boolean hasCooldown(long currentTime, long lastUpdate, @NotNull UpdateOption updateOption) { public static boolean hasCooldown(long currentTime, long lastUpdate, @NotNull UpdateOption updateOption) {
return hasCooldown(currentTime, lastUpdate, updateOption.getTimeUnit(), updateOption.getValue()); return hasCooldown(currentTime, lastUpdate, updateOption.toDuration());
} }
/** /**
@ -94,21 +78,6 @@ public final class Cooldown {
return currentTime - lastUpdate < cooldownMs; return currentTime - lastUpdate < cooldownMs;
} }
/**
* Gets if something is in cooldown based on the current time ({@link System#currentTimeMillis()}).
*
* @param lastUpdate the last update in milliseconds
* @param timeUnit the time unit of the cooldown
* @param cooldown the value of the cooldown
* @return true if the cooldown is in progress, false otherwise
*
* @deprecated Replaced by {@link #hasCooldown(long, TemporalUnit, int)}
*/
@Deprecated(forRemoval = true)
public static boolean hasCooldown(long lastUpdate, @NotNull TimeUnit timeUnit, int cooldown) {
return hasCooldown(System.currentTimeMillis(), lastUpdate, timeUnit, cooldown);
}
/** /**
* Gets if something is in cooldown based on the current time ({@link System#currentTimeMillis()}). * Gets if something is in cooldown based on the current time ({@link System#currentTimeMillis()}).
* *