Hi, I have this problem, I made a very simple kit plugin for my server, but when I run command tools it automatically crashes my test server, resulting in a error log. Code: 07:29:31 [NOTICE] A E_RECOVERABLE_ERROR error happened: "Argument 1 passed to pocketmine\Server::dispatchCommand() must implement interface pocketmine\command\CommandSender, string given, called in C:\Boot\PocketMine-MP\plugins\PocketCore\src\PocketCore\PocketCore.php on line 21 and defined" in "phar://C:/Boot/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php" at line 1629 07:29:31 [ERROR] A E_WARNING error happened: "Missing argument 2 for pocketmine\Server::dispatchCommand(), called in C:\Boot\PocketMine-MP\plugins\PocketCore\src\PocketCore\PocketCore.php on line 21 and defined" in "phar://C:/Boot/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php" at line 1629 07:29:31 [NOTICE] A E_NOTICE error happened: "Undefined variable: commandLine" in "phar://C:/Boot/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php" at line 1630 07:29:31 [NOTICE] A E_RECOVERABLE_ERROR error happened: "Argument 1 passed to pocketmine\command\SimpleCommandMap::dispatch() must implement interface pocketmine\command\CommandSender, string given, called in phar://C:/Boot/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php on line 1630 and defined" in "phar://C:/Boot/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/command/SimpleCommandMap.php" at line 166 Fatal error: Call to a member function sendMessage() on a non-object in phar://C:/Boot/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php on line 1637 I am not really sure what the problem is. Below is the source code of the simple plugin. PHP: <?phpnamespace PocketCore;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\Player;use pocketmine\plugin\PluginBase;class PocketCore extends PluginBase{ public function onEnable(){ $this->getLogger()->info("PocketCore has loaded!"); } public function onCommand(CommandSender $sender, Command $command, $label, array $args){ switch($command->getName()){ case "tools": if ($sender instanceof Player) { $this->getServer()->dispatchCommand("give " . $sender->getName() . " 364 64"); } else { $sender->sendMessage("Please run command in game."); return true; } break; case "food": if ($sender instanceof Player) { } else { $sender->sendMessage("Please run command in game."); return true; } break; default: return false; } } public function onDisable(){ $this->getLogger()->info("PocketCore has been disabled."); }}
See dispatchCommand()'s document! /** * Executes a command from a CommandSender * * @param CommandSender $sender * @param string $commandLine * * @return bool */ For example, Code: $this->getServer()->dispatchCommand($sender, "give " . $sender->getName() . " 364 64");
you need use pocketmine\Server::dispatchCommand(); use pocketmine\command\SimpleCommandMap::dispatch(); please look at the error before submitting an error