1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

[SOLVED] Please help | setExecutor() on null

Discussion in 'Development' started by InspectorGadget, Feb 10, 2017.

  1. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi! I've been working on this lately. I've been getting this error whenever i load this plugin. Idk why...

    Error:
    Loader:
    PHP:
    <?php

    namespace 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:
    <?php

    namespace 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 $senderCommand $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;
              
            }
            
        }

    }
     
  2. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    PHP:
        public function onCommand(CommandSender $senderCommand $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 :)
     
  3. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Why can't my version work?
     
  4. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Your solution allows to execute I prefer the solution that I give you
     
  5. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    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
     
  6. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    If I help you :) this is not for nothing ;)
     
  7. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    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
     
  8. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    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.
     
  9. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Fixed, thanks :)
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.