Deprecated net.minestom.server.entity.Entity.scheduleRemove(long, java.time.temporal.TemporalUnit)

This commit is contained in:
Németh Noel 2021-07-01 15:03:16 +02:00
parent fdf7153986
commit bcc1132ed7
2 changed files with 20 additions and 7 deletions

View File

@ -1530,17 +1530,29 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
* @param delay the time before removing the entity,
* 0 to cancel the removing
* @param temporalUnit the unit of the delay
* @deprecated Replaced by {@link #scheduleRemove(Duration)}
*/
@Deprecated
public void scheduleRemove(long delay, @NotNull TemporalUnit temporalUnit) {
if (delay == 0) { // Cancel the scheduled remove
this.scheduledRemoveTime = 0;
return;
}
this.scheduledRemoveTime = System.currentTimeMillis() + TimeUnit.getMillis(delay, temporalUnit);
scheduleRemove(Duration.of(delay, temporalUnit));
}
/**
* Gets if the entity removal has been scheduled with {@link #scheduleRemove(long, TemporalUnit)}.
* Triggers {@link #remove()} after the specified time.
*
* @param delay the time before removing the entity,
* 0 to cancel the removing
*/
public void scheduleRemove(Duration delay) {
if (delay.isZero()) { // Cancel the scheduled remove
this.scheduledRemoveTime = 0;
return;
}
this.scheduledRemoveTime = System.currentTimeMillis() + delay.toMillis();
}
/**
* Gets if the entity removal has been scheduled with {@link #scheduleRemove(Duration)}.
*
* @return true if the entity removal has been scheduled
*/

View File

@ -14,6 +14,7 @@ import net.minestom.server.utils.time.TimeUnit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.Duration;
import java.util.Collection;
import java.util.Set;
import java.util.UUID;
@ -80,7 +81,7 @@ public class EntityCreature extends LivingEntity implements NavigableEntity, Ent
if (removalAnimationDelay > 0) {
// Needed for proper death animation (wait for it to finish before destroying the entity)
scheduleRemove(removalAnimationDelay, TimeUnit.MILLISECOND);
scheduleRemove(Duration.of(removalAnimationDelay, TimeUnit.MILLISECOND));
} else {
// Instant removal without animation playback
remove();