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