PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
ServerboundPackSettingChangePacket.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\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
24use pocketmine\network\mcpe\protocol\types\PackSettingType;
26use Ramsey\Uuid\UuidInterface;
27
29 public const NETWORK_ID = ProtocolInfo::SERVERBOUND_PACK_SETTING_CHANGE_PACKET;
30
31 private UuidInterface $packId;
32 private PackSetting $packSetting;
33
37 public static function create(UuidInterface $packId, PackSetting $packSetting) : self{
38 $result = new self;
39 $result->packId = $packId;
40 $result->packSetting = $packSetting;
41 return $result;
42 }
43
44 public function getPackId() : UuidInterface{ return $this->packId; }
45
46 public function getPackSetting() : PackSetting{ return $this->packSetting; }
47
48 protected function decodePayload(ByteBufferReader $in) : void{
49 $this->packId = CommonTypes::getUUID($in);
50
51 $name = CommonTypes::getString($in);
52 $typeId = PackSettingType::from(VarInt::readUnsignedInt($in));
53 $this->packSetting = match($typeId){
54 PackSettingType::FLOAT => FloatPackSetting::read($in, $name),
55 PackSettingType::BOOL => BoolPackSetting::read($in, $name),
56 PackSettingType::STRING => StringPackSetting::read($in, $name),
57 };
58 }
59
60 protected function encodePayload(ByteBufferWriter $out) : void{
61 CommonTypes::putUUID($out, $this->packId);
62 CommonTypes::putString($out, $this->packSetting->getName());
63 VarInt::writeUnsignedInt($out, $this->packSetting->getTypeId()->value);
64 $this->packSetting->write($out);
65 }
66
67 public function handle(PacketHandlerInterface $handler) : bool{
68 return $handler->handleServerboundPackSettingChange($this);
69 }
70}