PocketMine-MP 5.36.1 git-eaa7c4834c8fe2f379d24e7f0ee6cc63cfb18ccc
Loading...
Searching...
No Matches
AvailableCommandsPacket.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;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
29use function count;
30
39 public const NETWORK_ID = ProtocolInfo::AVAILABLE_COMMANDS_PACKET;
40
45 public const ARG_FLAG_VALID = 0x100000;
46
51 public const ARG_TYPE_INT = ArgTypes::INT;
52 public const ARG_TYPE_FLOAT = ArgTypes::VAL;
53 public const ARG_TYPE_VALUE = ArgTypes::RVAL;
54 public const ARG_TYPE_WILDCARD_INT = ArgTypes::WILDCARDINT;
55 public const ARG_TYPE_OPERATOR = ArgTypes::OPERATOR;
56 public const ARG_TYPE_COMPARE_OPERATOR = ArgTypes::COMPAREOPERATOR;
57 public const ARG_TYPE_TARGET = ArgTypes::SELECTION;
58
59 public const ARG_TYPE_WILDCARD_TARGET = ArgTypes::WILDCARDSELECTION;
60
61 public const ARG_TYPE_FILEPATH = ArgTypes::PATHCOMMAND;
62
63 public const ARG_TYPE_FULL_INTEGER_RANGE = ArgTypes::FULLINTEGERRANGE;
64
65 public const ARG_TYPE_EQUIPMENT_SLOT = ArgTypes::EQUIPMENTSLOTENUM;
66 public const ARG_TYPE_STRING = ArgTypes::ID;
67
68 public const ARG_TYPE_INT_POSITION = ArgTypes::POSITION;
69 public const ARG_TYPE_POSITION = ArgTypes::POSITION_FLOAT;
70
71 public const ARG_TYPE_MESSAGE = ArgTypes::MESSAGE_ROOT;
72
73 public const ARG_TYPE_RAWTEXT = ArgTypes::RAWTEXT;
74
75 public const ARG_TYPE_JSON = ArgTypes::JSON_OBJECT;
76
77 public const ARG_TYPE_BLOCK_STATES = ArgTypes::BLOCK_STATE_ARRAY;
78
79 public const ARG_TYPE_COMMAND = ArgTypes::CODEBUILDERARGS;
80
85 public const ARG_FLAG_ENUM = 0x200000;
86
88 public const ARG_FLAG_POSTFIX = 0x1000000;
89
90 public const ARG_FLAG_SOFT_ENUM = 0x4000000;
91
96 public array $enumValues = [];
101 public array $chainedSubCommandValues = [];
106 public array $postfixes = [];
111 public array $enums = [];
116 public array $chainedSubCommandData = [];
121 public array $commandData = [];
126 public array $softEnums = [];
131 public array $enumConstraints = [];
132
152 public static function create(
153 array $enumValues,
154 array $chainedSubCommandValues,
155 array $postfixes,
156 array $enums,
157 array $chainedSubCommandData,
158 array $commandData,
159 array $softEnums,
160 array $enumConstraints,
161 ) : self{
162 $result = new self;
163 $result->enumValues = $enumValues;
164 $result->chainedSubCommandValues = $chainedSubCommandValues;
165 $result->postfixes = $postfixes;
166 $result->enums = $enums;
167 $result->chainedSubCommandData = $chainedSubCommandData;
168 $result->commandData = $commandData;
169 $result->softEnums = $softEnums;
170 $result->enumConstraints = $enumConstraints;
171 return $result;
172 }
173
174 protected function decodePayload(ByteBufferReader $in) : void{
175 $this->enumValues = [];
176 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
177 $this->enumValues[] = CommonTypes::getString($in);
178 }
179
180 $this->chainedSubCommandValues = [];
181 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
182 $this->chainedSubCommandValues[] = CommonTypes::getString($in);
183 }
184
185 $this->postfixes = [];
186 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
187 $this->postfixes[] = CommonTypes::getString($in);
188 }
189
190 $this->enums = [];
191 $valueListSize = count($this->enumValues);
192 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
193 $this->enums[] = CommandEnumRawData::read($in, $valueListSize);
194 }
195
196 $this->chainedSubCommandData = [];
197 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
198 $this->chainedSubCommandData[] = ChainedSubCommandRawData::read($in);
199 }
200
201 $this->commandData = [];
202 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
203 $this->commandData[] = CommandRawData::read($in);
204 }
205
206 $this->softEnums = [];
207 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
208 $this->softEnums[] = CommandSoftEnum::read($in);
209 }
210
211 $this->enumConstraints = [];
212 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
213 $this->enumConstraints[] = CommandEnumConstraintRawData::read($in);
214 }
215 }
216
217 protected function encodePayload(ByteBufferWriter $out) : void{
218 VarInt::writeUnsignedInt($out, count($this->enumValues));
219 foreach($this->enumValues as $value){
220 CommonTypes::putString($out, $value);
221 }
222
223 VarInt::writeUnsignedInt($out, count($this->chainedSubCommandValues));
224 foreach($this->chainedSubCommandValues as $value){
225 CommonTypes::putString($out, $value);
226 }
227
228 VarInt::writeUnsignedInt($out, count($this->postfixes));
229 foreach($this->postfixes as $postfix){
230 CommonTypes::putString($out, $postfix);
231 }
232
233 VarInt::writeUnsignedInt($out, count($this->enums));
234 $valueListSize = count($this->enumValues);
235 foreach($this->enums as $enum){
236 $enum->write($out, $valueListSize);
237 }
238
239 VarInt::writeUnsignedInt($out, count($this->chainedSubCommandData));
240 foreach($this->chainedSubCommandData as $data){
241 $data->write($out);
242 }
243
244 VarInt::writeUnsignedInt($out, count($this->commandData));
245 foreach($this->commandData as $data){
246 $data->write($out);
247 }
248
249 VarInt::writeUnsignedInt($out, count($this->softEnums));
250 foreach($this->softEnums as $softEnum){
251 $softEnum->write($out);
252 }
253
254 VarInt::writeUnsignedInt($out, count($this->enumConstraints));
255 foreach($this->enumConstraints as $constraint){
256 $constraint->write($out);
257 }
258 }
259
260 public function handle(PacketHandlerInterface $handler) : bool{
261 return $handler->handleAvailableCommands($this);
262 }
263}
static create(array $enumValues, array $chainedSubCommandValues, array $postfixes, array $enums, array $chainedSubCommandData, array $commandData, array $softEnums, array $enumConstraints,)