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

Check if command exists

Discussion in 'Development' started by Rysieku, Aug 31, 2017.

  1. Rysieku

    Rysieku Spider Jockey

    Messages:
    34
    GitHub:
    rysieku
    Is there a way to check if command exists?
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    not ideal POC:
    you can try summoning a fake player to run that cmd
    which use regex+return data to check if the cmd exist

    i think there's a getcommand map and if lable exist or something like that since it's used in overwriting default commands
    i dont see why it cant check if one existed
     
    Karanpatel567 likes this.
  3. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    yes i agree
     
  4. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    'if' is not a function in any programming language I know of. It's a control structure, you can read more about php control structures over on php.net.

    We can use pocketmine\command\SimpleCommandMap::getCommand() to check if a command exists -- see below:
    PHP:
    if(pocketmine\command\SimpleCommandMap::getCommand("commandnameoraliashere") instanceof pocketmine\command\Command) {
        echo 
    "Command exists!" PHP_EOL;
    } else {
        echo 
    "Command does not exist :c" PHP_EOL;
    }
     
    SOFe, jasonwynn10 and Muqsit like this.
  5. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Yeh I realised that wasnt really bothered to chance.
     
  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.