From 5e731e5ba915df2e6bc2e2072fe2d4fbd146c044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9meth=20Noel?= Date: Tue, 29 Jun 2021 23:04:25 +0200 Subject: [PATCH] Updated EntityFireEvent.java --- .../server/event/entity/EntityFireEvent.java | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/minestom/server/event/entity/EntityFireEvent.java b/src/main/java/net/minestom/server/event/entity/EntityFireEvent.java index 5ffdad699..9bcce987a 100644 --- a/src/main/java/net/minestom/server/event/entity/EntityFireEvent.java +++ b/src/main/java/net/minestom/server/event/entity/EntityFireEvent.java @@ -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