Hi! I've been working on this lately. I've been getting this error whenever i load this plugin. Idk why... Error: Loader: PHP: <?phpnamespace RTG\JDT;/* Essentials */use pocketmine\Server;use pocketmine\plugin\PluginBase;use pocketmine\Player;use pocketmine\network\protocol\TransferPacket;use pocketmine\command\CommandExecutor;use pocketmine\event\Listener;use RTG\JDT\Transfer;class Loader extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getCommand("jdt")->setExecutor(new Transfer($this)); } public function onTransfer($p, $ip, $port) { $pk = new \pocketmine\network\protocol\TransferPacket(); $pk->address = $ip; $pk->port = (int) $port; $p->dataPacket($pk); $p->sendMessage("[Transfer] Executing..."); } public function onDisable() { $this->getLogger()->warning("Turning off JDTransfer!"); } } Command: PHP: <?phpnamespace RTG\JDT;use RTG\JDT\Loader;/* Essentials */use pocketmine\Server;use pocketmine\plugin\PluginBase;use pocketmine\Player;use pocketmine\command\Command;use pocketmine\command\CommandExecutor;use pocketmine\command\CommandSender;use pocketmine\utils\TextFormat as TF;class Transfer implements CommandExecutor { public $plugin; public function __construct(Loader $plugin) { $this->plugin = $plugin; } public function onCommand(CommandSender $sender, Command $cmd, $label, array $param) { switch(strtolower($cmd->getName())) { case "jdt": $sender->sendMessage("[Transfer] /jdt [ServerName]"); $sender->sendMessage(" "); $sender->sendMessage("[Transfer] Server List: Revolution," . TF::GREEN . "JDE, JDB, JDMulti, BC, JDC, JDU, IB, JDCustom"); $sender->sendMessage("[Transfer]" . TF::RED . "If i miss any names out, please let me know - IG"); if(isset($param[0])) { switch(strtoupper($param[0])) { case "JDC": $ip = "jdcraft.net"; $port = 19132; if($sender instanceof Player) { $this->plugin->onTransfer($sender, $ip, $port); } else { $sender->sendMessage("[Error] In-game!"); } return true; break; } } else { $sender->sendMessage("Usage: /jdt"); } return true; break; } }}
PHP: public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ parent::onCommand($sender, $cmd, $label, $args); if($cmd->getName() == "transferto"){ if($sender instanceof Player){ $pk = new TransferPacket(); $pk->address = $args[0]; $pk->port = $args[1]; $sender->dataPacket($pk); Command::broadcastCommandMessage($sender, "Transferred to " . $args[0] . ":" . $args[1]); }else{ $sender->sendMessage("run this command in game!"); } } } Use this code
I think I'll move the command to my Loader.php. I'm not trying to make my code messy with a lot of code on each case and I don't want to make my player's life hard with asking them to type the IP and PORT
that dosent help op's question op never asked for an alternate op only asked for why as for why: because getCommand() returns null, and you try to do a ->setExecutor as for how to fix it, i am sorry i dont use this method but i think someone who knows how to do that will reply
Did you try to make someone use that command? If yes, I think you'd be better off using Server::dispatchCommand(). This is also an alternative, not how it would work your way.