PocketMine-MP 5.41.1 git-fcc6fb5566a921cb669160c90f56fb68f5b29123
Loading...
Searching...
No Matches
DataStoreUpdate.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;
23
27final class DataStoreUpdate extends DataStore{
28 public const ID = DataStoreType::UPDATE;
29
30 public function __construct(
31 private string $name,
32 private string $property,
33 private string $path,
34 private DataStoreValue $data,
35 private int $updateCount,
36 private int $pathUpdateCount,
37 ){}
38
39 public function getTypeId() : int{
40 return self::ID;
41 }
42
43 public function getName() : string{ return $this->name; }
44
45 public function getProperty() : string{ return $this->property; }
46
47 public function getPath() : string{ return $this->path; }
48
49 public function getData() : DataStoreValue{ return $this->data; }
50
51 public function getUpdateCount() : int{ return $this->updateCount; }
52
53 public function getPathUpdateCount() : int{ return $this->pathUpdateCount; }
54
55 public static function read(ByteBufferReader $in) : self{
56 $name = CommonTypes::getString($in);
57 $property = CommonTypes::getString($in);
58 $path = CommonTypes::getString($in);
59
60 $data = match(VarInt::readUnsignedInt($in)){
61 DataStoreValueType::DOUBLE => DoubleDataStoreValue::read($in),
62 DataStoreValueType::BOOL => BoolDataStoreValue::read($in),
63 DataStoreValueType::STRING => StringDataStoreValue::read($in),
64 default => throw new PacketDecodeException("Unknown DataStoreValueType"),
65 };
66
67 $updateCount = LE::readUnsignedInt($in);
68 $pathUpdateCount = LE::readUnsignedInt($in);
69
70 return new self(
71 $name,
72 $property,
73 $path,
74 $data,
75 $updateCount,
76 $pathUpdateCount,
77 );
78 }
79
80 public function write(ByteBufferWriter $out) : void{
81 CommonTypes::putString($out, $this->name);
82 CommonTypes::putString($out, $this->property);
83 CommonTypes::putString($out, $this->path);
84 VarInt::writeUnsignedInt($out, $this->data->getTypeId());
85 $this->data->write($out);
86 LE::writeUnsignedInt($out, $this->updateCount);
87 LE::writeUnsignedInt($out, $this->pathUpdateCount);
88 }
89}