Skip to content

Allowing custom command to handle/parse the command line by itself. #6704

@NTT1906

Description

@NTT1906

Problem description

Currently, SimpleCommandMap hardcoded the handling of command line when parsing them to args and there is not a non-hacky way to handle the raw inputs data without messing too much with PMMP internal.

Proposed solution

Allow command itself to dispatch/parse command line to args by itself via an internal method that can be overridden. The SimpleCommandMap only take the first token from the command line to find the command entry.

<?php
class Command{
    ...
    public function parseCommandLine(string $commandLine) : array{
        return CommandHelper::parseQuoteAware($commandLine);
    }
    ...
}

class CustomCommand extends Command{
    public function parseCommandLine(string $commandLine) : array{
        // Custom parse
    }
}

class SimpleCommandMap{
  ...
  public function dispatch(CommandSender $sender, string $commandLine) : bool{
    $sentCommandLabel = "";
    $parts = preg_split('/\s+/u', $commandLine, 2);
    if($parts !== false) {
      $sentCommandLabel = $parts[0];
      if ($target = $this->getEntry($sentCommandLabel)) !== null){
         $args = $target->command->handleCommandLine($parts[1]);
         // Command execute and stuff
      }
    }
    ...
}

Alternative solutions or workarounds

A plugin can create an extend of SimpleComamndMap, move over the data and then use reflection API/Closure bind to change the commandMap in Server instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Category: APIRelated to the plugin APIResolution: ObsoleteSuperseded by other changesType: EnhancementContributes features or other improvements to PocketMine-MP

    Type

    No type

    Projects

    Status

    Abandoned

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions