Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Add more method to Entity for PotionEffect (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBretze committed Dec 14, 2023
1 parent 2f3eeb5 commit 8edc998
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/net/minestom/server/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,36 @@ public void removeEffect(@NotNull PotionEffect effect) {
});
}

/**
* 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.
*/
Expand Down

0 comments on commit 8edc998

Please sign in to comment.