PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
SetDisplayObjectivePacket.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\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
21
23 public const NETWORK_ID = ProtocolInfo::SET_DISPLAY_OBJECTIVE_PACKET;
24
25 public const DISPLAY_SLOT_LIST = "list";
26 public const DISPLAY_SLOT_SIDEBAR = "sidebar";
27 public const DISPLAY_SLOT_BELOW_NAME = "belowname";
28
29 public const SORT_ORDER_ASCENDING = 0;
30 public const SORT_ORDER_DESCENDING = 1;
31
32 public string $displaySlot;
33 public string $objectiveName;
34 public string $displayName;
35 public string $criteriaName;
36 public int $sortOrder;
37
41 public static function create(string $displaySlot, string $objectiveName, string $displayName, string $criteriaName, int $sortOrder) : self{
42 $result = new self;
43 $result->displaySlot = $displaySlot;
44 $result->objectiveName = $objectiveName;
45 $result->displayName = $displayName;
46 $result->criteriaName = $criteriaName;
47 $result->sortOrder = $sortOrder;
48 return $result;
49 }
50
51 protected function decodePayload(ByteBufferReader $in) : void{
52 $this->displaySlot = CommonTypes::getString($in);
53 $this->objectiveName = CommonTypes::getString($in);
54 $this->displayName = CommonTypes::getString($in);
55 $this->criteriaName = CommonTypes::getString($in);
56 $this->sortOrder = VarInt::readSignedInt($in);
57 }
58
59 protected function encodePayload(ByteBufferWriter $out) : void{
60 CommonTypes::putString($out, $this->displaySlot);
61 CommonTypes::putString($out, $this->objectiveName);
62 CommonTypes::putString($out, $this->displayName);
63 CommonTypes::putString($out, $this->criteriaName);
64 VarInt::writeSignedInt($out, $this->sortOrder);
65 }
66
67 public function handle(PacketHandlerInterface $handler) : bool{
68 return $handler->handleSetDisplayObjective($this);
69 }
70}
static create(string $displaySlot, string $objectiveName, string $displayName, string $criteriaName, int $sortOrder)