PocketMine-MP 5.37.4 git-dbb3eefc44d5dddb20f540594fbda61467f50873
Loading...
Searching...
No Matches
UpdatePlayerGameTypePacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
22
24 public const NETWORK_ID = ProtocolInfo::UPDATE_PLAYER_GAME_TYPE_PACKET;
25
27 private int $gameMode;
28 private int $playerActorUniqueId;
29 private int $tick;
30
34 public static function create(int $gameMode, int $playerActorUniqueId, int $tick) : self{
35 $result = new self;
36 $result->gameMode = $gameMode;
37 $result->playerActorUniqueId = $playerActorUniqueId;
38 $result->tick = $tick;
39 return $result;
40 }
41
42 public function getGameMode() : int{ return $this->gameMode; }
43
44 public function getPlayerActorUniqueId() : int{ return $this->playerActorUniqueId; }
45
46 public function getTick() : int{ return $this->tick; }
47
48 protected function decodePayload(ByteBufferReader $in) : void{
49 $this->gameMode = VarInt::readSignedInt($in);
50 $this->playerActorUniqueId = CommonTypes::getActorUniqueId($in);
51 $this->tick = VarInt::readUnsignedLong($in);
52 }
53
54 protected function encodePayload(ByteBufferWriter $out) : void{
55 VarInt::writeSignedInt($out, $this->gameMode);
56 CommonTypes::putActorUniqueId($out, $this->playerActorUniqueId);
57 VarInt::writeUnsignedLong($out, $this->tick);
58 }
59
60 public function handle(PacketHandlerInterface $handler) : bool{
61 return $handler->handleUpdatePlayerGameType($this);
62 }
63}
static create(int $gameMode, int $playerActorUniqueId, int $tick)