From 384c556caf0b218451b851149637b861145321d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9meth=20Noel?= Date: Wed, 30 Jun 2021 00:51:22 +0200 Subject: [PATCH] Updated LivingEntity.java --- .../minestom/server/entity/LivingEntity.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/LivingEntity.java b/src/main/java/net/minestom/server/entity/LivingEntity.java index f1fd8642e..6fc129abc 100644 --- a/src/main/java/net/minestom/server/entity/LivingEntity.java +++ b/src/main/java/net/minestom/server/entity/LivingEntity.java @@ -30,11 +30,14 @@ import net.minestom.server.utils.Position; import net.minestom.server.utils.Vector; import net.minestom.server.utils.block.BlockIterator; import net.minestom.server.utils.time.Cooldown; +import net.minestom.server.utils.time.Tick; import net.minestom.server.utils.time.TimeUnit; -import net.minestom.server.utils.time.UpdateOption; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalUnit; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -42,7 +45,7 @@ public class LivingEntity extends Entity implements EquipmentHandler { // ItemStack pickup protected boolean canPickupItem; - protected Cooldown itemPickupCooldown = new Cooldown(new UpdateOption(5, TimeUnit.TICK)); + protected Cooldown itemPickupCooldown = new Cooldown(Duration.of(5, Tick.SERVER_TICKS)); protected boolean isDead; @@ -316,23 +319,23 @@ public class LivingEntity extends Entity implements EquipmentHandler { * @param duration duration in ticks of the effect */ public void setFireForDuration(int duration) { - setFireForDuration(duration, TimeUnit.TICK); + setFireForDuration(duration, Tick.SERVER_TICKS); } /** * Sets fire to this entity for a given duration. * * @param duration duration of the effect - * @param unit unit used to express the duration + * @param temporalUnit unit used to express the duration * @see #setOnFire(boolean) if you want it to be permanent without any event callback */ - public void setFireForDuration(int duration, TimeUnit unit) { - EntityFireEvent entityFireEvent = new EntityFireEvent(this, duration, unit); + public void setFireForDuration(int duration, TemporalUnit temporalUnit) { + EntityFireEvent entityFireEvent = new EntityFireEvent(this, temporalUnit.getDuration().multipliedBy(duration)); // Do not start fire event if the fire needs to be removed (< 0 duration) if (duration > 0) { EventDispatcher.callCancellable(entityFireEvent, () -> { - final long fireTime = entityFireEvent.getFireTime(TimeUnit.MILLISECOND); + final long fireTime = entityFireEvent.getFireTime(ChronoUnit.MILLIS); setOnFire(true); fireExtinguishTime = System.currentTimeMillis() + fireTime; }); @@ -659,7 +662,7 @@ public class LivingEntity extends Entity implements EquipmentHandler { * Gets the time in ms between two fire damage applications. * * @return the time in ms - * @see #setFireDamagePeriod(long, TimeUnit) + * @see #setFireDamagePeriod(long, TemporalUnit) */ public long getFireDamagePeriod() { return fireDamagePeriod; @@ -669,10 +672,10 @@ public class LivingEntity extends Entity implements EquipmentHandler { * Changes the delay between two fire damage applications. * * @param fireDamagePeriod the delay - * @param timeUnit the time unit + * @param temporalUnit the time unit */ - public void setFireDamagePeriod(long fireDamagePeriod, @NotNull TimeUnit timeUnit) { - fireDamagePeriod = timeUnit.toMilliseconds(fireDamagePeriod); + public void setFireDamagePeriod(long fireDamagePeriod, @NotNull TemporalUnit temporalUnit) { + fireDamagePeriod = temporalUnit.getDuration().multipliedBy(fireDamagePeriod).toMillis(); this.fireDamagePeriod = fireDamagePeriod; }