mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Add more method to Entity for PotionEffect (#85)
(cherry picked from commit 8edc9981d0
)
This commit is contained in:
parent
6a246d2ce4
commit
0920b90195
@ -1477,6 +1477,36 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* If the entity has the specified effect.
|
||||
*
|
||||
* @param effect the effect to check
|
||||
*/
|
||||
public boolean hasEffect(@NotNull PotionEffect effect) {
|
||||
return this.effects.stream().anyMatch(timedPotion -> timedPotion.getPotion().effect() == effect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the TimedPotion of the specified effect.
|
||||
*
|
||||
* @param effect the effect type
|
||||
* @return the effect, null if not found
|
||||
*/
|
||||
public @Nullable TimedPotion getEffect(@NotNull PotionEffect effect) {
|
||||
return this.effects.stream().filter(timedPotion -> timedPotion.getPotion().effect() == effect).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the level of the specified effect.
|
||||
*
|
||||
* @param effect the effect type
|
||||
* @return the effect level, 0 if not found
|
||||
*/
|
||||
public int getEffectLevel(@NotNull PotionEffect effect) {
|
||||
TimedPotion timedPotion = getEffect(effect);
|
||||
return timedPotion == null ? 0 : timedPotion.getPotion().amplifier();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all the effects currently applied to the entity.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user