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

Unregister Default Commands

Discussion in 'Development' started by QuiverlyRivalry, Jan 16, 2018.

  1. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    hullo, how would you unregister a command in built PocketMine?
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    You can't, you can only override it by another command
     
  3. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    You could edit PMMP source to prevent the registration of the command, or you could override it.

    EDIT: Commands can be overridden look at @Muqsit reply.
     
    Last edited: Jan 16, 2018
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    You can remove pmmp source code all Commands, than add it into your plugin.
     
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
  6. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You can override any default pocketmine commands, what did you try?
     
  8. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Lmao idk I am sick, I can’t go to my pc right now sorry.
     
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Try this function I made(copied):
    PHP:
    public function unregister(string ...$commands){
        
    $map Server::getInstance()->getCommandMap();
        foreach (
    $commands as $cmd) {
            
    $command $map->getCommand($cmd);
            if (
    $command !== null) {
                
    $command->setLabel("old_".$cmd);
                
    $map->unregister($command);
            }
        }
    }
    Usage:
    PHP:
    $this->unregister("list""op""enchant");

    $plugin $this->isMyPlugin();

    $map $plugin->getServer()->getCommandMap();
    $map->registerCommands($plugin->getName(), [
        new 
    MyCustomListCommand("list"$plugin),
        new 
    MyOpCommand("op"$plugin),
        new 
    MyEnchantCommand("enchant"$plugin)
    ]);

    class 
    MyCustomListCommand extends PluginCommand{
    }
    Not sure, but you may need to unregister command aliases too:
    PHP:
    $this->unregister(...$plugin->getServer()->getCommandMap()->getCommand("list")->getAliases());
     
    Last edited: Feb 1, 2018
    RicardoMilos384 likes this.
  10. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    You need to call SimpleCommandMap::unregister($command), not Command::unregister().
     
  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.