PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
NpcRequestPacket.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
21
23 public const NETWORK_ID = ProtocolInfo::NPC_REQUEST_PACKET;
24
25 public const REQUEST_SET_ACTIONS = 0;
26 public const REQUEST_EXECUTE_ACTION = 1;
27 public const REQUEST_EXECUTE_CLOSING_COMMANDS = 2;
28 public const REQUEST_SET_NAME = 3;
29 public const REQUEST_SET_SKIN = 4;
30 public const REQUEST_SET_INTERACTION_TEXT = 5;
31 public const REQUEST_EXECUTE_OPENING_COMMANDS = 6;
32
33 public int $actorRuntimeId;
34 public int $requestType;
35 public string $commandString;
36 public int $actionIndex;
37 public string $sceneName;
38
42 public static function create(int $actorRuntimeId, int $requestType, string $commandString, int $actionIndex, string $sceneName) : self{
43 $result = new self;
44 $result->actorRuntimeId = $actorRuntimeId;
45 $result->requestType = $requestType;
46 $result->commandString = $commandString;
47 $result->actionIndex = $actionIndex;
48 $result->sceneName = $sceneName;
49 return $result;
50 }
51
52 protected function decodePayload(ByteBufferReader $in) : void{
53 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
54 $this->requestType = Byte::readUnsigned($in);
55 $this->commandString = CommonTypes::getString($in);
56 $this->actionIndex = Byte::readUnsigned($in);
57 $this->sceneName = CommonTypes::getString($in);
58 }
59
60 protected function encodePayload(ByteBufferWriter $out) : void{
61 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
62 Byte::writeUnsigned($out, $this->requestType);
63 CommonTypes::putString($out, $this->commandString);
64 Byte::writeUnsigned($out, $this->actionIndex);
65 CommonTypes::putString($out, $this->sceneName);
66 }
67
68 public function handle(PacketHandlerInterface $handler) : bool{
69 return $handler->handleNpcRequest($this);
70 }
71}
static create(int $actorRuntimeId, int $requestType, string $commandString, int $actionIndex, string $sceneName)