From 911ad344c9ad8d76c1cd21ce3a52394de9cc1afb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 10 Dec 2021 17:27:28 +0000 Subject: [PATCH] Human: do not mutate parameter variables in setXpAndProgress() this caused a mystery that took 3 entire years to debug. --- src/pocketmine/entity/Human.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 835b7baf1..b80ecb45d 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -447,24 +447,26 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ } protected function setXpAndProgress(?int $level, ?float $progress) : bool{ + $newLevel = $level; + $newProgress = $progress; if(!$this->justCreated){ - $ev = new PlayerExperienceChangeEvent($this, $this->getXpLevel(), $this->getXpProgress(), $level, $progress); + $ev = new PlayerExperienceChangeEvent($this, $this->getXpLevel(), $this->getXpProgress(), $newLevel, $newProgress); $ev->call(); if($ev->isCancelled()){ return false; } - $level = $ev->getNewLevel(); - $progress = $ev->getNewProgress(); + $newLevel = $ev->getNewLevel(); + $newProgress = $ev->getNewProgress(); } - if($level !== null){ - $this->getAttributeMap()->getAttribute(Attribute::EXPERIENCE_LEVEL)->setValue($level); + if($newLevel !== null){ + $this->getAttributeMap()->getAttribute(Attribute::EXPERIENCE_LEVEL)->setValue($newLevel); } - if($progress !== null){ - $this->getAttributeMap()->getAttribute(Attribute::EXPERIENCE)->setValue($progress); + if($newProgress !== null){ + $this->getAttributeMap()->getAttribute(Attribute::EXPERIENCE)->setValue($newProgress); } return true;