pocketmine\entity\Entity::switchLevel PHP Method

switchLevel() protected method

protected switchLevel ( Level $targetLevel )
$targetLevel pocketmine\level\Level
    protected function switchLevel(Level $targetLevel)
    {
        if ($this->closed) {
            return false;
        }
        if ($this->isValid()) {
            $this->server->getPluginManager()->callEvent($ev = new EntityLevelChangeEvent($this, $this->level, $targetLevel));
            if ($ev->isCancelled()) {
                return false;
            }
            $this->level->removeEntity($this);
            if ($this->chunk !== null) {
                $this->chunk->removeEntity($this);
            }
            $this->despawnFromAll();
        }
        $this->setLevel($targetLevel);
        $this->level->addEntity($this);
        $this->chunk = null;
        return true;
    }