Added Entity#clearEffects

This commit is contained in:
themode 2021-02-22 06:00:49 +01:00
parent 1fda2aba6d
commit 77148338b9

View File

@ -1261,6 +1261,18 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
return Collections.unmodifiableList(effects); return Collections.unmodifiableList(effects);
} }
/**
* Adds an effect to an entity.
*
* @param potion The potion to add
*/
public void addEffect(@NotNull Potion potion) {
removeEffect(potion.getEffect());
this.effects.add(new TimedPotion(potion, System.currentTimeMillis()));
potion.sendAddPacket(this);
callEvent(EntityPotionAddEvent.class, new EntityPotionAddEvent(this, potion));
}
/** /**
* Removes effect from entity, if it has it. * Removes effect from entity, if it has it.
* *
@ -1281,15 +1293,17 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
} }
/** /**
* Adds an effect to an entity. * Removes all the effects currently applied to the entity.
*
* @param potion The potion to add
*/ */
public void addEffect(@NotNull Potion potion) { public void clearEffects() {
removeEffect(potion.getEffect()); for (TimedPotion timedPotion : effects) {
this.effects.add(new TimedPotion(potion, System.currentTimeMillis())); timedPotion.getPotion().sendRemovePacket(this);
potion.sendAddPacket(this); callEvent(EntityPotionRemoveEvent.class, new EntityPotionRemoveEvent(
callEvent(EntityPotionAddEvent.class, new EntityPotionAddEvent(this, potion)); this,
timedPotion.getPotion()
));
}
this.effects.clear();
} }
/** /**