PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
AgentActionEventPacket.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;
22
27 public const NETWORK_ID = ProtocolInfo::AGENT_ACTION_EVENT_PACKET;
28
29 private string $requestId;
31 private int $action;
32 private string $responseJson;
33
37 public static function create(string $requestId, int $action, string $responseJson) : self{
38 $result = new self;
39 $result->requestId = $requestId;
40 $result->action = $action;
41 $result->responseJson = $responseJson;
42 return $result;
43 }
44
45 public function getRequestId() : string{ return $this->requestId; }
46
48 public function getAction() : int{ return $this->action; }
49
50 public function getResponseJson() : string{ return $this->responseJson; }
51
52 protected function decodePayload(ByteBufferReader $in) : void{
53 $this->requestId = CommonTypes::getString($in);
54 $this->action = LE::readUnsignedInt($in);
55 $this->responseJson = CommonTypes::getString($in);
56 }
57
58 protected function encodePayload(ByteBufferWriter $out) : void{
59 CommonTypes::putString($out, $this->requestId);
60 LE::writeUnsignedInt($out, $this->action);
61 CommonTypes::putString($out, $this->responseJson);
62 }
63
64 public function handle(PacketHandlerInterface $handler) : bool{
65 return $handler->handleAgentActionEvent($this);
66 }
67}
static create(string $requestId, int $action, string $responseJson)