PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
Loading...
Searching...
No Matches
SyncWorldClockMarkerData.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\LE;
20use pmmp\encoding\VarInt;
22
27 public function __construct(
28 private int $id,
29 private string $name,
30 private int $time,
31 private ?int $period
32 ){}
33
34 public function getId() : int{ return $this->id; }
35
36 public function getName() : string{ return $this->name; }
37
38 public function getTime() : int{ return $this->time; }
39
40 public function getPeriod() : ?int{ return $this->period; }
41
42 public static function read(ByteBufferReader $in) : self{
43 $id = VarInt::readUnsignedLong($in);
44 $name = CommonTypes::getString($in);
45 $time = VarInt::readSignedInt($in);
46 $period = CommonTypes::readOptional($in, LE::readSignedInt(...));
47
48 return new self(
49 $id,
50 $name,
51 $time,
52 $period
53 );
54 }
55
56 public function write(ByteBufferWriter $out) : void{
57 VarInt::writeUnsignedLong($out, $this->id);
58 CommonTypes::putString($out, $this->name);
59 VarInt::writeSignedInt($out, $this->time);
60 CommonTypes::writeOptional($out, $this->period, LE::writeSignedInt(...));
61 }
62}