pocketmine\level\Level::removeEntity PHP Method

removeEntity() public method

Removes the entity from the level index
public removeEntity ( Entity $entity )
$entity pocketmine\entity\Entity
    public function removeEntity(Entity $entity)
    {
        if ($entity->getLevel() !== $this) {
            throw new LevelException("Invalid Entity level");
        }
        if ($entity instanceof Player) {
            unset($this->players[$entity->getId()]);
            $this->checkSleep();
        } else {
            $entity->close();
        }
        unset($this->entities[$entity->getId()]);
        unset($this->updateEntities[$entity->getId()]);
    }

Usage Example

 public function onUnload(ChunkUnloadEvent $event)
 {
     if ($event->getLevel() === $this->level) {
         foreach ($this->locs[Level::chunkHash($event->getChunk()->getX(), $event->getChunk()->getZ())] as $id => $spawn) {
             if (isset($this->spawns[$spawn->getId()])) {
                 $this->level->removeEntity($this->spawns[$spawn->getId()]);
             }
         }
     }
 }
Level