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

Solved Available subcommand/parameters above command

Discussion in 'Development' started by Sandertv, Apr 16, 2017.

  1. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Hey guys,
    So today @SOFe was talking about the way to make autocompletion, and basically the way to make commands work as vanilla, with syntax checking. So I started just trying things out, and messing with it, and found a way it works.

    This is the final code I came up with to make the syntax checking work and the arguments correctly:
    PHP:
    // Class that extends pocketmine\command\PluginCommand

    public function generateCustomCommandData(Player $player) {
       
    $commandData $this->commandData;
       
    $commandData["overloads"]["default"]["input"]["parameters"] = [
          
    => [
             
    "type" => "string",
             
    "name" => "parameter",
             
    "optional" => false
          
    ],
          
    => [
             
    "type" => "rawtext",
             
    "name" => "value",
             
    "optional" => true
          
    ],
          
    => [
             
    "type" => "string",
             
    "name" => "name",
             
    "optional" => true
          
    ]
       ];

       return 
    $commandData;
    }
    Now, even though this works flawlessly, there's something I could not figure out. I'm trying to make it so available subcommands and parameters to use show up above the typing bar, in chat. Basically, the actual autocompletion part. I'm not sure how I would go around doing this. I've tried adding things to the array of the input parameters above, for example "args" holding an array with the possible arguments, and options... I don't know how I would do it, that's for sure.

    I hope anybody has messed around with this enough to provide me with an answer for this question. Thank you in advance!
     
    gistrec, SOFe, jasonwynn10 and 2 others like this.
  2. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Question : what is the use of Player?
     
  3. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    jasonwynn10 likes this.
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    The function is actually meant to use Player to get the player's permissions. Based on that, it'll sort out the availabe commands packet rather than sending all registered commands to players.
     
    jasonwynn10 likes this.
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You forgot about the aliases.
    Better get the base data to edit from parent::generateCustomData($player) rather than $this->commandData.
     
  6. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Yeah, that's what I did in the actual code. I thought I'd just share only the important part.
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    As a matter of fact it doesn't have to extend PluginCommand.
    I'm adding this to https://bit.ly/PmDev
    That's called overloads. See this gist by @gurun for details:
     
    Last edited: Apr 20, 2017
    Sandertv likes this.
  8. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Aha, so enum_values is what I'm after. Thanks @SOFe!
     
  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.