Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Sub command

Comments in 'Plugin Development' started by TheMaks, Sep 15, 2015.

  1. TheMaks
    Offline

    TheMaks Active Member

    Joined:
    Jul 19, 2015
    Posts:
    58
    Minecraft User:
    TheMaks
    how to make sub commands ?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    If you want a simpler method, use the default variable/array $args.
    Since it is an array, get the first sub-command using the key 0 (Remember it starts with a 0).
    PHP:
    $args[0]
    Use switch-case or an if:
    PHP:
    switch(strtolower($args[0])){
        case 
    "help":
           break;
        case 
    "blah":
           
    // ANYTHING
           
    break;
    }
  4. TheMaks
    Offline

    TheMaks Active Member

    Joined:
    Jul 19, 2015
    Posts:
    58
    Minecraft User:
    TheMaks
    if($command->getName() == "mg"){
    //how make sub command for command 'mg' , example '/mg help'
    }
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Understand the code. Use the array $args.
    PHP:
    if($command->getName() == "mg"){
        switch(
    strtolower($args[0])){
            case 
    "help":
                
    $sender->sendMessage("Hi");
                break;
        }
    }
    TheMaks likes this.
  6. TheMaks
    Offline

    TheMaks Active Member

    Joined:
    Jul 19, 2015
    Posts:
    58
    Minecraft User:
    TheMaks
    Thanks :3
    Sorry the my bad english , i from Russia
    Legoboy0215 likes this.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    English does not matter :p You understand, then I am happy. Like?
    Vaivez66, PEMapModder and TheMaks like this.
  8. TheMaks
    Offline

    TheMaks Active Member

    Joined:
    Jul 19, 2015
    Posts:
    58
    Minecraft User:
    TheMaks
    Yes , of course
    Legoboy0215 likes this.

Share This Page

Advertisement