PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
NpcDialoguePacket.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
18
20 public const NETWORK_ID = ProtocolInfo::NPC_DIALOGUE_PACKET;
21
22 public const ACTION_OPEN = 0;
23 public const ACTION_CLOSE = 1;
24
25 private int $npcActorUniqueId;
26 private int $actionType;
27 private string $dialogue;
28 private string $sceneName;
29 private string $npcName;
30 private string $actionJson;
31
35 public static function create(int $npcActorUniqueId, int $actionType, string $dialogue, string $sceneName, string $npcName, string $actionJson) : self{
36 $result = new self;
37 $result->npcActorUniqueId = $npcActorUniqueId;
38 $result->actionType = $actionType;
39 $result->dialogue = $dialogue;
40 $result->sceneName = $sceneName;
41 $result->npcName = $npcName;
42 $result->actionJson = $actionJson;
43 return $result;
44 }
45
46 public function getNpcActorUniqueId() : int{ return $this->npcActorUniqueId; }
47
48 public function getActionType() : int{ return $this->actionType; }
49
50 public function getDialogue() : string{ return $this->dialogue; }
51
52 public function getSceneName() : string{ return $this->sceneName; }
53
54 public function getNpcName() : string{ return $this->npcName; }
55
56 public function getActionJson() : string{ return $this->actionJson; }
57
58 protected function decodePayload(PacketSerializer $in) : void{
59 $this->npcActorUniqueId = $in->getLLong(); //WHY NOT USING STANDARD METHODS, MOJANG
60 $this->actionType = $in->getVarInt();
61 $this->dialogue = $in->getString();
62 $this->sceneName = $in->getString();
63 $this->npcName = $in->getString();
64 $this->actionJson = $in->getString();
65 }
66
67 protected function encodePayload(PacketSerializer $out) : void{
68 $out->putLLong($this->npcActorUniqueId);
69 $out->putVarInt($this->actionType);
70 $out->putString($this->dialogue);
71 $out->putString($this->sceneName);
72 $out->putString($this->npcName);
73 $out->putString($this->actionJson);
74 }
75
76 public function handle(PacketHandlerInterface $handler) : bool{
77 return $handler->handleNpcDialogue($this);
78 }
79}
static create(int $npcActorUniqueId, int $actionType, string $dialogue, string $sceneName, string $npcName, string $actionJson)