mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 01:17:47 +01:00
Updated EntityFireEvent.java
This commit is contained in:
parent
ab80ffcd0e
commit
5e731e5ba9
@ -3,37 +3,62 @@ package net.minestom.server.event.entity;
|
|||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.event.trait.CancellableEvent;
|
import net.minestom.server.event.trait.CancellableEvent;
|
||||||
import net.minestom.server.event.trait.EntityEvent;
|
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 org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.temporal.TemporalUnit;
|
||||||
|
|
||||||
public class EntityFireEvent implements EntityEvent, CancellableEvent {
|
public class EntityFireEvent implements EntityEvent, CancellableEvent {
|
||||||
|
|
||||||
private final Entity entity;
|
private final Entity entity;
|
||||||
private int duration;
|
private Duration duration;
|
||||||
private TimeUnit timeUnit;
|
|
||||||
|
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
public EntityFireEvent(Entity entity, int duration, TimeUnit timeUnit) {
|
@SuppressWarnings("removal")
|
||||||
this.entity = entity;
|
@Deprecated(forRemoval = true)
|
||||||
setFireTime(duration, timeUnit);
|
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) {
|
switch (timeUnit) {
|
||||||
case TICK:
|
case TICK:
|
||||||
return duration;
|
return duration.toMillis() / Tick.TICKS.getDuration().toMillis();
|
||||||
case MILLISECOND:
|
case MILLISECOND:
|
||||||
return timeUnit.toMilliseconds(duration);
|
return duration.toMillis();
|
||||||
default:
|
default:
|
||||||
// Unexpected
|
// Unexpected
|
||||||
return -1;
|
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.duration = duration;
|
||||||
this.timeUnit = timeUnit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user