From 666f722df224e909d3a653802ae4958818f612f5 Mon Sep 17 00:00:00 2001 From: Muqsit Date: Sun, 10 Mar 2024 06:38:51 +0000 Subject: [PATCH] Address stopping issue with offline due commands handler --- plugin.yml | 2 +- .../handler/command/RegisteredTebexCommandExecutor.php | 4 ++-- src/muqsit/tebex/handler/command/TebexCommandSender.php | 2 +- src/muqsit/tebex/handler/due/TebexDueCommandsHandler.php | 4 ++-- .../tebex/handler/due/TebexDueOfflineCommandsHandler.php | 9 +++++++-- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/plugin.yml b/plugin.yml index 5983ccf..fc65ba9 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: Tebex main: muqsit\tebex\Loader -version: 0.1.11 +version: 0.1.12 author: Muqsit api: 5.0.0 permissions: diff --git a/src/muqsit/tebex/handler/command/RegisteredTebexCommandExecutor.php b/src/muqsit/tebex/handler/command/RegisteredTebexCommandExecutor.php index 8d81f31..5c5cc6c 100644 --- a/src/muqsit/tebex/handler/command/RegisteredTebexCommandExecutor.php +++ b/src/muqsit/tebex/handler/command/RegisteredTebexCommandExecutor.php @@ -78,13 +78,13 @@ function(CommandSender $sender, Command $command, string $label, array $args) : static $command_senders_force_check = null; if($command_senders_force_check === null){ $command_senders_force_check = []; - $this->handler->getDueCommandsHandler()->refresh(static function(int $offline_commands, int|TebexException $online_players) use(&$command_senders_force_check) : void{ + $this->handler->getDueCommandsHandler()->refresh(static function(int|TebexException $offline_commands, int|TebexException $online_players) use(&$command_senders_force_check) : void{ if($command_senders_force_check !== null){ foreach($command_senders_force_check as $sender){ if(!($sender instanceof Player) || $sender->isOnline()){ $sender->sendMessage( TextFormat::WHITE . "Refreshed command queue" . TextFormat::EOL . - TextFormat::WHITE . "Offline commands fetched: " . TextFormat::GRAY . $offline_commands . TextFormat::EOL . + TextFormat::WHITE . "Offline commands fetched: " . TextFormat::GRAY . ($offline_commands instanceof TebexException ? TextFormat::RED . TextFormat::ITALIC . $offline_commands->getMessage() . TextFormat::RESET : $offline_commands) . TextFormat::EOL . TextFormat::WHITE . "Online players due: " . TextFormat::GRAY . ($online_players instanceof TebexException ? TextFormat::RED . TextFormat::ITALIC . $online_players->getMessage() . TextFormat::RESET : $online_players) ); } diff --git a/src/muqsit/tebex/handler/command/TebexCommandSender.php b/src/muqsit/tebex/handler/command/TebexCommandSender.php index 302e0c5..ed68a7e 100644 --- a/src/muqsit/tebex/handler/command/TebexCommandSender.php +++ b/src/muqsit/tebex/handler/command/TebexCommandSender.php @@ -20,7 +20,7 @@ final public static function hasInstance() : bool{ } final public static function getInstance() : TebexCommandSender{ - return self::$instance ?? throw new LogicException("No instance of " . self::class . " has been set");; + return self::$instance ?? throw new LogicException("No instance of " . self::class . " has been set"); } final public static function setInstance(TebexCommandSender $instance) : void{ diff --git a/src/muqsit/tebex/handler/due/TebexDueCommandsHandler.php b/src/muqsit/tebex/handler/due/TebexDueCommandsHandler.php index 3d0bff2..f10608f 100644 --- a/src/muqsit/tebex/handler/due/TebexDueCommandsHandler.php +++ b/src/muqsit/tebex/handler/due/TebexDueCommandsHandler.php @@ -145,10 +145,10 @@ public function getList() : TebexDuePlayerList{ } /** - * @param (Closure(int, int|TebexException) : void)|null $callback + * @param (Closure(int|TebexException, int|TebexException) : void)|null $callback */ public function refresh(?Closure $callback = null) : void{ - $this->offline_commands_handler->check(function(int $offline_cmds_count) use($callback) : void{ + $this->offline_commands_handler->check(function(int|TebexException $offline_cmds_count) use($callback) : void{ $this->checkDuePlayers(null, static function(int|TebexException $response) use($offline_cmds_count, $callback) : void{ if($callback !== null){ $callback($offline_cmds_count, $response); diff --git a/src/muqsit/tebex/handler/due/TebexDueOfflineCommandsHandler.php b/src/muqsit/tebex/handler/due/TebexDueOfflineCommandsHandler.php index 14864a8..8f7a758 100644 --- a/src/muqsit/tebex/handler/due/TebexDueOfflineCommandsHandler.php +++ b/src/muqsit/tebex/handler/due/TebexDueOfflineCommandsHandler.php @@ -13,6 +13,7 @@ use muqsit\tebex\handler\TebexApiUtils; use muqsit\tebex\handler\TebexHandler; use muqsit\tebex\Loader; +use muqsit\tebexapi\utils\TebexException; use pocketmine\scheduler\ClosureTask; use pocketmine\Server; @@ -33,14 +34,18 @@ public function __construct(Loader $plugin, TebexHandler $handler, int $check_pe } /** - * @param (Closure(int) : void)|null $callback + * @param (Closure(int|TebexException) : void)|null $callback */ public function check(?Closure $callback = null) : void{ - $this->plugin->getApi()->getQueuedOfflineCommands(TebexResponseHandler::onSuccess(function(TebexQueuedOfflineCommandsInfo $info) use($callback) : void{ + $this->plugin->getApi()->getQueuedOfflineCommands(new TebexResponseHandler(function(TebexQueuedOfflineCommandsInfo $info) use($callback) : void{ if($callback !== null){ $callback(count($info->commands)); } $this->onFetchDueOfflineCommands($info); + }, function(TebexException $exception) use($callback) : void{ + if($callback !== null){ + $callback($exception); + } })); }