Added tick as a TemporalUnit

This commit is contained in:
Németh Noel 2021-06-29 22:22:30 +02:00
parent 7e82edcbd9
commit 8f906d80d0

View File

@ -0,0 +1,45 @@
package net.minestom.server.utils.time;
import net.minestom.server.MinecraftServer;
import java.time.Duration;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalUnit;
public class Tick implements TemporalUnit {
public static final Tick TICKS = new Tick();
private Tick() {
}
@Override
public Duration getDuration() {
return Duration.ofMillis(MinecraftServer.TICK_MS);
}
@Override
public boolean isDurationEstimated() {
return false;
}
@Override
public boolean isDateBased() {
return false;
}
@Override
public boolean isTimeBased() {
return true;
}
@Override
public <R extends Temporal> R addTo(R temporal, long amount) {
//noinspection unchecked
return (R) temporal.plus(amount, this);
}
@Override
public long between(Temporal temporal1Inclusive, Temporal temporal2Exclusive) {
return temporal1Inclusive.until(temporal2Exclusive, this);
}
}