PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
UpdateSoftEnumPacket.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
22use function count;
23
25 public const NETWORK_ID = ProtocolInfo::UPDATE_SOFT_ENUM_PACKET;
26
27 public const TYPE_ADD = 0;
28 public const TYPE_REMOVE = 1;
29 public const TYPE_SET = 2;
30
31 public string $enumName;
33 public array $values = [];
34 public int $type;
35
40 public static function create(string $enumName, array $values, int $type) : self{
41 $result = new self;
42 $result->enumName = $enumName;
43 $result->values = $values;
44 $result->type = $type;
45 return $result;
46 }
47
48 protected function decodePayload(ByteBufferReader $in) : void{
49 $this->enumName = CommonTypes::getString($in);
50 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
51 $this->values[] = CommonTypes::getString($in);
52 }
53 $this->type = Byte::readUnsigned($in);
54 }
55
56 protected function encodePayload(ByteBufferWriter $out) : void{
57 CommonTypes::putString($out, $this->enumName);
58 VarInt::writeUnsignedInt($out, count($this->values));
59 foreach($this->values as $v){
60 CommonTypes::putString($out, $v);
61 }
62 Byte::writeUnsigned($out, $this->type);
63 }
64
65 public function handle(PacketHandlerInterface $handler) : bool{
66 return $handler->handleUpdateSoftEnum($this);
67 }
68}
static create(string $enumName, array $values, int $type)