Updated EntityFireEvent.java

This commit is contained in:
Németh Noel 2021-06-29 23:04:25 +02:00
parent ab80ffcd0e
commit 5e731e5ba9

View File

@ -3,37 +3,62 @@ package net.minestom.server.event.entity;
import net.minestom.server.entity.Entity;
import net.minestom.server.event.trait.CancellableEvent;
import net.minestom.server.event.trait.EntityEvent;
import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.time.Tick;
import org.jetbrains.annotations.NotNull;
import java.time.Duration;
import java.time.temporal.TemporalUnit;
public class EntityFireEvent implements EntityEvent, CancellableEvent {
private final Entity entity;
private int duration;
private TimeUnit timeUnit;
private Duration duration;
private boolean cancelled;
public EntityFireEvent(Entity entity, int duration, TimeUnit timeUnit) {
this.entity = entity;
setFireTime(duration, timeUnit);
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public EntityFireEvent(Entity entity, int duration, net.minestom.server.utils.time.TimeUnit timeUnit) {
this(entity, Duration.ofMillis(timeUnit.toMilliseconds(duration)));
}
public long getFireTime(TimeUnit timeUnit) {
public EntityFireEvent(Entity entity, Duration duration) {
this.entity = entity;
setFireTime(duration);
}
/**
* @deprecated Replaced by {@link #getFireTime(TemporalUnit)}
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public long getFireTime(net.minestom.server.utils.time.TimeUnit timeUnit) {
switch (timeUnit) {
case TICK:
return duration;
return duration.toMillis() / Tick.TICKS.getDuration().toMillis();
case MILLISECOND:
return timeUnit.toMilliseconds(duration);
return duration.toMillis();
default:
// Unexpected
return -1;
}
}
public void setFireTime(int duration, TimeUnit timeUnit) {
public long getFireTime(TemporalUnit temporalUnit) {
return duration.toNanos() / temporalUnit.getDuration().toNanos();
}
/**
* @deprecated Replaced by {@link #setFireTime(Duration)}
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true)
public void setFireTime(int duration, net.minestom.server.utils.time.TimeUnit timeUnit) {
setFireTime(Duration.ofMillis(timeUnit.toMilliseconds(duration)));
}
public void setFireTime(Duration duration) {
this.duration = duration;
this.timeUnit = timeUnit;
}
@Override