PocketMine-MP 5.36.1 git-eaa7c4834c8fe2f379d24e7f0ee6cc63cfb18ccc
Loading...
Searching...
No Matches
CommandSoftEnum.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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
21use function count;
22
23final class CommandSoftEnum{
24
29 public function __construct(
30 private string $name,
31 private array $values
32 ){
33 self::stringArrayCheck(...$this->values);
34 }
35
36 private static function stringArrayCheck(string ...$values) : void{
37 //NOOP
38 }
39
40 public function getName() : string{ return $this->name; }
41
46 public function getValues() : array{ return $this->values; }
47
48 public static function read(ByteBufferReader $in) : self{
49 $name = CommonTypes::getString($in);
50
51 $values = [];
52 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
53 $values[] = CommonTypes::getString($in);
54 }
55
56 return new self($name, $values);
57 }
58
59 public function write(ByteBufferWriter $out) : void{
60 CommonTypes::putString($out, $this->name);
61
62 VarInt::writeUnsignedInt($out, count($this->values));
63 foreach($this->values as $value){
64 CommonTypes::putString($out, $value);
65 }
66 }
67}
__construct(private string $name, private array $values)