PocketMine-MP 5.39.3 git-66148f13a91e4af6778ba9f200ca25ad8a04a584
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 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
192 $this->enums[] = CommandEnumRawData::read($in);
193 }
194
195 $this->chainedSubCommandData = [];
196 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
197 $this->chainedSubCommandData[] = ChainedSubCommandRawData::read($in);
198 }
199
200 $this->commandData = [];
201 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
202 $this->commandData[] = CommandRawData::read($in);
203 }
204
205 $this->softEnums = [];
206 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
207 $this->softEnums[] = CommandSoftEnum::read($in);
208 }
209
210 $this->enumConstraints = [];
211 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
212 $this->enumConstraints[] = CommandEnumConstraintRawData::read($in);
213 }
214 }
215
216 protected function encodePayload(ByteBufferWriter $out) : void{
217 VarInt::writeUnsignedInt($out, count($this->enumValues));
218 foreach($this->enumValues as $value){
219 CommonTypes::putString($out, $value);
220 }
221
222 VarInt::writeUnsignedInt($out, count($this->chainedSubCommandValues));
223 foreach($this->chainedSubCommandValues as $value){
224 CommonTypes::putString($out, $value);
225 }
226
227 VarInt::writeUnsignedInt($out, count($this->postfixes));
228 foreach($this->postfixes as $postfix){
229 CommonTypes::putString($out, $postfix);
230 }
231
232 VarInt::writeUnsignedInt($out, count($this->enums));
233 foreach($this->enums as $enum){
234 $enum->write($out);
235 }
236
237 VarInt::writeUnsignedInt($out, count($this->chainedSubCommandData));
238 foreach($this->chainedSubCommandData as $data){
239 $data->write($out);
240 }
241
242 VarInt::writeUnsignedInt($out, count($this->commandData));
243 foreach($this->commandData as $data){
244 $data->write($out);
245 }
246
247 VarInt::writeUnsignedInt($out, count($this->softEnums));
248 foreach($this->softEnums as $softEnum){
249 $softEnum->write($out);
250 }
251
252 VarInt::writeUnsignedInt($out, count($this->enumConstraints));
253 foreach($this->enumConstraints as $constraint){
254 $constraint->write($out);
255 }
256 }
257
258 public function handle(PacketHandlerInterface $handler) : bool{
259 return $handler->handleAvailableCommands($this);
260 }
261}
static create(array $enumValues, array $chainedSubCommandValues, array $postfixes, array $enums, array $chainedSubCommandData, array $commandData, array $softEnums, array $enumConstraints,)