PocketMine-MP 5.18.1 git-9381fc4172e5dce4cada1cb356050c8a2ab57b94
CommandRequestPacket.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
19
21 public const NETWORK_ID = ProtocolInfo::COMMAND_REQUEST_PACKET;
22
23 public string $command;
24 public CommandOriginData $originData;
25 public bool $isInternal;
26 public int $version;
27
31 public static function create(string $command, CommandOriginData $originData, bool $isInternal, int $version) : self{
32 $result = new self;
33 $result->command = $command;
34 $result->originData = $originData;
35 $result->isInternal = $isInternal;
36 $result->version = $version;
37 return $result;
38 }
39
40 protected function decodePayload(PacketSerializer $in) : void{
41 $this->command = $in->getString();
42 $this->originData = $in->getCommandOriginData();
43 $this->isInternal = $in->getBool();
44 $this->version = $in->getVarInt();
45 }
46
47 protected function encodePayload(PacketSerializer $out) : void{
48 $out->putString($this->command);
49 $out->putCommandOriginData($this->originData);
50 $out->putBool($this->isInternal);
51 $out->putVarInt($this->version);
52 }
53
54 public function handle(PacketHandlerInterface $handler) : bool{
55 return $handler->handleCommandRequest($this);
56 }
57}
static create(string $command, CommandOriginData $originData, bool $isInternal, int $version)