mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 20:07:09 +00:00
Use static-analysis-friendly method for getting effects from EffectManager
fixes 5 phpstan level 8 errors
This commit is contained in:
parent
9e6f1c9a5a
commit
7e331c590d
@ -281,7 +281,7 @@ abstract class Living extends Entity{
|
||||
* Returns the initial upwards velocity of a jumping entity in blocks/tick, including additional velocity due to effects.
|
||||
*/
|
||||
public function getJumpVelocity() : float{
|
||||
return $this->jumpVelocity + ($this->effectManager->has(VanillaEffects::JUMP_BOOST()) ? ($this->effectManager->get(VanillaEffects::JUMP_BOOST())->getEffectLevel() / 10) : 0);
|
||||
return $this->jumpVelocity + ((($jumpBoost = $this->effectManager->get(VanillaEffects::JUMP_BOOST())) !== null ? $jumpBoost->getEffectLevel() : 0) / 10);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,7 +294,7 @@ abstract class Living extends Entity{
|
||||
}
|
||||
|
||||
public function fall(float $fallDistance) : void{
|
||||
$damage = ceil($fallDistance - 3 - ($this->effectManager->has(VanillaEffects::JUMP_BOOST()) ? $this->effectManager->get(VanillaEffects::JUMP_BOOST())->getEffectLevel() : 0));
|
||||
$damage = ceil($fallDistance - 3 - (($jumpBoost = $this->effectManager->get(VanillaEffects::JUMP_BOOST())) !== null ? $jumpBoost->getEffectLevel() : 0));
|
||||
if($damage > 0){
|
||||
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
|
||||
$this->attack($ev);
|
||||
@ -367,8 +367,8 @@ abstract class Living extends Entity{
|
||||
}
|
||||
|
||||
$cause = $source->getCause();
|
||||
if($this->effectManager->has(VanillaEffects::RESISTANCE()) and $cause !== EntityDamageEvent::CAUSE_VOID and $cause !== EntityDamageEvent::CAUSE_SUICIDE){
|
||||
$source->setModifier(-$source->getFinalDamage() * min(1, 0.2 * $this->effectManager->get(VanillaEffects::RESISTANCE())->getEffectLevel()), EntityDamageEvent::MODIFIER_RESISTANCE);
|
||||
if(($resistance = $this->effectManager->get(VanillaEffects::RESISTANCE())) !== null and $cause !== EntityDamageEvent::CAUSE_VOID and $cause !== EntityDamageEvent::CAUSE_SUICIDE){
|
||||
$source->setModifier(-$source->getFinalDamage() * min(1, 0.2 * $resistance->getEffectLevel()), EntityDamageEvent::MODIFIER_RESISTANCE);
|
||||
}
|
||||
|
||||
$totalEpf = 0;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,16 +130,6 @@ parameters:
|
||||
count: 1
|
||||
path: ../../../src/entity/Entity.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method getEffectLevel\\(\\) on pocketmine\\\\entity\\\\effect\\\\EffectInstance\\|null\\.$#"
|
||||
count: 3
|
||||
path: ../../../src/entity/Living.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method getEffectLevel\\(\\) on pocketmine\\\\entity\\\\effect\\\\EffectInstance\\|null\\.$#"
|
||||
count: 2
|
||||
path: ../../../src/event/entity/EntityDamageByEntityEvent.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$oldContents of method pocketmine\\\\inventory\\\\InventoryListener\\:\\:onContentChange\\(\\) expects array\\<pocketmine\\\\item\\\\Item\\>, array\\<int, pocketmine\\\\item\\\\Item\\|null\\> given\\.$#"
|
||||
count: 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user