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

Register a Command into Main file

Discussion in 'Development' started by Remarkabless, Dec 11, 2017.

  1. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    Undefined property: pocketmine\Server::$getCommandMap" (EXCEPTION) in


    PHP:

    use pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\CommandMap;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;

    class 
    Core extends PluginBase{

        public function 
    onEnable() {
            
    $this->getServer()->getCommandMap->register("info", new Info($this));
            
    $this->getServer()->getCommandMap->register("refill", new Refill($this));
        }
    }
    Is this the way to register a command? I dont like coming here to ask about this topix because most of you guys say “dont do it if you dont know” but how is someone supposed to learn. Anyways. Can someone help me register this the right way?
     
  2. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Well, the error is telling you that $this->getServer()->getCommandMap isn't a property. I see your error and so should you. (hint: your trying to access getCommandMap as a variable, not as a function :p)
     
  3. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    Confused. I see everyone enabling it like this, this is my first time trying can you show me with some example code? Please
     
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Create a folder name Commands
    create anyname.php
    PHP:
    $this->getServer()->getCommandMap()->register("anyname", new Commands\anyname());
     
  5. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Have a good look into this thread, I have made a detailed explanation. Look at my first post I have explained it in pretty much detail.
     
  6. Remarkabless

    Remarkabless Slime

    Messages:
    83
    GitHub:
    Remakem
    What do I put as the “class blank extends blank{ in the command file? Thats the part i dont know
     
  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.