Effect: get rid of runtimeIDs

This commit is contained in:
Dylan K. Taylor
2021-09-03 21:25:06 +01:00
parent c062282954
commit 0404298c74
5 changed files with 41 additions and 45 deletions

View File

@ -27,6 +27,7 @@ use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\VanillaEffects;
use pocketmine\utils\SingletonTrait;
use function array_key_exists;
use function spl_object_id;
final class EffectIdMap{
use SingletonTrait;
@ -79,7 +80,7 @@ final class EffectIdMap{
public function register(int $mcpeId, Effect $effect) : void{
$this->idToEffect[$mcpeId] = $effect;
$this->effectToId[$effect->getRuntimeId()] = $mcpeId;
$this->effectToId[spl_object_id($effect)] = $mcpeId;
}
public function fromId(int $id) : ?Effect{
@ -88,10 +89,10 @@ final class EffectIdMap{
}
public function toId(Effect $effect) : int{
if(!array_key_exists($effect->getRuntimeId(), $this->effectToId)){
if(!array_key_exists(spl_object_id($effect), $this->effectToId)){
//this should never happen, so we treat it as an exceptional condition
throw new \InvalidArgumentException("Effect does not have a mapped ID");
}
return $this->effectToId[$effect->getRuntimeId()];
return $this->effectToId[spl_object_id($effect)];
}
}