removed scheduledPotions

This commit is contained in:
ThatCreeper 2020-12-30 18:55:20 -06:00
parent fa41aabaed
commit c01b57ed9b
2 changed files with 14 additions and 15 deletions

View File

@ -135,7 +135,6 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
protected Pose pose = Pose.STANDING; protected Pose pose = Pose.STANDING;
private CopyOnWriteArrayList<TimedPotion> effects = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList<TimedPotion> effects = new CopyOnWriteArrayList<>();
private CopyOnWriteArrayList<Potion> scheduledPotions = new CopyOnWriteArrayList<>();
// list of scheduled tasks to be executed during the next entity tick // list of scheduled tasks to be executed during the next entity tick
protected final Queue<Consumer<Entity>> nextTick = Queues.newConcurrentLinkedQueue(); protected final Queue<Consumer<Entity>> nextTick = Queues.newConcurrentLinkedQueue();
@ -406,16 +405,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
// remove expired effects // remove expired effects
{ {
effects.removeIf(timedPotion -> time >= effects.removeIf(timedPotion -> time >=
(timedPotion.startingTime + timedPotion.potion.duration * 50)); (timedPotion.getStartingTime() + timedPotion.getPotion().duration * MinecraftServer.TICK_MS));
}
// add queued effects
{
for (Potion potion : scheduledPotions) {
effects.add(new TimedPotion(potion, time));
potion.sendAddPacket(this);
}
scheduledPotions.clear();
} }
// scheduled tasks // scheduled tasks
@ -1474,7 +1464,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
* @param effect The effect to remove * @param effect The effect to remove
*/ */
public void removeEffect(@NotNull PotionEffect effect) { 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) { public void addEffect(@NotNull Potion potion) {
removeEffect(potion.effect); removeEffect(potion.effect);
scheduledPotions.add(potion); effects.add(new TimedPotion(potion, System.currentTimeMillis()));
potion.sendAddPacket(this);
} }
protected boolean shouldRemove() { protected boolean shouldRemove() {

View File

@ -1,11 +1,19 @@
package net.minestom.server.potion; package net.minestom.server.potion;
public class TimedPotion { public class TimedPotion {
public Potion potion; private final Potion potion;
public Long startingTime; private final Long startingTime;
public TimedPotion(Potion potion, Long startingTime) { public TimedPotion(Potion potion, Long startingTime) {
this.potion = potion; this.potion = potion;
this.startingTime = startingTime; this.startingTime = startingTime;
} }
public Potion getPotion() {
return potion;
}
public Long getStartingTime() {
return startingTime;
}
} }