I need help in my plugin allert (my message in sendTip) I am asking for the code on sendTip my message /allert (mymessage) PHP: <?phpnamespace Allert;use pocketmine\plugin\PluginBase;use pocketmine\command\Command;use pocketmine\command\CommandSender;class Main extends PluginBase{ public function onEnable(){ $this->getLogger()->info("[Allert] On"); } public function onCommand(CommandSender $sender, Command $command, $label, array $args){ if(strtolower($command->getName()) === "alert"){ $sender->sendTip("[Allert] $args (mymessage)"); return true; }}}
PHP: public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{
Error: >allert kd [Server] [23:50:18] [Server thread/INFO]: An unknown error occurred while attempting to perform this command [Server] [23:50:18] [Server thread/CRITICAL]: Unhandled exception executing command 'allert kd' in allert: Call to undefined method pocketmine\command\ConsoleCommandSender::sendTip() [Server] [23:50:18] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\command\ConsoleCommandSender::sendTip()" (EXCEPTION) in "myzip:///komedadrop.zip#allert/allert/allert/allert/src/alert/Main" at line 16 PHP: <?phpnamespace alert;use pocketmine\plugin\PluginBase;use pocketmine\command\Command;use pocketmine\command\CommandSender;class Main extends PluginBase{ public function onEnable(){ $this->getLogger()->info("drop"); } public function onCommand(CommandSender $sender, Command $command, $label, array $args) : bool{ if(strtolower($command->getName()) === "allert"){ Line 16 - $sender->sendTip($args); }}}
You have to send the Tip to players only. You can't run the command in the console, because Tips can only be displayed to Players. Otherwise, it should work. It won't display properly if you have BasicHUD or another plugin that sends Tips very often.
You need to check if $sender is an instance of the Player class before sending the tip to make sure the plugin doesn't crash when using from console. Spoiler: me want le code PHP: if (!$sender instanceof Player) { $sender->sendMessage("Please use this command ingame!"); return true;} also make sure to add a use statement for pocketmine\Player so php knows what Class you're meaning with Player.
Read the error, she is sending it from console. @girlx189 If you go in game that command should make the tip pop up on your own screen PHP: <?phpnamespace alert;use pocketmine\plugin\PluginBase;use pocketmine\command\Command;use pocketmine\command\CommandSender;class Main extends PluginBase{ public function onEnable(){ $this->getLogger()->info("drop"); } public function onCommand(CommandSender $sender, Command $command, string $label, array $args) :bool{ if(strtolower($command->getName()) === "allert"){ $sender->sendTip(implode(" ",$args)); } return true; }} Also you need to implode $args, you cant put an array in a string