PocketMine-MP 5.42.2 git-88c18cd9cf7fc37bd5261e6f29ed6041bfe776f1
Loading...
Searching...
No Matches
SyncWorldClocksPacket.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;
25
27 public const NETWORK_ID = ProtocolInfo::SYNC_WORLD_CLOCKS_PACKET;
28
29 private SyncWorldClocksPayload $payload;
30
34 public static function create(SyncWorldClocksPayload $payload) : self{
35 $result = new self;
36 $result->payload = $payload;
37 return $result;
38 }
39
40 public function getPayload() : SyncWorldClocksPayload{ return $this->payload; }
41
42 protected function decodePayload(ByteBufferReader $in) : void{
43 $this->payload = match(VarInt::readUnsignedInt($in)){
44 SyncWorldClocksSyncState::ID => SyncWorldClocksSyncState::read($in),
45 SyncWorldClocksInitializeRegistry::ID => SyncWorldClocksInitializeRegistry::read($in),
46 SyncWorldClocksAddTimeMarker::ID => SyncWorldClocksAddTimeMarker::read($in),
47 SyncWorldClocksRemoveTimeMarker::ID => SyncWorldClocksRemoveTimeMarker::read($in),
48 default => throw new PacketDecodeException("Unknown SyncWorldClocks type"),
49 };
50 }
51
52 protected function encodePayload(ByteBufferWriter $out) : void{
53 VarInt::writeUnsignedInt($out, $this->payload->getTypeId());
54 $this->payload->write($out);
55 }
56
57 public function handle(PacketHandlerInterface $handler) : bool{
58 return $handler->handleSyncWorldClocks($this);
59 }
60}