Use static-analysis-friendly method for getting effects from EffectManager

fixes 5 phpstan level 8 errors
This commit is contained in:
Dylan K. Taylor
2020-06-27 13:08:36 +01:00
parent 9e6f1c9a5a
commit 7e331c590d
3 changed files with 8 additions and 18 deletions

View File

@ -49,12 +49,12 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{
protected function addAttackerModifiers(Entity $damager) : void{
if($damager instanceof Living){ //TODO: move this to entity classes
$effects = $damager->getEffects();
if($effects->has(VanillaEffects::STRENGTH())){
$this->setModifier($this->getBaseDamage() * 0.3 * $effects->get(VanillaEffects::STRENGTH())->getEffectLevel(), self::MODIFIER_STRENGTH);
if(($strength = $effects->get(VanillaEffects::STRENGTH())) !== null){
$this->setModifier($this->getBaseDamage() * 0.3 * $strength->getEffectLevel(), self::MODIFIER_STRENGTH);
}
if($effects->has(VanillaEffects::WEAKNESS())){
$this->setModifier(-($this->getBaseDamage() * 0.2 * $effects->get(VanillaEffects::WEAKNESS())->getEffectLevel()), self::MODIFIER_WEAKNESS);
if(($weakness = $effects->get(VanillaEffects::WEAKNESS())) !== null){
$this->setModifier(-($this->getBaseDamage() * 0.2 * $weakness->getEffectLevel()), self::MODIFIER_WEAKNESS);
}
}
}