PocketMine-MP 5.36.1 git-eaa7c4834c8fe2f379d24e7f0ee6cc63cfb18ccc
Loading...
Searching...
No Matches
CommandRawData.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\command\raw;
16
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
21use pmmp\encoding\VarInt;
23use function count;
24
25final class CommandRawData{
26
33 public function __construct(
34 private string $name,
35 private string $description,
36 private int $flags,
37 private int $permission,
38 private int $aliasEnumIndex,
39 private array $chainedSubCommandDataIndexes,
40 private array $overloads,
41 ){}
42
43 public function getName() : string{ return $this->name; }
44
45 public function getDescription() : string{ return $this->description; }
46
47 public function getFlags() : int{ return $this->flags; }
48
49 public function getPermission() : int{ return $this->permission; }
50
51 public function getAliasEnumIndex() : int{ return $this->aliasEnumIndex; }
52
57 public function getChainedSubCommandDataIndexes() : array{ return $this->chainedSubCommandDataIndexes; }
58
63 public function getOverloads() : array{ return $this->overloads; }
64
65 public static function read(ByteBufferReader $in) : self{
66 $name = CommonTypes::getString($in);
67 $description = CommonTypes::getString($in);
68 $flags = LE::readUnsignedShort($in);
69 $permission = Byte::readUnsigned($in);
70 $aliasEnumIndex = LE::readSignedInt($in); //may be -1 for not set
71
72 $chainedSubCommandDataIndexes = [];
73 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
74 $chainedSubCommandDataIndexes[] = LE::readUnsignedShort($in);
75 }
76
77 $overloads = [];
78 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
79 $overloads[] = CommandOverloadRawData::read($in);
80 }
81
82 return new self(
83 name: $name,
84 description: $description,
85 flags: $flags,
86 permission: $permission,
87 aliasEnumIndex: $aliasEnumIndex,
88 chainedSubCommandDataIndexes: $chainedSubCommandDataIndexes,
89 overloads: $overloads
90 );
91 }
92
93 public function write(ByteBufferWriter $out) : void{
94 CommonTypes::putString($out, $this->name);
95 CommonTypes::putString($out, $this->description);
96 LE::writeUnsignedShort($out, $this->flags);
97 Byte::writeUnsigned($out, $this->permission);
98 LE::writeSignedInt($out, $this->aliasEnumIndex);
99
100 VarInt::writeUnsignedInt($out, count($this->chainedSubCommandDataIndexes));
101 foreach($this->chainedSubCommandDataIndexes as $index){
102 LE::writeUnsignedShort($out, $index);
103 }
104
105 VarInt::writeUnsignedInt($out, count($this->overloads));
106 foreach($this->overloads as $overload){
107 $overload->write($out);
108 }
109 }
110}
__construct(private string $name, private string $description, private int $flags, private int $permission, private int $aliasEnumIndex, private array $chainedSubCommandDataIndexes, private array $overloads,)