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
13
declare(strict_types=1);
14
15
namespace
pocketmine\network\mcpe\protocol;
16
17
use pmmp\encoding\Byte;
18
use pmmp\encoding\ByteBufferReader;
19
use pmmp\encoding\ByteBufferWriter;
20
use pmmp\encoding\VarInt;
21
use
pocketmine\network\mcpe\protocol\serializer\CommonTypes
;
22
use
function
count;
23
24
class
UpdateSoftEnumPacket
extends
DataPacket
implements
ClientboundPacket
{
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
}
pocketmine\network\mcpe\protocol\DataPacket
Definition
DataPacket.php:23
pocketmine\network\mcpe\protocol\UpdateSoftEnumPacket
Definition
UpdateSoftEnumPacket.php:24
pocketmine\network\mcpe\protocol\UpdateSoftEnumPacket\decodePayload
decodePayload(ByteBufferReader $in)
Definition
UpdateSoftEnumPacket.php:48
pocketmine\network\mcpe\protocol\UpdateSoftEnumPacket\encodePayload
encodePayload(ByteBufferWriter $out)
Definition
UpdateSoftEnumPacket.php:56
pocketmine\network\mcpe\protocol\UpdateSoftEnumPacket\create
static create(string $enumName, array $values, int $type)
Definition
UpdateSoftEnumPacket.php:40
pocketmine\network\mcpe\protocol\UpdateSoftEnumPacket\handle
handle(PacketHandlerInterface $handler)
Definition
UpdateSoftEnumPacket.php:65
pocketmine\network\mcpe\protocol\serializer\CommonTypes
Definition
CommonTypes.php:70
pocketmine\network\mcpe\protocol\ClientboundPacket
Definition
ClientboundPacket.php:17
pocketmine\network\mcpe\protocol\PacketHandlerInterface
Definition
PacketHandlerInterface.php:20
vendor
pocketmine
bedrock-protocol
src
UpdateSoftEnumPacket.php
Generated by
1.12.0