From aac594439688ea01598bd4d460a9754188f8d14d Mon Sep 17 00:00:00 2001 From: ShockedPlot7560 Date: Wed, 19 Jul 2023 17:38:15 +0200 Subject: [PATCH] Accept Translatable permission messages in `Command` (#5830) --- src/command/Command.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/command/Command.php b/src/command/Command.php index 02bae60d9e..30338ddad7 100644 --- a/src/command/Command.php +++ b/src/command/Command.php @@ -58,7 +58,7 @@ abstract class Command{ /** @var string[] */ private array $permission = []; - private ?string $permissionMessage = null; + private Translatable|string|null $permissionMessage = null; /** * @param string[] $aliases @@ -112,10 +112,11 @@ abstract class Command{ return true; } - if($this->permissionMessage === null){ - $target->sendMessage(KnownTranslationFactory::pocketmine_command_error_permission($this->name)->prefix(TextFormat::RED)); - }elseif($this->permissionMessage !== ""){ - $target->sendMessage(str_replace("", $permission ?? implode(";", $this->permission), $this->permissionMessage)); + $message = $this->permissionMessage ?? KnownTranslationFactory::pocketmine_command_error_permission($this->name); + if($message instanceof Translatable){ + $target->sendMessage($message->prefix(TextFormat::RED)); + }elseif($message !== ""){ + $target->sendMessage(str_replace("", $permission ?? implode(";", $this->permission), $message)); } return false; @@ -187,7 +188,7 @@ abstract class Command{ return $this->activeAliases; } - public function getPermissionMessage() : ?string{ + public function getPermissionMessage() : Translatable|string|null{ return $this->permissionMessage; } @@ -213,7 +214,7 @@ abstract class Command{ $this->description = $description; } - public function setPermissionMessage(string $permissionMessage) : void{ + public function setPermissionMessage(Translatable|string $permissionMessage) : void{ $this->permissionMessage = $permissionMessage; }