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

Not sure what's happening | Undifined Error

Discussion in 'Development' started by InspectorGadget, Jan 25, 2017.

  1. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi! I'm cracking my head on this one plugin. Any help would be appreciated...

    My Error:
    PHP:
    [14:02:21] [Server thread/CRITICAL]: Error"Call to undefined method RTG\GitHub\Review::setExecutor()" (EXCEPTIONin "/Review/src/RTG/GitHub/Review" at line 23
    My Loader on where its causing it from:
    PHP:
        public function onEnable() {
            @
    mkdir($this->getDataFolder());
            @
    mkdir($this->getDataFolder() . "/players");
            
    $this->getLogger()->info("[Review] DIR has been made!");
            
    $this->getLogger()->info("Loaded!");
           
            
    /* Execution */
            
    $this->setExecutor(new MyCommand($this)); - Line 23
           
            $this
    ->getLogger()->info("[Review] Everything has been loaded!");
        }
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Does your Review class extend PluginCommand?
     
    applqpak likes this.
  3. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Nope, I'll attach my full Review.php and MyCommand.php

    PHP:
    <?php

    namespace RTG\GitHub;

    /*
     * All rights reserved RTGNetworkkk
     */

    /* Essentials */
    use pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\plugin\PluginBase;

    class 
    Review extends PluginBase {
       
        public function 
    onEnable() {
            @
    mkdir($this->getDataFolder());
            @
    mkdir($this->getDataFolder() . "/players");
            
    $this->getLogger()->warning("[Review] DIR has been made!");
            
    $this->getLogger()->warning("Loaded!");
           
            
    /* Execution */
            
    $this->setExecutor(new MyCommand($this));
           
            
    $this->getLogger()->warning("[Review] Everything has been loaded!");
        }
       
        public function 
    onDisable() {
        }
       
    }
    MyCommand:
    PHP:
    <?php

    namespace RTG\GitHub\Command;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\CommandExecutor;

    use 
    pocketmine\utils\Config;

    use 
    RTG\GitHub\Review;

    use 
    pocketmine\utils\TextFormat as TF;

    class 
    MyCommand implements CommandExecutor {
       
        public function 
    __construct(Review $plugin) {
            
    $this->plugin $plugin;
        }
       
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $param) {
            switch(
    $cmd->getName()) {
               
                case 
    "review":
                   
                    if(isset(
    $param[0])) {
                       
                        switch(
    $param[0]) {
                           
                            case 
    "add":
                               
                                if(
    $sender->hasPermission("review.add")) {
                   
                                    
    $n $sender->getName();
                   
                                    if(
    count($param) < 1) return false;
                   
                                        
    $msg trim(implode(" "$param));
                       
                                         
    $this->cfg = new Config($this->getDataFolder() . "/players" $n "yml"Config::YAML);
                       
                                         
    $this->cfg->setNested($msg);
                       
                                         
    $sender->sendMessage("[Review] You review has been added!");
                           
                                }
                                else {
                                    
    $sender->sendMessage(TF::RED "You have no permission to use this command!");
                                }  
                               
                                return 
    true;
                            break;        
                           
                        }
                    }
                    else {
                        
    $sender->sendMessage("Usage: /review add {review}");
                    }
                   
                    return 
    true;
                break;
               
            }
           
        }
       
    }
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Your class has to extend PluginCommand if you want to set the executor. You need to create a third class extending PluginCommand.
     
  5. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    The solution is really easy. Just make that line:
    PHP:
    $this->getCommand("review")->setExecutor(blablabla);
     
  6. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    It worked, Thanks :)
    PHP:
    [14:35:08] [Server thread/WARNING]: [Reviewer] [ReviewDIR has been made!
    [
    14:35:08] [Server thread/WARNING]: [ReviewerLoaded!
    [
    14:35:08] [Server thread/WARNING]: [Reviewer] [ReviewEverything has been loaded!
     
    Sandertv likes this.
  7. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    That worked :)

    I know this is wrong :p
    PHP:
    $this->cfg = new Config($this->plugin->getDataFolder() . "/players" $n "yml"Config::YAML);
    because i didnt add "pocketmine\utils\Config" xD
     
  8. [deleted]

    [deleted] Guest

    Use PHPStorm or any other IDE, they do this Job for you because we humans are too lazy
     
    Muqsit likes this.
  9. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I use NetBeans IDE
     
  10. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I don't know why I see this, but shouldn't you use $this->getLogger()->notice() instead of $this->getLogger()->warning() unless you are displaying errors?
     
  11. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    yea, but that's not really relevant
     
    InspectorGadget likes this.
  12. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    So this tiny thing is bugging you instead of that full PHP file?
     
  13. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I would like to apologize for being irrelevant or annoying. I was simply trying to point out something that might inform you or another developer if you choose to acknowledge it, that $this->getLogger->warning() outputs a message that appears as an error, which may be misleading to somebody using the plugin.
     
    Last edited: Jan 27, 2017
  14. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    It's still not late to point it out
     
  15. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I phrased my previous response poorly, I have edited it to make more sense. :p
     
  16. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I used it to let me track it when I'm testing it. I'll change back to info() after it's working!
     
  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.