PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
22
24 public const NETWORK_ID = ProtocolInfo::NPC_DIALOGUE_PACKET;
25
26 public const ACTION_OPEN = 0;
27 public const ACTION_CLOSE = 1;
28
29 private int $npcActorUniqueId;
30 private int $actionType;
31 private string $dialogue;
32 private string $sceneName;
33 private string $npcName;
34 private string $actionJson;
35
39 public static function create(int $npcActorUniqueId, int $actionType, string $dialogue, string $sceneName, string $npcName, string $actionJson) : self{
40 $result = new self;
41 $result->npcActorUniqueId = $npcActorUniqueId;
42 $result->actionType = $actionType;
43 $result->dialogue = $dialogue;
44 $result->sceneName = $sceneName;
45 $result->npcName = $npcName;
46 $result->actionJson = $actionJson;
47 return $result;
48 }
49
50 public function getNpcActorUniqueId() : int{ return $this->npcActorUniqueId; }
51
52 public function getActionType() : int{ return $this->actionType; }
53
54 public function getDialogue() : string{ return $this->dialogue; }
55
56 public function getSceneName() : string{ return $this->sceneName; }
57
58 public function getNpcName() : string{ return $this->npcName; }
59
60 public function getActionJson() : string{ return $this->actionJson; }
61
62 protected function decodePayload(ByteBufferReader $in) : void{
63 $this->npcActorUniqueId = LE::readSignedLong($in); //WHY NOT USING STANDARD METHODS, MOJANG
64 $this->actionType = VarInt::readSignedInt($in);
65 $this->dialogue = CommonTypes::getString($in);
66 $this->sceneName = CommonTypes::getString($in);
67 $this->npcName = CommonTypes::getString($in);
68 $this->actionJson = CommonTypes::getString($in);
69 }
70
71 protected function encodePayload(ByteBufferWriter $out) : void{
72 LE::writeSignedLong($out, $this->npcActorUniqueId);
73 VarInt::writeSignedInt($out, $this->actionType);
74 CommonTypes::putString($out, $this->dialogue);
75 CommonTypes::putString($out, $this->sceneName);
76 CommonTypes::putString($out, $this->npcName);
77 CommonTypes::putString($out, $this->actionJson);
78 }
79
80 public function handle(PacketHandlerInterface $handler) : bool{
81 return $handler->handleNpcDialogue($this);
82 }
83}
static create(int $npcActorUniqueId, int $actionType, string $dialogue, string $sceneName, string $npcName, string $actionJson)