当前位置: 首页>>代码示例>>PHP>>正文


PHP TextFormat::toJSON方法代码示例

本文整理汇总了PHP中pocketmine\utils\TextFormat::toJSON方法的典型用法代码示例。如果您正苦于以下问题:PHP TextFormat::toJSON方法的具体用法?PHP TextFormat::toJSON怎么用?PHP TextFormat::toJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\utils\TextFormat的用法示例。


在下文中一共展示了TextFormat::toJSON方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: serverToInterface

 public function serverToInterface(DesktopPlayer $player, DataPacket $packet)
 {
     switch ($packet->pid()) {
         case Info::DISCONNECT_PACKET:
             if ($player->bigBrother_getStatus() === 0) {
                 $pk = new LoginDisconnectPacket();
                 $pk->reason = TextFormat::toJSON($packet->message === "" ? "You have been disconnected." : $packet->message);
             } else {
                 $pk = new PlayDisconnectPacket();
                 $pk->reason = TextFormat::toJSON($packet->message === "" ? "You have been disconnected." : $packet->message);
             }
             return $pk;
         case Info::TEXT_PACKET:
             echo $player->getSetting("Lang") . "\n";
             /*if($packet->message === "chat.type.achievement"){
             		/*$pk = new ScoreboardObjectivePacket();
             		$pk->ObjectiveName = $packet->parameters[0];
             		$pk->Mode = 0;
             		$pk->ObjectiveValue = 3;
             		return $pk;*/
             /*echo "TextPacket: achievement\n";
             			return null;
             		}else{
             			$pk = new STCChatPacket();
             			$pk->message = TextFormat::toJSON($packet->message, $packet->type, $packet->parameters);
             		}*/
             //return $pk;
             return null;
         case Info::SET_TIME_PACKET:
             $pk = new TimeUpdatePacket();
             $pk->age = $packet->time;
             $pk->time = $packet->time;
             //TODO: calculate offset from MCPE
             return $pk;
         case Info::START_GAME_PACKET:
             $packets = [];
             $pk = new JoinGamePacket();
             $pk->eid = $packet->eid;
             $pk->gamemode = $packet->gamemode;
             $pk->dimension = 0;
             $pk->difficulty = $player->getServer()->getDifficulty();
             $pk->maxPlayers = $player->getServer()->getMaxPlayers();
             $pk->levelType = "default";
             $packets[] = $pk;
             $pk = new SpawnPositionPacket();
             $pk->spawnX = $packet->spawnX;
             $pk->spawnY = $packet->spawnY;
             $pk->spawnZ = $packet->spawnZ;
             $packets[] = $pk;
             $pk = new PlayerAbilitiesPacket();
             $pk->flyingSpeed = 0.05;
             $pk->walkingSpeed = 0.1;
             $pk->canFly = ($player->getGamemode() & 0x1) > 0;
             $pk->damageDisabled = ($player->getGamemode() & 0x1) > 0;
             $pk->isFlying = false;
             $pk->isCreative = ($player->getGamemode() & 0x1) > 0;
             $packets[] = $pk;
             $pk = new PositionAndLookPacket();
             $pk->x = $packet->x;
             $pk->y = $packet->y;
             $pk->z = $packet->z;
             $pk->yaw = $player->yaw;
             $pk->pitch = $player->pitch;
             $packets[] = $pk;
             return $packets;
         case Info::ADD_PLAYER_PACKET:
             $packets = [];
             $packetplayer = $player->getServer()->getPlayerExact($packet->username);
             $pk = new PlayerListPacket();
             $pk->actionID = PlayerListPacket::TYPE_ADD;
             $pk->players[] = [$packetplayer->getUniqueId()->toBinary(), $packetplayer->getName(), [], $packetplayer->getGamemode(), 0, false];
             if ($packetplayer instanceof DesktopPlayer) {
                 $pk->players[0][2] = $packetplayer->bigBrother_getPeroperties();
             }
             $packets[] = $pk;
             $pk = new SpawnPlayerPacket();
             $pk->eid = $packet->eid;
             $pk->uuid = $packetplayer->getUniqueId()->toBinary();
             $pk->x = $packet->x;
             $pk->z = $packet->z;
             $pk->y = $packet->y;
             $pk->yaw = $packet->yaw;
             $pk->pitch = $packet->pitch;
             $pk->item = $packetplayer->getInventory()->getItemInHand()->getId();
             $pk->metadata = $packet->metadata;
             $packets[] = $pk;
             $pk = new EntityTeleportPacket();
             $pk->eid = $packet->eid;
             $pk->x = $packet->x;
             $pk->y = $packet->y;
             $pk->z = $packet->z;
             $pk->yaw = $packet->yaw;
             $pk->pitch = $packet->pitch;
             $packets[] = $pk;
             return $packets;
             /*case Info::ADD_ENTITY_PACKET:
             		return null;*/
             /*case Info::REMOVE_PLAYER_PACKET:
             				$pk = new PlayerListPacket();
             				$pk->actionID = PlayerListPacket::TYPE_REMOVE;
//.........这里部分代码省略.........
开发者ID:iPocketTeam,项目名称:BigBrother,代码行数:101,代码来源:Translator_84.php

示例2: process

 public function process()
 {
     $length = Binary::readVarIntSession($this);
     if ($length === false or $this->status === -1) {
         $this->close("Connection closed");
         return;
     } elseif ($length <= 0 or $length > 131070) {
         $this->close("Invalid length");
         return;
     }
     $offset = 0;
     $buffer = $this->read($length);
     if ($this->threshold !== null) {
         $dataLength = Binary::readVarInt($buffer, $offset);
         if ($dataLength !== 0) {
             if ($dataLength < $this->threshold) {
                 $this->close("Invalid compression threshold");
             } else {
                 $buffer = zlib_decode(substr($buffer, $offset));
                 $offset = 0;
             }
         } else {
             $buffer = substr($buffer, $offset);
             $offset = 0;
         }
     }
     if ($this->status === 2) {
         //Login
         $this->manager->sendPacket($this->identifier, $buffer);
     } elseif ($this->status === 1) {
         $pid = Binary::readVarInt($buffer, $offset);
         if ($pid === 0x0) {
             $sample = [];
             foreach ($this->manager->sample as $id => $name) {
                 $sample[] = ["name" => $name, "id" => $id];
             }
             $data = ["version" => ["name" => Info::VERSION, "protocol" => Info::PROTOCOL], "players" => ["max" => $this->manager->getServerData()["MaxPlayers"], "online" => $this->manager->getServerData()["OnlinePlayers"], "sample" => $sample], "description" => json_decode(TextFormat::toJSON($this->manager->description))];
             if ($this->manager->favicon !== null) {
                 $data["favicon"] = $this->manager->favicon;
             }
             $data = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
             $data = Binary::writeVarInt(0x0) . Binary::writeVarInt(strlen($data)) . $data;
             $this->writeRaw($data);
         } elseif ($pid === 0x1) {
             $packet = new PingPacket();
             $packet->read($buffer, $offset);
             $this->writePacket($packet);
             $this->status = -1;
         }
     } elseif ($this->status === 0) {
         $pid = Binary::readVarInt($buffer, $offset);
         if ($pid === 0x0) {
             $protocol = Binary::readVarInt($buffer, $offset);
             $len = Binary::readVarInt($buffer, $offset);
             $hostname = substr($buffer, $offset, $len);
             $offset += $len;
             $serverPort = Binary::readShort(substr($buffer, $offset, 2));
             $offset += 2;
             $nextState = Binary::readVarInt($buffer, $offset);
             if ($nextState === 1) {
                 $this->status = 1;
             } elseif ($nextState === 2) {
                 $this->status = -1;
                 if ($protocol < Info::PROTOCOL) {
                     $packet = new LoginDisconnectPacket();
                     $packet->reson = TextFormat::toJSON(TextFormat::BOLD . "Outdated client!" . TextFormat::RESET . "\n\nPlease use " . Info::VERSION);
                     $this->writePacket($packet);
                 } elseif ($protocol > Info::PROTOCOL) {
                     $packet = new LoginDisconnectPacket();
                     $packet->reson = TextFormat::toJSON(TextFormat::BOLD . "Outdated server!" . TextFormat::RESET . "\n\nI'm using " . Info::VERSION);
                     $this->writePacket($packet);
                 } else {
                     $this->manager->openSession($this);
                     $this->status = 2;
                 }
             } else {
                 $this->close();
             }
         } else {
             $this->close("Unexpected packet {$pid}");
         }
     }
 }
开发者ID:iPocketTeam,项目名称:BigBrother,代码行数:83,代码来源:Session.php

示例3: close

 public function close($message = "", $reason = "generic reason")
 {
     if ($this->bigBrother_status === 0) {
         $pk = new LoginDisconnectPacket();
         $pk->reason = TextFormat::toJSON($reason === "" ? "You have been disconnected." : $reason);
         $this->putRawPacket($pk);
     } else {
         $pk = new PlayDisconnectPacket();
         $pk->reason = TextFormat::toJSON($reason === "" ? "You have been disconnected." : $reason);
         $this->putRawPacket($pk);
     }
     parent::close($message, $reason);
 }
开发者ID:MrGenga,项目名称:BigBrother,代码行数:13,代码来源:DesktopPlayer.php

示例4: serverToInterface

 public function serverToInterface(DesktopPlayer $player, DataPacket $packet)
 {
     switch ($packet->pid()) {
         case Info::UPDATE_BLOCK_PACKET:
             $pk = new BlockChangePacket();
             $pk->x = $packet->x;
             $pk->y = $packet->y;
             $pk->z = $packet->z;
             $pk->blockId = $packet->block;
             $pk->blockMeta = $packet->meta;
             return $pk;
         case Info::START_GAME_PACKET:
             $packets = [];
             $pk = new JoinGamePacket();
             $pk->eid = $packet->eid;
             $pk->gamemode = $player->getGamemode();
             $pk->dimension = 0;
             $pk->difficulty = $player->getServer()->getDifficulty();
             $pk->maxPlayers = $player->getServer()->getMaxPlayers();
             $pk->levelType = "default";
             $packets[] = $pk;
             $pk = new PlayerAbilitiesPacket();
             $pk->flyingSpeed = 0.05;
             $pk->walkingSpeed = 0.1;
             $pk->canFly = ($player->getGamemode() & 0x1) > 0;
             $pk->damageDisabled = ($player->getGamemode() & 0x1) > 0;
             $pk->isFlying = false;
             $pk->isCreative = ($player->getGamemode() & 0x1) > 0;
             if ($player->spawned === true) {
                 $packets = [$pk];
                 $pk = new ChangeGameStatePacket();
                 $pk->reason = 3;
                 $pk->value = $player->getGamemode();
                 $packets[] = $pk;
                 return $packets;
             } else {
                 $packets[] = $pk;
             }
             $pk = new SpawnPositionPacket();
             $pk->spawnX = $packet->spawnX;
             $pk->spawnY = $packet->spawnY;
             $pk->spawnZ = $packet->spawnZ;
             $packets[] = $pk;
             $pk = new PositionAndLookPacket();
             $pk->x = $packet->x;
             $pk->y = $packet->y;
             $pk->z = $packet->z;
             $pk->yaw = $player->yaw;
             $pk->pitch = $player->pitch;
             $pk->onGround = $player->isOnGround();
             $packets[] = $pk;
             return $packets;
         case Info::SET_HEALTH_PACKET:
             $pk = new UpdateHealthPacket();
             $pk->health = $packet->health;
             $pk->food = 20;
             $pk->saturation = 5;
             return $pk;
         case Info::TEXT_PACKET:
             $pk = new STCChatPacket();
             $pk->message = TextFormat::toJSON($packet->message);
             return $pk;
         case Info::SET_TIME_PACKET:
             $pk = new TimeUpdatePacket();
             $pk->age = $packet->time;
             $pk->time = $packet->time;
             //TODO: calculate offset from MCPE
             return $pk;
         case Info::SET_SPAWN_POSITION_PACKET:
             $pk = new SpawnPositionPacket();
             $pk->spawnX = $packet->x;
             $pk->spawnY = $packet->y;
             $pk->spawnZ = $packet->z;
             return $pk;
         case Info::REMOVE_ENTITY_PACKET:
         case Info::REMOVE_PLAYER_PACKET:
             $pk = new DestroyEntitiesPacket();
             $pk->ids[] = $packet->eid;
             return $pk;
         case Info::MOVE_PLAYER_PACKET:
             if ($packet->eid === 0) {
                 $pk = new PositionAndLookPacket();
                 $pk->x = $packet->x;
                 $pk->y = $packet->y;
                 $pk->z = $packet->z;
                 $pk->yaw = $packet->yaw;
                 $pk->pitch = $packet->pitch;
                 $pk->onGround = $player->isOnGround();
                 return $pk;
             } else {
                 $packets = [];
                 $pk = new EntityTeleportPacket();
                 $pk->eid = $packet->eid;
                 $pk->x = $packet->x;
                 $pk->y = $packet->y;
                 $pk->z = $packet->z;
                 $pk->yaw = $packet->yaw;
                 $pk->pitch = $packet->pitch;
                 $packets[] = $pk;
                 $pk = new EntityHeadLookPacket();
//.........这里部分代码省略.........
开发者ID:vibrocil,项目名称:BigBrother,代码行数:101,代码来源:Translator_20.php


注:本文中的pocketmine\utils\TextFormat::toJSON方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。