PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
Loading...
Searching...
No Matches
SyncWorldClocksAddTimeMarker.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\types;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
20use function count;
21
26 public const ID = SyncWorldClocksType::ADD_TIME_MARKER;
27
32 public function __construct(
33 private int $clockId,
34 private array $markers,
35 ){}
36
37 public function getTypeId() : int{
38 return self::ID;
39 }
40
41 public function getClockId() : int{ return $this->clockId; }
42
47 public function getMarkers() : array{ return $this->markers; }
48
49 public static function read(ByteBufferReader $in) : self{
50 $clockId = VarInt::readUnsignedLong($in);
51
52 $markers = [];
53 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
54 $markers[] = SyncWorldClockMarkerData::read($in);
55 }
56
57 return new self(
58 $clockId,
59 $markers,
60 );
61 }
62
63 public function write(ByteBufferWriter $out) : void{
64 VarInt::writeUnsignedLong($out, $this->clockId);
65
66 VarInt::writeUnsignedInt($out, count($this->markers));
67 foreach($this->markers as $marker){
68 $marker->write($out);
69 }
70 }
71}