mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 01:17:47 +01:00
Repurpose TimeUnit.java
This commit is contained in:
parent
4b04539086
commit
ff4bb20a04
@ -1,38 +1,14 @@
|
|||||||
package net.minestom.server.utils.time;
|
package net.minestom.server.utils.time;
|
||||||
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.time.temporal.TemporalUnit;
|
||||||
/**
|
|
||||||
* @deprecated Replaced by {@link java.time.temporal.TemporalUnit}
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public enum TimeUnit {
|
|
||||||
|
|
||||||
TICK, DAY, HOUR, MINUTE, SECOND, MILLISECOND;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a value and its unit to milliseconds.
|
|
||||||
*
|
|
||||||
* @param value the time value
|
|
||||||
* @return the converted milliseconds based on the time value and the unit
|
|
||||||
*/
|
|
||||||
public long toMilliseconds(long value) {
|
|
||||||
switch (this) {
|
|
||||||
case TICK:
|
|
||||||
return MinecraftServer.TICK_MS * value;
|
|
||||||
case DAY:
|
|
||||||
return value * 86_400_000;
|
|
||||||
case HOUR:
|
|
||||||
return value * 3_600_000;
|
|
||||||
case MINUTE:
|
|
||||||
return value * 60_000;
|
|
||||||
case SECOND:
|
|
||||||
return value * 1000;
|
|
||||||
case MILLISECOND:
|
|
||||||
return value;
|
|
||||||
default:
|
|
||||||
return -1; // Unexpected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public class TimeUnit {
|
||||||
|
public static final TemporalUnit DAY = ChronoUnit.DAYS;
|
||||||
|
public static final TemporalUnit HOUR = ChronoUnit.HOURS;
|
||||||
|
public static final TemporalUnit MINUTE = ChronoUnit.MINUTES;
|
||||||
|
public static final TemporalUnit SECOND = ChronoUnit.SECONDS;
|
||||||
|
public static final TemporalUnit MILLISECOND = ChronoUnit.MILLIS;
|
||||||
|
public static final TemporalUnit SERVER_TICK = Tick.SERVER_TICKS;
|
||||||
|
public static final TemporalUnit CLIENT_TICK = Tick.CLIENT_TICKS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user