PocketMine-MP 5.44.4 git-bc94a0da0c87abe7eb99d229a9ec672b3c405d11
Loading...
Searching...
No Matches
DataStoreChange.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\ddui;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
23use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
24
28final class DataStoreChange implements DataStoreOperation{
29 use GetTypeIdFromConstTrait;
30
31 public const ID = DataStoreOperationType::CHANGE;
32
33 public function __construct(
34 private string $name,
35 private string $property,
36 private int $updateCount,
37 private ?DynamicValue $data
38 ){}
39
40 public function getName() : string{ return $this->name; }
41
42 public function getProperty() : string{ return $this->property; }
43
44 public function getUpdateCount() : int{ return $this->updateCount; }
45
46 public function getData() : ?DynamicValue{ return $this->data; }
47
48 public static function read(ByteBufferReader $in) : self{
49 $name = CommonTypes::getString($in);
50 $property = CommonTypes::getString($in);
51 $updateCount = LE::readUnsignedInt($in);
52
53 $type = LE::readUnsignedInt($in);
54 $data = DynamicValue::read($in, $type);
55
56 return new self(
57 $name,
58 $property,
59 $updateCount,
60 $data,
61 );
62 }
63
64 public function write(ByteBufferWriter $out) : void{
65 CommonTypes::putString($out, $this->name);
66 CommonTypes::putString($out, $this->property);
67 LE::writeUnsignedInt($out, $this->updateCount);
68
69 //TODO: yucky, we really need to revamp how unions are handled :(
70 $type = $this->data?->getTypeId() ?? DynamicValueType::NULL;
71 LE::writeUnsignedInt($out, $type);
72 $this->data?->write($out);
73 }
74}