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

Delete a default command.

Discussion in 'Development' started by LCraftPE, Jan 13, 2017.

  1. 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...
    PHP:
    $unregister = array("help""version""teleport""give");
    foreach(
    $unregister as $cmd){
        if(
    $this->getServer()->getCommandMap()->getCommand($cmd) !== null){
          
    $this->getServer()->getCommandMap()->getCommand($cmd)->setLabel($cmd.'__');
          
    $this->getServer()->getCommandMap()->getCommand($cmd)->unregister($this->getServer()->getCommandMap());
        }
    }
    $this->getServer()->getCommandMap()->register("help", new HelpCommand($this));
    $this->getServer()->getCommandMap()->register("version", new VersionCommand($this));
    $this->getServer()->getCommandMap()->register("teleport", new TeleportCommand($this));
    Here, the command "give" will be always work while I have unregister the command... Is there a PM function to completely remove a default command ? The "unregister" function should not do this ?
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I don't think you can remove a command. But you can overwrite it with a command that won't do anything.
     
    jasonwynn10 and applqpak like this.
  3. LCraftPE

    LCraftPE Silverfish

    Messages:
    20
    GitHub:
    LCraftPE
    If I want to remove all the defaults commands, it can be long...

    And, the unregister function remove also the alias of defaults commands ? For example, if I unregister /tell and I "overwrite it with a command that won't do anything", I must also unregister and "overwrite it with a command that won't do anything" for all the alias of /tell ?
     
  4. applqpak

    applqpak Spider Jockey

    Messages:
    27
    GitHub:
    applqpak
    Aliases aren't seperate commands - they're different ways to access the function of a command.
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It won't be long. And since the code is executed on plugin enable, it won't cause lag or reduce performance.

    PHP:
    $unregister = ["help""version""teleport""give"];
    foreach(
    $unregister as $cmd){
        if(
    $this->getServer()->getCommandMap()->getCommand($cmd) !== null){
          
    $this->getServer()->getCommandMap()->getCommand($cmd)->setLabel($cmd.'__');
          
    $this->getServer()->getCommandMap()->getCommand($cmd)->unregister($this->getServer()->getCommandMap());
          
    $this->getServer()->getCommandMap()->register($cmd, new UselessCommand($this));
        }
    }
     
    applqpak likes this.
  6. LCraftPE

    LCraftPE Silverfish

    Messages:
    20
    GitHub:
    LCraftPE
    Ok thank you :)
     
  7. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Try this if ever you'd like a command that does nothing when executed (this case it's help)

    PHP:
    public function onCommandPreProcess(PlayerCommandPreprocessEvent $event){  
     
    $args explode(" "$event->getMessage());
    if(
    $args[0] == "/help"){    
    if (!(
    $event->getPlayer() instanceof Player)){ 
     return 
    true;
    } else {
    $event->setCancelled();
    }
    PS : France un jour, France toujours !
     
  8. kaliiks

    kaliiks Zombie

    Messages:
    250
    This only change command function dont remove it
     
  9. LCraftPE

    LCraftPE Silverfish

    Messages:
    20
    GitHub:
    LCraftPE
    C'est pas la bonne méthode pour modifier une commande :)
    Tu es Francais ?
     
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Try not using PlayerCommandPreprocessEvent.
    It's hacky!
     
    applqpak likes this.
  11. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Use English in thsi forhms please, so others can understand what you posted when reading thsi thread to get further information
     
    applqpak and Muqsit like this.
  12. LCraftPE

    LCraftPE Silverfish

    Messages:
    20
    GitHub:
    LCraftPE
    I just said that PlayerCommandPreprocess is not the good method :)
     
    HimbeersaftLP and applqpak like this.
  13. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Still, /help command does not send a message using this code, it may be hacky but It works.

    Et oui je suis français
     
  14. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Not sure if onCommand work tough never tried
     
  15. LCraftPE

    LCraftPE Silverfish

    Messages:
    20
    GitHub:
    LCraftPE
    Non ça marche pas tout le temps, j'utilisais cette manière et j'ai changé car elle marchait 1/5... Si tu ne me crois pas, regarde les discussions pocketmine ou shoghicp (le créateur de PocketMine) l'explique. :)
     
  16. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Speak English or speak in PM, and for me it works every time, maybe cause I'm using a fork, idk I'll test something else
     
    Muqsit and HimbeersaftLP like this.
  17. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    I hate that still have to hack your way through the command map. And aliases are often still stuck somewhere in there.
     
  18. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I guess that's the best anyone could do?
     
    applqpak likes this.
  19. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Of course, but this should get a 'fix'. The cmd map is a true mess. And aliases look like they have been an afterthought.
     
    Muqsit likes this.
  20. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    thats only cancel the command if a player will execute it ^^ what about the console?
     
  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.