PocketMine-MP 5.43.2 git-a137a986d01d9af23452b2e741699a770c7ae112
Loading...
Searching...
No Matches
UpdateClientOptionsPacket.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;
21use pocketmine\network\mcpe\protocol\types\GraphicsMode;
22
24 public const NETWORK_ID = ProtocolInfo::UPDATE_CLIENT_OPTIONS_PACKET;
25
26 private ?GraphicsMode $graphicsMode;
27 private ?bool $filterProfanityChange;
28
32 public static function create(?GraphicsMode $graphicsMode, ?bool $filterProfanityChange) : self{
33 $result = new self;
34 $result->graphicsMode = $graphicsMode;
35 $result->filterProfanityChange = $filterProfanityChange;
36 return $result;
37 }
38
39 public function getGraphicsMode() : ?GraphicsMode{ return $this->graphicsMode; }
40
41 public function getFilterProfanityChange() : ?bool{ return $this->filterProfanityChange; }
42
43 protected function decodePayload(ByteBufferReader $in) : void{
44 $this->graphicsMode = CommonTypes::readOptional($in, fn() => GraphicsMode::fromPacket(Byte::readUnsigned($in)));
45 $this->filterProfanityChange = CommonTypes::readOptional($in, CommonTypes::getBool(...));
46 }
47
48 protected function encodePayload(ByteBufferWriter $out) : void{
49 CommonTypes::writeOptional($out, $this->graphicsMode, fn(ByteBufferWriter $out, GraphicsMode $v) => Byte::writeUnsigned($out, $v->value));
50 CommonTypes::writeOptional($out, $this->filterProfanityChange, CommonTypes::putBool(...));
51 }
52
53 public function handle(PacketHandlerInterface $handler) : bool{
54 return $handler->handleUpdateClientOptions($this);
55 }
56}
static create(?GraphicsMode $graphicsMode, ?bool $filterProfanityChange)