public function unloadChunks($force = false) { if (count($this->unloadQueue) > 0) { $maxUnload = 96; $now = microtime(true); foreach ($this->unloadQueue as $index => $time) { Level::getXZ($index, $X, $Z); if (!$force) { if ($maxUnload <= 0) { break; } elseif ($time > $now - 30) { continue; } } //If the chunk can't be unloaded, it stays on the queue if ($this->unloadChunk($X, $Z, true)) { unset($this->unloadQueue[$index]); --$maxUnload; } } } }
/** * Note for plugin developers: use kick() with the isAdmin * flag set to kick without the "Kicked by admin" part instead of this method. * * @param string $message * Message to be broadcasted * @param string $reason * Reason showed in console * @param bool $notify */ public final function close($message = "", $reason = "generic reason", $notify = true) { if ($this->connected and !$this->closed) { if ($notify and strlen((string) $reason) > 0) { $pk = new DisconnectPacket(); $pk->message = $reason; $this->directDataPacket($pk); } $this->connected = false; if (strlen($this->getName()) > 0) { $this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message, true)); if ($this->loggedIn === true and $ev->getAutoSave()) { $this->save(); } } foreach ($this->server->getOnlinePlayers() as $player) { if (!$player->canSee($this)) { $player->showPlayer($this); } } $this->hiddenPlayers = []; foreach ($this->windowIndex as $window) { $this->removeWindow($window); } foreach ($this->usedChunks as $index => $d) { Level::getXZ($index, $chunkX, $chunkZ); $this->level->unregisterChunkLoader($this, $chunkX, $chunkZ); unset($this->usedChunks[$index]); } parent::close(); $this->interface->close($this, $notify ? $reason : ""); if ($this->loggedIn) { $this->server->removeOnlinePlayer($this); } $this->loggedIn = false; if (isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != "") { $this->server->broadcastMessage($ev->getQuitMessage()); } $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); $this->spawned = false; $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("BukkitPE.player.logOut", [TextFormat::AQUA . $this->getName() . TextFormat::WHITE, $this->ip, $this->port, $this->getServer()->getLanguage()->translateString($reason)])); $this->windows = new \SplObjectStorage(); $this->windowIndex = []; $this->usedChunks = []; $this->loadQueue = []; $this->hasSpawned = []; $this->spawnPosition = null; unset($this->buffer); } if ($this->perm !== null) { $this->perm->clearPermissions(); $this->perm = null; } if ($this->inventory !== null) { $this->inventory = null; $this->currentTransaction = null; } $this->chunk = null; $this->server->removePlayer($this); }