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

Is it possible to unregister a default command?

Discussion in 'Development' started by cd9r, Dec 21, 2016.

  1. cd9r

    cd9r Spider

    Messages:
    7
    GitHub:
    cd9r
    I have tried this, but it won't work.
    PHP:
    $this->getServer()->getCommandMap()->getCommand('ban')->unregister($this->getServer()->getCommandMap());
    Is it possible to unregister a default command without changing the PMMP source code? Plz help, thanks.
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    This is how I do it on my server...
    PHP:
    //onEnable()
    $unregister = array("help""version""teleport"); //unregistering... note that the command wont be unregistered until overrided.
    foreach ($unregister as $cmd) {
        if (
    $this->getServer()->getCommandMap()->getCommand($cmd) !== null) {
            
    $this->getServer()->getCommandMap()->getCommand($cmd)->setLabel($cmd.'__');//hacky?
            
    $this->getServer()->getCommandMap()->getCommand($cmd)->unregister($this->getServer()->getCommandMap());
        }
    }

    //Overriding... (onEnable())
    $this->getServer()->getCommandMap()->register("help", new HelpCommand($this));
    $this->getServer()->getCommandMap()->register("version", new VersionCommand($this));
    $this->getServer()->getCommandMap()->register("teleport", new TeleportCommand($this));

    //Separate class.
    //HelpCommand class
    public function __construct(MainClass $plugin$cmd){
        
    parent::__construct($cmd"For noobs"null, ["?"]); //"For noobs" => description, ["?"] => array of aliases.
        
    $this->plugin $plugin;
    }

    public function 
    execute(CommandSender $issuer$alias, array $args){
        if(!
    $this->testPermission($issuer)) return true;
        
    $issuer->sendMessage("modified help command output.");
        return 
    true;
    }
     
    applqpak likes this.
  3. cd9r

    cd9r Spider

    Messages:
    7
    GitHub:
    cd9r
    thanks! I'll try it.
     
  4. Intyre

    Intyre Administrator Staff Member PMMP Team

    Messages:
    81
    GitHub:
    Intyre
    HittmanA, applqpak, SOFe and 3 others like this.
  5. Magicode

    Magicode Baby Zombie

    Messages:
    183
    GitHub:
    magicode1
  6. LCraftPE

    LCraftPE Silverfish

    Messages:
    20
    GitHub:
    LCraftPE
    How to delete a default command ? I'm using that but commands which aren't modified always work... Help?
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Start a new thread for a new thread.
     
    iCirgio likes this.
  8. LCraftPE

    LCraftPE Silverfish

    Messages:
    20
    GitHub:
    LCraftPE
  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.