diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index ef44c1858..956436c0b 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -135,7 +135,6 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P protected Pose pose = Pose.STANDING; private CopyOnWriteArrayList effects = new CopyOnWriteArrayList<>(); - private CopyOnWriteArrayList scheduledPotions = new CopyOnWriteArrayList<>(); // list of scheduled tasks to be executed during the next entity tick protected final Queue> nextTick = Queues.newConcurrentLinkedQueue(); @@ -406,16 +405,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P // remove expired effects { effects.removeIf(timedPotion -> time >= - (timedPotion.startingTime + timedPotion.potion.duration * 50)); - } - - // add queued effects - { - for (Potion potion : scheduledPotions) { - effects.add(new TimedPotion(potion, time)); - potion.sendAddPacket(this); - } - scheduledPotions.clear(); + (timedPotion.getStartingTime() + timedPotion.getPotion().duration * MinecraftServer.TICK_MS)); } // scheduled tasks @@ -1474,7 +1464,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P * @param effect The effect to remove */ public void removeEffect(@NotNull PotionEffect effect) { - effects.removeIf(timedPotion -> timedPotion.potion.effect == effect); + effects.removeIf(timedPotion -> timedPotion.getPotion().effect == effect); } /** @@ -1484,7 +1474,8 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P */ public void addEffect(@NotNull Potion potion) { removeEffect(potion.effect); - scheduledPotions.add(potion); + effects.add(new TimedPotion(potion, System.currentTimeMillis())); + potion.sendAddPacket(this); } protected boolean shouldRemove() { diff --git a/src/main/java/net/minestom/server/potion/TimedPotion.java b/src/main/java/net/minestom/server/potion/TimedPotion.java index 46d2c7819..7674c9f7d 100644 --- a/src/main/java/net/minestom/server/potion/TimedPotion.java +++ b/src/main/java/net/minestom/server/potion/TimedPotion.java @@ -1,11 +1,19 @@ package net.minestom.server.potion; public class TimedPotion { - public Potion potion; - public Long startingTime; + private final Potion potion; + private final Long startingTime; public TimedPotion(Potion potion, Long startingTime) { this.potion = potion; this.startingTime = startingTime; } + + public Potion getPotion() { + return potion; + } + + public Long getStartingTime() { + return startingTime; + } }