From c4f29043871e25f70be5c3021ffcf6176536b51c Mon Sep 17 00:00:00 2001 From: Muqsit Date: Mon, 13 Feb 2023 12:39:02 +0000 Subject: [PATCH] Use tebexapi v0.1.0 --- .poggit.yml | 2 +- plugin.yml | 2 +- src/muqsit/tebex/Loader.php | 6 ++--- src/muqsit/tebex/handler/TebexApiUtils.php | 10 +++---- .../RegisteredTebexCommandExecutor.php | 22 ++++++++-------- .../UnregisteredTebexCommandExecutor.php | 6 ++--- .../handler/due/TebexDueCommandsHandler.php | 26 +++++++++---------- .../due/TebexDueOfflineCommandsHandler.php | 18 ++++++------- .../due/playerlist/TebexDuePlayerList.php | 6 ++--- .../indexer/NameBasedPlayerIndexer.php | 2 +- .../indexer/XuidBasedPlayerIndexer.php | 4 +-- .../due/session/TebexPlayerSession.php | 12 ++++----- 12 files changed, 58 insertions(+), 58 deletions(-) diff --git a/.poggit.yml b/.poggit.yml index 4b88aa0..ef813e7 100644 --- a/.poggit.yml +++ b/.poggit.yml @@ -8,5 +8,5 @@ projects: path: "" libs: - src: muqsit/tebexapi/TebexApi - version: ^0.0.3 + version: ^0.1.0 ... \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index b16c0b2..038f9ed 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: Tebex main: muqsit\tebex\Loader -version: 0.1.2 +version: 0.1.3 author: Muqsit api: 4.0.0 permissions: diff --git a/src/muqsit/tebex/Loader.php b/src/muqsit/tebex/Loader.php index 9ab3120..8d054a5 100644 --- a/src/muqsit/tebex/Loader.php +++ b/src/muqsit/tebex/Loader.php @@ -109,9 +109,9 @@ private function init(ConnectionBasedTebexApi $api, TebexInformation $informatio } $this->command->setExecutor($executor); - $account = $this->information->getAccount(); - $server = $this->information->getServer(); - $this->getLogger()->debug("Listening to events of \"{$server->getName()}\"[#{$server->getId()}] server as \"{$account->getName()}\"[#{$account->getId()}] (latency: " . round($this->getApi()->getLatency() * 1000) . "ms)"); + $account = $this->information->account; + $server = $this->information->server; + $this->getLogger()->debug("Listening to events of \"{$server->name}\"[#{$server->id}] server as \"{$account->name}\"[#{$account->id}] (latency: " . round($this->getApi()->getLatency() * 1000) . "ms)"); } public function getApi() : TebexApi{ diff --git a/src/muqsit/tebex/handler/TebexApiUtils.php b/src/muqsit/tebex/handler/TebexApiUtils.php index 01a9dae..afd509a 100644 --- a/src/muqsit/tebex/handler/TebexApiUtils.php +++ b/src/muqsit/tebex/handler/TebexApiUtils.php @@ -18,11 +18,11 @@ final class TebexApiUtils{ public static function convertGuiItemToItem(TebexGuiItem $gui_item) : Item{ - $item = StringToItemParser::getInstance()->parse($gui_item->getValue()); + $item = StringToItemParser::getInstance()->parse($gui_item->value); if($item === null){ $plugin = Server::getInstance()->getPluginManager()->getPlugin("Tebex"); if($plugin instanceof Loader){ - $plugin->getLogger()->warning("Failed to parse GUI item \"{$gui_item->getValue()}\", using PAPER as fallback"); + $plugin->getLogger()->warning("Failed to parse GUI item \"{$gui_item->value}\", using PAPER as fallback"); } return VanillaItems::PAPER(); } @@ -34,18 +34,18 @@ public static function onlineFormatCommand(TebexCommand $command, Player $player return strtr($command->asRawString(), [ "{name}" => $gamertag, "{player}" => $gamertag, - "{username}" => "\"{$due_player->getName()}\"", + "{username}" => "\"{$due_player->name}\"", "{id}" => $player->getXuid() ]); } public static function offlineFormatCommand(TebexCommand $command, TebexDuePlayer $due_player) : string{ - $gamertag = "\"{$due_player->getName()}\""; + $gamertag = "\"{$due_player->name}\""; return strtr($command->asRawString(), [ "{name}" => $gamertag, "{player}" => $gamertag, "{username}" => $gamertag, - "{id}" => $due_player->getUuid() ?? "" + "{id}" => $due_player->uuid ?? "" ]); } } \ No newline at end of file diff --git a/src/muqsit/tebex/handler/command/RegisteredTebexCommandExecutor.php b/src/muqsit/tebex/handler/command/RegisteredTebexCommandExecutor.php index 764f5a1..ced05d2 100644 --- a/src/muqsit/tebex/handler/command/RegisteredTebexCommandExecutor.php +++ b/src/muqsit/tebex/handler/command/RegisteredTebexCommandExecutor.php @@ -45,23 +45,23 @@ function(CommandSender $sender, Command $command, string $label, array $args) : $this->registerSubCommand(new TebexSubCommand("info", "Fetch Tebex account, server and API info", new ClosureCommandExecutor( function(CommandSender $sender, Command $command, string $label, array $args) : bool{ $info = $this->plugin->getInformation(); - $account = $info->getAccount(); - $server = $info->getServer(); + $account = $info->account; + $server = $info->server; $sender->sendMessage( "" . TextFormat::EOL . TextFormat::BOLD . TextFormat::WHITE . "Tebex Account" . TextFormat::RESET . TextFormat::EOL . - TextFormat::WHITE . "ID: " . TextFormat::GRAY . $account->getId() . TextFormat::EOL . - TextFormat::WHITE . "Domain: " . TextFormat::GRAY . $account->getDomain() . TextFormat::EOL . - TextFormat::WHITE . "Name: " . TextFormat::GRAY . $account->getName() . TextFormat::EOL . - TextFormat::WHITE . "Currency: " . TextFormat::GRAY . "{$account->getCurrency()->getIso4217()} ({$account->getCurrency()->getSymbol()})" . TextFormat::EOL . - TextFormat::WHITE . "Online Mode: " . TextFormat::GRAY . ($account->isOnlineModeEnabled() ? "Enabled" : "Disabled") . TextFormat::EOL . - TextFormat::WHITE . "Game Type: " . TextFormat::GRAY . $account->getGameType() . TextFormat::EOL . - TextFormat::WHITE . "Event Logging: " . TextFormat::GRAY . ($account->isLogEventsEnabled() ? "Enabled" : "Disabled") . TextFormat::EOL . + TextFormat::WHITE . "ID: " . TextFormat::GRAY . $account->id . TextFormat::EOL . + TextFormat::WHITE . "Domain: " . TextFormat::GRAY . $account->domain . TextFormat::EOL . + TextFormat::WHITE . "Name: " . TextFormat::GRAY . $account->name . TextFormat::EOL . + TextFormat::WHITE . "Currency: " . TextFormat::GRAY . "{$account->currency->iso_4217} ({$account->currency->symbol})" . TextFormat::EOL . + TextFormat::WHITE . "Online Mode: " . TextFormat::GRAY . ($account->online_mode ? "Enabled" : "Disabled") . TextFormat::EOL . + TextFormat::WHITE . "Game Type: " . TextFormat::GRAY . $account->game_type . TextFormat::EOL . + TextFormat::WHITE . "Event Logging: " . TextFormat::GRAY . ($account->log_events ? "Enabled" : "Disabled") . TextFormat::EOL . "" . TextFormat::EOL . TextFormat::BOLD . TextFormat::WHITE . "Tebex Server" . TextFormat::RESET . TextFormat::EOL . - TextFormat::WHITE . "ID: " . TextFormat::GRAY . $server->getId() . TextFormat::EOL . - TextFormat::WHITE . "Name: " . TextFormat::GRAY . $server->getName() . TextFormat::EOL . + TextFormat::WHITE . "ID: " . TextFormat::GRAY . $server->id . TextFormat::EOL . + TextFormat::WHITE . "Name: " . TextFormat::GRAY . $server->name . TextFormat::EOL . "" . TextFormat::EOL . TextFormat::BOLD . TextFormat::WHITE . "Tebex API" . TextFormat::RESET . TextFormat::EOL . TextFormat::WHITE . "Latency: " . TextFormat::GRAY . round($this->plugin->getApi()->getLatency() * 1000) . "ms" . TextFormat::EOL . diff --git a/src/muqsit/tebex/handler/command/UnregisteredTebexCommandExecutor.php b/src/muqsit/tebex/handler/command/UnregisteredTebexCommandExecutor.php index 7a68b2c..9a6af02 100644 --- a/src/muqsit/tebex/handler/command/UnregisteredTebexCommandExecutor.php +++ b/src/muqsit/tebex/handler/command/UnregisteredTebexCommandExecutor.php @@ -30,9 +30,9 @@ public static function handleTypeSecret(Loader $loader, CommandSender $sender, s $config->set("secret", $secret); $config->save(); - $account = $info->getAccount(); - $server = $info->getServer(); - $sender->sendMessage("Successfully logged in to server (#{$server->getId()}) {$server->getName()} as (#{$account->getId()}) {$account->getName()}!"); + $account = $info->account; + $server = $info->server; + $sender->sendMessage("Successfully logged in to server (#{$server->id}) {$server->name} as (#{$account->id}) {$account->name}!"); } } diff --git a/src/muqsit/tebex/handler/due/TebexDueCommandsHandler.php b/src/muqsit/tebex/handler/due/TebexDueCommandsHandler.php index 70ee984..f0a882b 100644 --- a/src/muqsit/tebex/handler/due/TebexDueCommandsHandler.php +++ b/src/muqsit/tebex/handler/due/TebexDueCommandsHandler.php @@ -52,26 +52,26 @@ public function __construct( $this->offline_commands_handler = new TebexDueOfflineCommandsHandler($plugin, $handler); $api = $plugin->getApi(); - $this->list = self::getListFromGameType($plugin->getInformation()->getAccount()->getGameType(), function(Player $player, TebexDuePlayerHolder $holder) use($api, $handler) : void{ + $this->list = self::getListFromGameType($plugin->getInformation()->account->game_type, function(Player $player, TebexDuePlayerHolder $holder) use($api, $handler) : void{ $session = $this->list->getOnlinePlayer($player); assert($session !== null); - $api->getQueuedOnlineCommands($holder->getPlayer()->getId(), TebexResponseHandler::onSuccess(function(TebexQueuedOnlineCommandsInfo $info) use($player, $session, $holder, $handler) : void{ + $api->getQueuedOnlineCommands($holder->getPlayer()->id, TebexResponseHandler::onSuccess(function(TebexQueuedOnlineCommandsInfo $info) use($player, $session, $holder, $handler) : void{ if(!$player->isOnline()){ return; } - $commands = $info->getCommands(); + $commands = $info->commands; $total_commands = count($commands); $timestamp = microtime(true); foreach($commands as $tebex_command){ $session->executeOnlineCommand($tebex_command, $holder->getPlayer(), function(bool $success) use($tebex_command, $handler, &$total_commands, $player, $holder, $timestamp) : void{ - $command_string = TebexApiUtils::onlineFormatCommand($tebex_command->getCommand(), $player, $holder->getPlayer()); + $command_string = TebexApiUtils::onlineFormatCommand($tebex_command->command, $player, $holder->getPlayer()); if(!$success){ $this->logger->warning("Failed to execute online command: {$command_string}"); return; } - $command_id = $tebex_command->getId(); + $command_id = $tebex_command->id; $handler->queueCommandDeletion($command_id); if(--$total_commands === 0){ $current_holder = $this->list->getTebexAwaitingPlayer($player); @@ -95,7 +95,7 @@ public function __construct( public function markAllAsExecuted(?Closure $callback = null) : void{ $this->plugin->getApi()->getDuePlayersList(TebexResponseHandler::onSuccess(function(TebexDuePlayersInfo $result) use($callback) : void{ $marked = 0; - $batches = count($result->getPlayers()) + 1; + $batches = count($result->players) + 1; $cb = static function(int $done) use(&$marked, &$batches, $callback) : void{ $marked += $done; @@ -108,11 +108,11 @@ public function markAllAsExecuted(?Closure $callback = null) : void{ $this->offline_commands_handler->markAllAsExecuted($cb); - foreach($result->getPlayers() as $player){ - $this->plugin->getApi()->getQueuedOnlineCommands($player->getId(), TebexResponseHandler::onSuccess(function(TebexQueuedOnlineCommandsInfo $info) use($cb) : void{ - $commands = $info->getCommands(); + foreach($result->players as $player){ + $this->plugin->getApi()->getQueuedOnlineCommands($player->id, TebexResponseHandler::onSuccess(function(TebexQueuedOnlineCommandsInfo $info) use($cb) : void{ + $commands = $info->commands; foreach($commands as $command){ - $this->handler->queueCommandDeletion($command->getId()); + $this->handler->queueCommandDeletion($command->id); } $cb(count($commands)); })); @@ -163,17 +163,17 @@ public function checkDuePlayers(?Closure $reschedule_condition = null, ?Closure $this->plugin->getApi()->getDuePlayersList(TebexResponseHandler::onSuccess(function(TebexDuePlayersInfo $result) use($reschedule_condition, $callback) : void{ $this->onFetchDuePlayers($result); if($callback !== null){ - $callback(count($result->getPlayers())); + $callback(count($result->players)); } if($reschedule_condition !== null && $reschedule_condition()){ - $next_check = $result->getMeta()->getNextCheck(); + $next_check = $result->meta->next_check; $this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask(function() use($reschedule_condition, $callback) : void{ $this->checkDuePlayers($reschedule_condition, $callback); }), $next_check * 20); } })); } private function onFetchDuePlayers(TebexDuePlayersInfo $result) : void{ - $players = $result->getPlayers(); + $players = $result->players; $this->list->update($players); $players_c = count($players); diff --git a/src/muqsit/tebex/handler/due/TebexDueOfflineCommandsHandler.php b/src/muqsit/tebex/handler/due/TebexDueOfflineCommandsHandler.php index 7a08bce..24b90a1 100644 --- a/src/muqsit/tebex/handler/due/TebexDueOfflineCommandsHandler.php +++ b/src/muqsit/tebex/handler/due/TebexDueOfflineCommandsHandler.php @@ -38,7 +38,7 @@ public function __construct(Loader $plugin, TebexHandler $handler, int $check_pe public function check(?Closure $callback = null) : void{ $this->plugin->getApi()->getQueuedOfflineCommands(TebexResponseHandler::onSuccess(function(TebexQueuedOfflineCommandsInfo $info) use($callback) : void{ if($callback !== null){ - $callback(count($info->getCommands())); + $callback(count($info->commands)); } $this->onFetchDueOfflineCommands($info); })); @@ -49,9 +49,9 @@ public function check(?Closure $callback = null) : void{ */ public function markAllAsExecuted(?Closure $callback = null) : void{ $this->plugin->getApi()->getQueuedOfflineCommands(TebexResponseHandler::onSuccess(function(TebexQueuedOfflineCommandsInfo $info) use($callback) : void{ - $commands = $info->getCommands(); + $commands = $info->commands; foreach($commands as $command){ - $this->handler->queueCommandDeletion($command->getId()); + $this->handler->queueCommandDeletion($command->id); } if($callback !== null){ $callback(count($commands)); @@ -60,16 +60,16 @@ public function markAllAsExecuted(?Closure $callback = null) : void{ } private function onFetchDueOfflineCommands(TebexQueuedOfflineCommandsInfo $info) : void{ - $commands = $info->getCommands(); + $commands = $info->commands; $commands_c = count($commands); $this->logger->debug("Fetched {$commands_c} offline command" . ($commands_c === 1 ? "" : "s")); foreach($commands as $command){ $this->executeCommand($command, function(bool $success) use($command) : void{ - $command_string = TebexApiUtils::offlineFormatCommand($command->getCommand(), $command->getPlayer()); + $command_string = TebexApiUtils::offlineFormatCommand($command->command, $command->player); if($success){ - $command_id = $command->getId(); + $command_id = $command->id; $this->handler->queueCommandDeletion($command_id); $this->logger->info("Executed offline command #{$command_id}: {$command_string}"); }else{ @@ -84,9 +84,9 @@ private function onFetchDueOfflineCommands(TebexQueuedOfflineCommandsInfo $info) * @param Closure(bool) : void $callback */ private function executeCommand(TebexQueuedOfflineCommand $command, Closure $callback) : void{ - $delay = $command->getConditions()->getDelay(); + $delay = $command->conditions->delay; if($delay > 0){ - if(!isset($this->delayed[$id = $command->getId()])){ + if(!isset($this->delayed[$id = $command->id])){ $this->delayed[$id] = $id; $this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask(function() use($id, $command, $callback) : void{ $callback($this->instantlyExecuteCommand($command)); @@ -99,6 +99,6 @@ private function executeCommand(TebexQueuedOfflineCommand $command, Closure $cal } private function instantlyExecuteCommand(TebexQueuedOfflineCommand $command) : bool{ - return Server::getInstance()->dispatchCommand(TebexCommandSender::getInstance(), TebexApiUtils::offlineFormatCommand($command->getCommand(), $command->getPlayer())); + return Server::getInstance()->dispatchCommand(TebexCommandSender::getInstance(), TebexApiUtils::offlineFormatCommand($command->command, $command->player)); } } \ No newline at end of file diff --git a/src/muqsit/tebex/handler/due/playerlist/TebexDuePlayerList.php b/src/muqsit/tebex/handler/due/playerlist/TebexDuePlayerList.php index f891f17..1925201 100644 --- a/src/muqsit/tebex/handler/due/playerlist/TebexDuePlayerList.php +++ b/src/muqsit/tebex/handler/due/playerlist/TebexDuePlayerList.php @@ -64,8 +64,8 @@ public function update(array $due_players) : void{ $this->tebex_due_players_by_index = []; foreach($due_players as $player){ $holder = new TebexDuePlayerHolder($player); - $this->tebex_due_players_by_id[$player->getId()] = $holder; - $this->tebex_due_players_by_index[$index = $this->indexer->fromTebexDuePlayer($player)] = $player->getId(); + $this->tebex_due_players_by_id[$player->id] = $holder; + $this->tebex_due_players_by_index[$index = $this->indexer->fromTebexDuePlayer($player)] = $player->id; if(isset($this->online_players[$index])){ $this->onMatch($this->online_players[$index]->getPlayer(), $holder); } @@ -74,7 +74,7 @@ public function update(array $due_players) : void{ public function remove(TebexDuePlayerHolder $holder) : void{ $player = $holder->getPlayer(); - unset($this->tebex_due_players_by_id[$player->getId()], $this->tebex_due_players_by_index[$this->indexer->fromTebexDuePlayer($player)]); + unset($this->tebex_due_players_by_id[$player->id], $this->tebex_due_players_by_index[$this->indexer->fromTebexDuePlayer($player)]); } public function getTebexAwaitingPlayer(Player $player) : ?TebexDuePlayerHolder{ diff --git a/src/muqsit/tebex/handler/due/playerlist/indexer/NameBasedPlayerIndexer.php b/src/muqsit/tebex/handler/due/playerlist/indexer/NameBasedPlayerIndexer.php index 4396d10..6acf904 100644 --- a/src/muqsit/tebex/handler/due/playerlist/indexer/NameBasedPlayerIndexer.php +++ b/src/muqsit/tebex/handler/due/playerlist/indexer/NameBasedPlayerIndexer.php @@ -17,6 +17,6 @@ public function fromPlayer(Player $player) : string{ } public function fromTebexDuePlayer(TebexDuePlayer $player) : string{ - return strtolower($player->getName()); + return strtolower($player->name); } } \ No newline at end of file diff --git a/src/muqsit/tebex/handler/due/playerlist/indexer/XuidBasedPlayerIndexer.php b/src/muqsit/tebex/handler/due/playerlist/indexer/XuidBasedPlayerIndexer.php index 3919655..5821d6b 100644 --- a/src/muqsit/tebex/handler/due/playerlist/indexer/XuidBasedPlayerIndexer.php +++ b/src/muqsit/tebex/handler/due/playerlist/indexer/XuidBasedPlayerIndexer.php @@ -22,7 +22,7 @@ public function fromPlayer(Player $player) : string{ } public function fromTebexDuePlayer(TebexDuePlayer $player) : string{ - $xuid = $player->getUuid(); // Tebex player uuids in Minecraft: Bedrock Edition (Online) mode is xbox's xuid - return $xuid ?? throw new InvalidArgumentException("Cannot retrieve XUID of Tebex due player: {$player->getName()}"); + $xuid = $player->uuid; // Tebex player uuids in Minecraft: Bedrock Edition (Online) mode is xbox's xuid + return $xuid ?? throw new InvalidArgumentException("Cannot retrieve XUID of Tebex due player: {$player->name}"); } } \ No newline at end of file diff --git a/src/muqsit/tebex/handler/due/session/TebexPlayerSession.php b/src/muqsit/tebex/handler/due/session/TebexPlayerSession.php index 84e9e66..41519c9 100644 --- a/src/muqsit/tebex/handler/due/session/TebexPlayerSession.php +++ b/src/muqsit/tebex/handler/due/session/TebexPlayerSession.php @@ -46,8 +46,8 @@ public function destroy() : void{ * @param Closure(bool) : void $callback */ public function executeOnlineCommand(TebexQueuedOnlineCommand $command, TebexDuePlayer $due_player, Closure $callback) : void{ - $conditions = $command->getConditions(); - $delay = $conditions->getDelay(); + $conditions = $command->conditions; + $delay = $conditions->delay; if($delay > 0){ $this->scheduleCommandForDelay($command, $due_player, $delay * 20, $callback); }else{ @@ -63,7 +63,7 @@ public function executeOnlineCommand(TebexQueuedOnlineCommand $command, TebexDue * @return bool */ private function scheduleCommandForDelay(TebexQueuedOnlineCommand $command, TebexDuePlayer $due_player, int $delay, Closure $callback) : bool{ - if(isset($this->delayed_online_command_handlers[$id = $command->getId()])){ + if(isset($this->delayed_online_command_handlers[$id = $command->id])){ return false; } @@ -75,8 +75,8 @@ private function scheduleCommandForDelay(TebexQueuedOnlineCommand $command, Tebe } private function instantlyExecuteOnlineCommand(TebexQueuedOnlineCommand $command, TebexDuePlayer $due_player) : bool{ - $conditions = $command->getConditions(); - $slots = $conditions->getInventorySlots(); + $conditions = $command->conditions; + $slots = $conditions->slots; if($slots > 0){ $inventory = $this->player->getInventory(); $free_slots = $inventory->getSize() - count($inventory->getContents()); @@ -85,6 +85,6 @@ private function instantlyExecuteOnlineCommand(TebexQueuedOnlineCommand $command } } - return $this->player->getServer()->dispatchCommand(TebexCommandSender::getInstance(), TebexApiUtils::onlineFormatCommand($command->getCommand(), $this->player, $due_player)); + return $this->player->getServer()->dispatchCommand(TebexCommandSender::getInstance(), TebexApiUtils::onlineFormatCommand($command->command, $this->player, $due_player)); } } \ No newline at end of file