PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
Loading...
Searching...
No Matches
SyncWorldClockData.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;
21use function count;
22
27
32 public function __construct(
33 private int $id,
34 private string $name,
35 private int $time,
36 private bool $paused,
37 private array $markers
38 ){}
39
40 public function getId() : int{ return $this->id; }
41
42 public function getName() : string{ return $this->name; }
43
44 public function getTime() : int{ return $this->time; }
45
46 public function isPaused() : bool{ return $this->paused; }
47
52 public function getMarkers() : array{ return $this->markers; }
53
54 public static function read(ByteBufferReader $in) : self{
55 $id = VarInt::readUnsignedLong($in);
56 $name = CommonTypes::getString($in);
57 $time = VarInt::readSignedInt($in);
58 $paused = CommonTypes::getBool($in);
59
60 $markers = [];
61 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
62 $markers[] = SyncWorldClockMarkerData::read($in);
63 }
64
65 return new self(
66 $id,
67 $name,
68 $time,
69 $paused,
70 $markers
71 );
72 }
73
74 public function write(ByteBufferWriter $out) : void{
75 VarInt::writeUnsignedLong($out, $this->id);
76 CommonTypes::putString($out, $this->name);
77 VarInt::writeSignedInt($out, $this->time);
78 CommonTypes::putBool($out, $this->paused);
79
80 VarInt::writeUnsignedInt($out, count($this->markers));
81 foreach($this->markers as $marker){
82 $marker->write($out);
83 }
84 }
85}
__construct(private int $id, private string $name, private int $time, private bool $paused, private array $markers)