diff --git a/src/CortexPE/Commando/args/TargetArgument.php b/src/CortexPE/Commando/args/TargetArgument.php new file mode 100644 index 0000000..53e8f9a --- /dev/null +++ b/src/CortexPE/Commando/args/TargetArgument.php @@ -0,0 +1,64 @@ +. + * + * Written by @CortexPE + * + */ +declare(strict_types=1); + +namespace CortexPE\Commando\args; + + +use pocketmine\command\CommandSender; +use pocketmine\network\mcpe\protocol\AvailableCommandsPacket; +use pocketmine\Player; +use pocketmine\Server; + +class TargetArgument extends BaseArgument { + /** @var Server */ + private $server; + + public function __construct(string $name, bool $optional) { + parent::__construct($name, $optional); + $this->server = Server::getInstance(); + } + + public function getNetworkType() : int { + return AvailableCommandsPacket::ARG_TYPE_TARGET; + } + + public function getTypeName() : string { + return "target"; + } + + public function canParse(string $testString, CommandSender $sender) : bool { + return Player::isValidUserName($testString); + } + + public function parse(string $argument, CommandSender $sender) { + // TODO: handle @a @e @p @r @s @c @v + $player = $this->server->getPlayer($argument) ?? $this->server->getOfflinePlayer($argument); + return $player->getName(); + } +}