PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
Loading...
Searching...
No Matches
CommandParameter.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;
16
18
20 public const FLAG_FORCE_COLLAPSE_ENUM = 0x1;
21 public const FLAG_HAS_ENUM_CONSTRAINT = 0x2;
22
23 public string $paramName;
24 public int $paramType;
25 public bool $isOptional;
26 public int $flags = 0; //shows enum name if 1, always zero except for in /gamerule command
27 public ?CommandEnum $enum = null;
28 public ?string $postfix = null;
29
30 private static function baseline(string $name, int $type, int $flags, bool $optional) : self{
31 $result = new self;
32 $result->paramName = $name;
33 $result->paramType = $type;
34 $result->flags = $flags;
35 $result->isOptional = $optional;
36 return $result;
37 }
38
39 public static function standard(string $name, int $type, int $flags = 0, bool $optional = false) : self{
40 return self::baseline($name, AvailableCommandsPacket::ARG_FLAG_VALID | $type, $flags, $optional);
41 }
42
43 public static function postfixed(string $name, string $postfix, int $flags = 0, bool $optional = false) : self{
44 $result = self::baseline($name, AvailableCommandsPacket::ARG_FLAG_POSTFIX, $flags, $optional);
45 $result->postfix = $postfix;
46 return $result;
47 }
48
49 public static function enum(string $name, CommandEnum $enum, int $flags, bool $optional = false) : self{
50 $result = self::baseline($name, AvailableCommandsPacket::ARG_FLAG_ENUM | AvailableCommandsPacket::ARG_FLAG_VALID, $flags, $optional);
51 $result->enum = $enum;
52 return $result;
53 }
54}