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 Kyd, Mar 25, 2017.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Can i unregister default command for example /summon without editing software?
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Any answer, please?
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You can overwrite it with an empty command, but you cannot unregister it AFAIK.
     
  4. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    You can override commands in a plugin using this method by shoghi:

     
    SOFe likes this.
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    If i use this method i dont see command when i type / to chat?
     
  6. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
    I'm not sure, but i tried it long ago. Command->unregister(); does not remove the registration of that Command.

    So the best attempt to unregister/overwrite a command is by listening PlayerCommandPreprocessEvent, then get message from that event and check if specified command is executed. If true, cancel the event.
    PHP:
    public function onCommand(PlayerCommandPreprocessEvent $e){
        
    $msg $e->getMessage();
        
    $cmd substr($msg0strpos($msg" "));
        if(
    $cmd == "/example"){
            
    //Attempt to execute command, example
            
    $e->setCancelled();
        }
    }
     
  7. asyven

    asyven Spider

    Messages:
    14
    Be sure, It works until today
     
    Last edited: Apr 3, 2017
  8. ALLINSEO

    ALLINSEO Baby Zombie

    Messages:
    133
    has this been updated?
    I have many commands that most users cannot use, is there anyway to hide them with new API?
     
  9. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
    I'm not sure with Command->unregister(). Not the code I posted ;)

    Use this:
    PHP:
    public function onCommand(PlayerCommandPreprocessEvent $e){
        
    $msg $e->getMessage();
        
    $cmd substr($msg0strpos($msg" "));
        if(
    $cmd == "/example"){
            
    //Attempt to execute command, example
            
    $e->setCancelled();
        }
    }
    Where, "/example" is the command you wanted to "remove"
     
  10. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    Look at my post, it contains an example from shoghicp using $command->unregister()
     
  11. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
    I looked already, and now you please look at my post:
    I said, I'm not sure if Command->unregister() is working. I tried unregister long ago, it seems not to be worked
     
  12. [deleted]

    [deleted] Guest

    Does this actually work? Have you tested it?
     
  13. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
    I have tested Command->unregister() before, the command does not removed.
    For my code, I'm pretty sure it's working.
     
  14. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
  15. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
  16. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
  17. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
    unregister() is available at Command class, not CommandMap ;) All VanillaCommand like /summon is extended with Command Class, so you can just execute unregister() directly.
    But, I'm not sure if Command->unregister() actually removes the command
     
  18. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    Last time i check these 4 lines of code worked. Then just register your command the normal way.

    PHP:
    $map $plugin->getServer()->getCommandMap();
            
    $command $map->getCommand($name);
            
    $command->setLabel($name "_disabled");
            
    $command->unregister($map);
     
    Last edited: Apr 3, 2017
    jasonwynn10 likes this.
  19. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Uche uch, These are PocketMine forums not Nukkit!
     
    Muqsit likes this.
  20. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    Sorry copied it directly from my plugin (i only made for nukkit because it had no half decent plugins) i didnt realise it was java when i copied the code lol.

    EDIT: Converted to PHP code
     
  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.