PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
21use function count;
22
23final class AbilitiesData{
28 public function __construct(
29 private int $commandPermission,
30 private int $playerPermission,
31 private int $targetActorUniqueId, //This is a little-endian long, NOT a var-long. (WTF Mojang)
32 private array $abilityLayers
33 ){}
34
35 public function getCommandPermission() : int{ return $this->commandPermission; }
36
37 public function getPlayerPermission() : int{ return $this->playerPermission; }
38
39 public function getTargetActorUniqueId() : int{ return $this->targetActorUniqueId; }
40
45 public function getAbilityLayers() : array{ return $this->abilityLayers; }
46
47 public static function decode(ByteBufferReader $in) : self{
48 $targetActorUniqueId = LE::readSignedLong($in); //WHY IS THIS NON-STANDARD?
49 $playerPermission = Byte::readUnsigned($in);
50 $commandPermission = Byte::readUnsigned($in);
51
52 $abilityLayers = [];
53 for($i = 0, $len = Byte::readUnsigned($in); $i < $len; $i++){
54 $abilityLayers[] = AbilitiesLayer::decode($in);
55 }
56
57 return new self($commandPermission, $playerPermission, $targetActorUniqueId, $abilityLayers);
58 }
59
60 public function encode(ByteBufferWriter $out) : void{
61 LE::writeSignedLong($out, $this->targetActorUniqueId);
62 Byte::writeUnsigned($out, $this->playerPermission);
63 Byte::writeUnsigned($out, $this->commandPermission);
64
65 Byte::writeUnsigned($out, count($this->abilityLayers));
66 foreach($this->abilityLayers as $abilityLayer){
67 $abilityLayer->encode($out);
68 }
69 }
70}
__construct(private int $commandPermission, private int $playerPermission, private int $targetActorUniqueId, private array $abilityLayers)