PocketMine-MP 5.15.1 git-08c6e63aac45a450fe3b437616ee8aa2500e04e2
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
18use function count;
19
21 public const NETWORK_ID = ProtocolInfo::UPDATE_SOFT_ENUM_PACKET;
22
23 public const TYPE_ADD = 0;
24 public const TYPE_REMOVE = 1;
25 public const TYPE_SET = 2;
26
27 public string $enumName;
29 public array $values = [];
30 public int $type;
31
36 public static function create(string $enumName, array $values, int $type) : self{
37 $result = new self;
38 $result->enumName = $enumName;
39 $result->values = $values;
40 $result->type = $type;
41 return $result;
42 }
43
44 protected function decodePayload(PacketSerializer $in) : void{
45 $this->enumName = $in->getString();
46 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
47 $this->values[] = $in->getString();
48 }
49 $this->type = $in->getByte();
50 }
51
52 protected function encodePayload(PacketSerializer $out) : void{
53 $out->putString($this->enumName);
54 $out->putUnsignedVarInt(count($this->values));
55 foreach($this->values as $v){
56 $out->putString($v);
57 }
58 $out->putByte($this->type);
59 }
60
61 public function handle(PacketHandlerInterface $handler) : bool{
62 return $handler->handleUpdateSoftEnum($this);
63 }
64}
static create(string $enumName, array $values, int $type)