public function close() { if (!$this->closed) { $this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this)); $this->closed = true; $this->despawnFromAll(); if ($this->chunk !== null) { $this->chunk->removeEntity($this); } if ($this->level !== null) { $this->level->removeEntity($this); } } }