Skip to content

Commit

Permalink
Address stopping issue with offline due commands handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Muqsit committed Mar 10, 2024
1 parent 624b88b commit 666f722
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/muqsit/tebex/handler/command/TebexCommandSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions src/muqsit/tebex/handler/due/TebexDueCommandsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}));
}

Expand Down

0 comments on commit 666f722

Please sign in to comment.