From 77148338b9c2815c80b89b0205a9aaba6ed74422 Mon Sep 17 00:00:00 2001 From: themode Date: Mon, 22 Feb 2021 06:00:49 +0100 Subject: [PATCH] Added Entity#clearEffects --- .../net/minestom/server/entity/Entity.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 171c1cae2..9d6f9d23c 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -1261,6 +1261,18 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P 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. * @@ -1281,15 +1293,17 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P } /** - * Adds an effect to an entity. - * - * @param potion The potion to add + * Removes all the effects currently applied to the entity. */ - 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)); + public void clearEffects() { + for (TimedPotion timedPotion : effects) { + timedPotion.getPotion().sendRemovePacket(this); + callEvent(EntityPotionRemoveEvent.class, new EntityPotionRemoveEvent( + this, + timedPotion.getPotion() + )); + } + this.effects.clear(); } /**