PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
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
18use function count;
19
20final class Experiments{
25 public function __construct(
26 private array $experiments,
27 private bool $hasPreviouslyUsedExperiments
28 ){}
29
31 public function getExperiments() : array{ return $this->experiments; }
32
33 public function hasPreviouslyUsedExperiments() : bool{ return $this->hasPreviouslyUsedExperiments; }
34
35 public static function read(PacketSerializer $in) : self{
36 $experiments = [];
37 for($i = 0, $len = $in->getLInt(); $i < $len; ++$i){
38 $experimentName = $in->getString();
39 $enabled = $in->getBool();
40 $experiments[$experimentName] = $enabled;
41 }
42 $hasPreviouslyUsedExperiments = $in->getBool();
43 return new self($experiments, $hasPreviouslyUsedExperiments);
44 }
45
46 public function write(PacketSerializer $out) : void{
47 $out->putLInt(count($this->experiments));
48 foreach($this->experiments as $experimentName => $enabled){
49 $out->putString($experimentName);
50 $out->putBool($enabled);
51 }
52 $out->putBool($this->hasPreviouslyUsedExperiments);
53 }
54}
__construct(private array $experiments, private bool $hasPreviouslyUsedExperiments)