pocketmine\Player::close PHP Method

close() final public method

Note for plugin developers: use kick() with the isAdmin flag set to kick without the "Kicked by admin" part instead of this method.
final public close ( string $message = "", string $reason = "generic reason", boolean $notify = true )
$message string Message to be broadcasted
$reason string Reason showed in console
$notify boolean
    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->setLinked();
            if ($this->fishingHook instanceof FishingHook) {
                $this->fishingHook->close();
                $this->fishingHook = null;
            }
            $this->removeEffect(Effect::HEALTH_BOOST);
            $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() != "") {
                if ($this->server->playerMsgType === Server::PLAYER_MSG_TYPE_MESSAGE) {
                    $this->server->broadcastMessage($ev->getQuitMessage());
                } elseif ($this->server->playerMsgType === Server::PLAYER_MSG_TYPE_TIP) {
                    $this->server->broadcastTip(str_replace("@player", $this->getName(), $this->server->playerLogoutMsg));
                } elseif ($this->server->playerMsgType === Server::PLAYER_MSG_TYPE_POPUP) {
                    $this->server->broadcastPopup(str_replace("@player", $this->getName(), $this->server->playerLogoutMsg));
                }
            }
            $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this);
            $this->spawned = false;
            $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.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->server->dserverConfig["enable"] and $this->server->dserverConfig["queryAutoUpdate"]) {
                $this->server->updateQuery();
            }
        }
        if ($this->perm !== null) {
            $this->perm->clearPermissions();
            $this->perm = null;
        }
        $this->inventory = null;
        $this->transactionQueue = null;
        $this->chunk = null;
        $this->server->removePlayer($this);
    }

Usage Example

コード例 #1
0
 public function close(Player $player, $reason = "unknown reason")
 {
     if ($player instanceof DummyReceiver) {
         if ($player->entity instanceof DummyEntity) {
             $player->entity->close();
         }
         $player->close();
     }
     $this->sessions->detach($player);
     unset($this->ackStore[$player->getName()]);
     unset($this->replyStore[$player->getName()]);
 }
All Usage Examples Of pocketmine\Player::close
Player