PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
Loading...
Searching...
No Matches
TransactionData.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\inventory;
16
20use function count;
21
22abstract class TransactionData{
24 protected array $actions = [];
25
29 final public function getActions() : array{
30 return $this->actions;
31 }
32
33 abstract public function getTypeId() : int;
34
39 final public function decode(PacketSerializer $stream) : void{
40 $actionCount = $stream->getUnsignedVarInt();
41 for($i = 0; $i < $actionCount; ++$i){
42 $this->actions[] = (new NetworkInventoryAction())->read($stream);
43 }
44 $this->decodeData($stream);
45 }
46
51 abstract protected function decodeData(PacketSerializer $stream) : void;
52
53 final public function encode(PacketSerializer $stream) : void{
54 $stream->putUnsignedVarInt(count($this->actions));
55 foreach($this->actions as $action){
56 $action->write($stream);
57 }
58 $this->encodeData($stream);
59 }
60
61 abstract protected function encodeData(PacketSerializer $stream) : void;
62}