PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
Experiments.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\types;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
21use function count;
22
23final class Experiments{
28 public function __construct(
29 private array $experiments,
30 private bool $hasPreviouslyUsedExperiments
31 ){}
32
34 public function getExperiments() : array{ return $this->experiments; }
35
36 public function hasPreviouslyUsedExperiments() : bool{ return $this->hasPreviouslyUsedExperiments; }
37
38 public static function read(ByteBufferReader $in) : self{
39 $experiments = [];
40 for($i = 0, $len = LE::readUnsignedInt($in); $i < $len; ++$i){
41 $experimentName = CommonTypes::getString($in);
42 $enabled = CommonTypes::getBool($in);
43 $experiments[$experimentName] = $enabled;
44 }
45 $hasPreviouslyUsedExperiments = CommonTypes::getBool($in);
46 return new self($experiments, $hasPreviouslyUsedExperiments);
47 }
48
49 public function write(ByteBufferWriter $out) : void{
50 LE::writeUnsignedInt($out, count($this->experiments));
51 foreach($this->experiments as $experimentName => $enabled){
52 CommonTypes::putString($out, $experimentName);
53 CommonTypes::putBool($out, $enabled);
54 }
55 CommonTypes::putBool($out, $this->hasPreviouslyUsedExperiments);
56 }
57}
__construct(private array $experiments, private bool $hasPreviouslyUsedExperiments)