Suggestion Add args for the commands

Discussion in 'Suggestions' started by Ameer4Real, Feb 4, 2019.

  1. Ameer4Real

    Ameer4Real Shog Chips

    Messages:
    0
    GitHub:
    ameer4real
    Why don't you add args for the commands ?
    For example using this code:
    PHP:
    declare(strict_types=1);
    namespace 
    pocketmine\command\defaults;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\utils\InvalidCommandSyntaxException;
    use 
    pocketmine\lang\TranslationContainer;
    use 
    pocketmine\network\mcpe\protocol\AvailableCommandsPacket;
    use 
    pocketmine\network\mcpe\protocol\types\CommandParameter;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\TextFormat;
    use function 
    array_shift;
    use function 
    count;
    class 
    OpCommand extends VanillaCommand{
        public function 
    __construct(string $name){
            
    parent::__construct($name"%pocketmine.command.op.description""%commands.op.usage", [], [
                [
                    new 
    CommandParameter("player"AvailableCommandsPacket::ARG_TYPE_TARGETfalse)
                ]
            ]);
            
    $this->setPermission("pocketmine.command.op.give");
        }
        public function 
    execute(CommandSender $senderstring $commandLabel, array $args){
            if(!
    $this->testPermission($sender)){
                return 
    true;
            }
            if(
    count($args) === 0){
                throw new 
    InvalidCommandSyntaxException();
            }
            
    $name array_shift($args);
            
    $player $sender->getServer()->getOfflinePlayer($name);
            
    Command::broadcastCommandMessage($sender, new TranslationContainer("commands.op.success", [$player->getName()]));
            if(
    $player instanceof Player){
                
    $player->sendMessage(TextFormat::GRAY "You are now op!");
            }
            
    $player->setOp(true);
            return 
    true;
        }
    }

    In the OpCommand.php instead of using the current one
     
    Last edited: Feb 5, 2019
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin Noobiest member in the PMMP Team

    Messages:
    1,765
    GitHub:
    sof3
    Reminder: use [php] and [/php] to put your PHP code in a code block.
     
  3. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    460
    GitHub:
    InspectorGadget
    Hi, what's your suggestion? It isn't clear enough
     
  4. Ameer4Real

    Ameer4Real Shog Chips

    Messages:
    0
    GitHub:
    ameer4real
    Thanks
     
  5. Ameer4Real

    Ameer4Real Shog Chips

    Messages:
    0
    GitHub:
    ameer4real
    I mean when you type the command in the chat it says [unknown:args] so why don't they put the args here for example: the /op command
    The args are /op {player: target}
    I don't think I explained it well but here is an image that describes what I mean
     

    Attached Files:

  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin Noobiest member in the PMMP Team

    Messages:
    1,765
    GitHub:
    sof3
    We have been planning for a new command API that allows commands to declare their arguments, but that would be an API-breaking change, and we haven't reached consensus how to implement this yet.
     
  7. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    693
    GitHub:
    dktapps
    The proposed code adds zero value and tethers the commands API to the protocol. It is simply cosmetic and does not solve any of the actual issues which plague the commands API.
     

Share This Page

  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.