E_ERROR - Call to a member function sendMessage() on string here is the plugin code: PHP: <?phpnamespace Hittmana\TradePro;use pocketmine\command\CommandSender;use pocketmine\command\Command;use pocketmine\plugin\PluginBase;use pocketmine\Player;use pocketmine\event\Listener;use pocketmine\event\TranslationContainer;use pocketmine\utils\TextFormat;class MainClass extends PluginBase implements Listener{ public function onEnable() { $this->getLogger()->info("Test enabled"); $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onDisable() { $this->getLogger()->info("Test disabled"); }public function onCommand(CommandSender $sender, Command $command, $label, array $args){ if($sender instanceof Player) { $name = $sender->getName(); if ($command->getName() == "test") { $this->getLogger()->info("IT WORKS!!" . $name . "USED IT!!!!"); $recipient = $args[0]; $trader = $sender->getName(); $recipient->sendMessage($trader . " wants to trade with you!"); $sender->sendMessage("You sent a trade request " . $recipient . ". Lets hope he says YES!"); return true; } else { $this->getLogger()->info("Command must be run in-game or by a player :("); return false; } }}}
I said recipient, not sender. PHP: if(!$recipient instanceof Player){ $sender->sendMessage("Player not found");}else{ //code}
$recipent is $args[0], $args[0] is a part of a typed, command, means that args is a string, so you need to do $recipent = $this->getServer()->getPlayer($args[0]);
Args isn't a string. $args is an array, which you get the first(counting starts from 0 at programming) entry from: $args[0] and the entry is a string. If you want $args as a string, you have to use implode().
Ok now it doesn't find a player at all! Here is the code: PHP: <?phpnamespace Hittmana\TradePro;use pocketmine\command\CommandSender;use pocketmine\command\Command;use pocketmine\plugin\PluginBase;use pocketmine\Player;use pocketmine\event\Listener;use pocketmine\event\TranslationContainer;use pocketmine\utils\TextFormat;class MainClass extends PluginBase implements Listener{ public function onEnable() { $this->getLogger()->info("Test enabled"); $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onDisable() { $this->getLogger()->info("Test disabled"); }public function onCommand(CommandSender $sender, Command $command, $label, array $args){ if($sender instanceof Player) { $name = $sender->getName(); if ($command->getName() == "test") { $this->getLogger()->info("IT WORKS!!" . $name . "USED IT!!!!"); $recipient = $args[0]; if($recipient instanceof Player) { $trader = $sender->getName(); $recipient->sendMessage($trader . " wants to trade with you!"); $sender->sendMessage("You sent a trade request " . $recipient . ". Lets hope he says YES!"); return true; } else { $sender->sendMessage("Player not found"); } } else { $this->getLogger()->info("Command must be run in-game or by a player :("); return false; } }}}
$args[0] is the player name that the command sender typed. It has absolutely nothing to do with a player object. Just from a logical sense, not even talking about API knowledge, there is no way that PHP/PocketMine/whoever would know that that certain command argument would be related to a player. (Say, maybe it may be a world name, a plugin name, or whatever? Who knows?)