PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
AbilitiesData.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 AbilitiesData{
25 public function __construct(
26 private int $commandPermission,
27 private int $playerPermission,
28 private int $targetActorUniqueId, //This is a little-endian long, NOT a var-long. (WTF Mojang)
29 private array $abilityLayers
30 ){}
31
32 public function getCommandPermission() : int{ return $this->commandPermission; }
33
34 public function getPlayerPermission() : int{ return $this->playerPermission; }
35
36 public function getTargetActorUniqueId() : int{ return $this->targetActorUniqueId; }
37
42 public function getAbilityLayers() : array{ return $this->abilityLayers; }
43
44 public static function decode(PacketSerializer $in) : self{
45 $targetActorUniqueId = $in->getLLong(); //WHY IS THIS NON-STANDARD?
46 $playerPermission = $in->getByte();
47 $commandPermission = $in->getByte();
48
49 $abilityLayers = [];
50 for($i = 0, $len = $in->getByte(); $i < $len; $i++){
51 $abilityLayers[] = AbilitiesLayer::decode($in);
52 }
53
54 return new self($commandPermission, $playerPermission, $targetActorUniqueId, $abilityLayers);
55 }
56
57 public function encode(PacketSerializer $out) : void{
58 $out->putLLong($this->targetActorUniqueId);
59 $out->putByte($this->playerPermission);
60 $out->putByte($this->commandPermission);
61
62 $out->putByte(count($this->abilityLayers));
63 foreach($this->abilityLayers as $abilityLayer){
64 $abilityLayer->encode($out);
65 }
66 }
67}
__construct(private int $commandPermission, private int $playerPermission, private int $targetActorUniqueId, private array $abilityLayers)