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;
}