diff --git a/src/command/ClosureCommand.php b/src/command/ClosureCommand.php new file mode 100644 index 000000000..289c82853 --- /dev/null +++ b/src/command/ClosureCommand.php @@ -0,0 +1,60 @@ + $args) : mixed + */ +final class ClosureCommand extends Command{ + /** @phpstan-var Execute */ + private \Closure $execute; + + /** + * @param string[] $permissions + * @phpstan-param Execute $execute + */ + public function __construct( + string $name, + \Closure $execute, + array $permissions, + Translatable|string $description = "", + Translatable|string|null $usageMessage = null, + array $aliases = [] + ){ + Utils::validateCallableSignature( + fn(CommandSender $sender, Command $command, string $commandLabel, array $args) : mixed => 1, + $execute, + ); + $this->execute = $execute; + parent::__construct($name, $description, $usageMessage, $aliases); + $this->setPermissions($permissions); + } + + public function execute(CommandSender $sender, string $commandLabel, array $args){ + return ($this->execute)($sender, $this, $commandLabel, $args); + } +}