From ed4880f79009b848a41fbd91268a4cb4d44f7b26 Mon Sep 17 00:00:00 2001 From: toby7002 <144540995+toby7002@users.noreply.github.com> Date: Fri, 6 Oct 2023 19:11:12 +0700 Subject: [PATCH] Add some args for list command --- resources/lang/en_us.json | 15 +++++-- src/thebigcrafter/omp/OhMyPMMP.php | 2 + .../omp/commands/subcommands/ListCommand.php | 45 +++++++++++-------- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/resources/lang/en_us.json b/resources/lang/en_us.json index 0b6e0f0..f294f6b 100644 --- a/resources/lang/en_us.json +++ b/resources/lang/en_us.json @@ -1,7 +1,9 @@ { - "text.cache.running": "§eFetching plugins list from Poggit", - "text.cache.failed": "§cCould not get Poggit plugins list from Poggit: {%reason}", + "text.cache.running": "§eFinished caching", + "text.cache.failed": "§cA error has occurred: {%reason}", "text.cache.successfully": "§a{{count}} Poggit plugins has been cached successfully", + "text.cache.installed.plugin": "§eGetting installed plugins", + "text.cache.upgradable.plugin": "§eChecking upgradable plugins", "command.version.description": "Get plugin version", "command.version.api_version": "§aPocketMine-MP API v{{version}}", @@ -10,5 +12,12 @@ "command.help.description": "Print oh-my-pmmp command line options", - "command.list.description": "List the available, installed and, upgradeable plugins" + "command.list.description": "List the available, installed and, upgradeable plugins", + "command.list.plugin.name": "Name: {{name}}", + "command.list.plugin.versions": "Versions: {{versions}}", + "command.list.plugin.description": "Description: {{description}}", + "command.list.plugin.homepage": "Homepage: {{homepage}}", + "command.list.plugin.downloads": "Downloads: {{downloads}}", + "command.list.plugin.score": "Score: {{score}}", + "command.list.plugin.license": "License: {{license}}" } diff --git a/src/thebigcrafter/omp/OhMyPMMP.php b/src/thebigcrafter/omp/OhMyPMMP.php index c72c2f7..824518a 100644 --- a/src/thebigcrafter/omp/OhMyPMMP.php +++ b/src/thebigcrafter/omp/OhMyPMMP.php @@ -19,6 +19,7 @@ use thebigcrafter\Iodine\Iodine; use thebigcrafter\omp\commands\OMPCommand; use thebigcrafter\omp\lang\OMPLanguage; +use thebigcrafter\omp\tasks\CacheInstalledPlugins; use thebigcrafter\omp\tasks\CachePlugins; use thebigcrafter\omp\trait\Language; use function is_dir; @@ -67,6 +68,7 @@ public function loadLanguage() : void self::setLanguage(new OMPLanguage($selectedLanguage)); } public function cachePlugins() : void { + Iodine::async(function() { $this->getLogger()->info(self::getLanguage()->translate("text.cache.running")); CachePlugins::run()->await(); diff --git a/src/thebigcrafter/omp/commands/subcommands/ListCommand.php b/src/thebigcrafter/omp/commands/subcommands/ListCommand.php index 7570542..be3f78c 100644 --- a/src/thebigcrafter/omp/commands/subcommands/ListCommand.php +++ b/src/thebigcrafter/omp/commands/subcommands/ListCommand.php @@ -11,6 +11,8 @@ namespace thebigcrafter\omp\commands\subcommands; +use CortexPE\Commando\args\IntegerArgument; +use CortexPE\Commando\args\RawStringArgument; use CortexPE\Commando\BaseSubCommand; use pocketmine\command\CommandSender; use pocketmine\Server; @@ -22,34 +24,41 @@ class ListCommand extends BaseSubCommand { protected function prepare() : void { $this->setPermission("oh-my-pmmp.list"); + + $this->registerArgument(0, new IntegerArgument("page", true)); + $this->registerArgument(1, new RawStringArgument("type", true)); // 1 => available, 2 => installed, 3 => 3 for upgradable } /** * @param array $args */ public function onRun(CommandSender $sender,string $aliasUsed,array $args) : void { - foreach (PluginsPool::getStorage() as $plugin) { - $this->renderBlock($sender, $plugin); + $page = isset($args["page"]) ?: 1; + $type = isset($args["type"]) ?: 1; + + switch ($type) { + case "1": + foreach (PluginsPool::getStorage() as $plugin) { + $this->renderBlock($sender, $plugin); + } + break; + case "2": + break; + case "3": + break; } } - private function renderBlock(CommandSender $sender, PluginCache $plugin) { - $name = $plugin->getName(); - $versions = implode(",", $plugin->getVersions()); - $desc = $plugin->getShortDescription(); - $homepage = $plugin->getHomepage(); - $downloads = $plugin->getDownloads(); - $score = $plugin->getScore(); - $license = $plugin->getLicense(); - + private function renderBlock(CommandSender $sender, PluginCache $plugin): void + { $sender->sendMessage("================" . PHP_EOL); - $sender->sendMessage("# Name: $name"); - $sender->sendMessage("# Versions: $versions"); - $sender->sendMessage("# Description: $desc"); - $sender->sendMessage("# Homepage: $homepage"); - $sender->sendMessage("# Downloads: $downloads"); - $sender->sendMessage("# Score: $score"); - $sender->sendMessage("# License: $license"); + $sender->sendMessage("# " . OhMyPMMP::getLanguage()->translate("command.list.plugin.name", ["name" => $plugin->getName()])); + $sender->sendMessage("# " . OhMyPMMP::getLanguage()->translate("command.list.plugin.versions", ["versions" => implode(",", $plugin->getVersions())])); + $sender->sendMessage("# " . OhMyPMMP::getLanguage()->translate("command.list.plugin.description", ["description" => $plugin->getShortDescription()])); + $sender->sendMessage("# " . OhMyPMMP::getLanguage()->translate("command.list.plugin.homepage", ["homepage" => $plugin->getHomepage()])); + $sender->sendMessage("# " . OhMyPMMP::getLanguage()->translate("command.list.plugin.downloads", ["downloads" => $plugin->getDownloads()])); + $sender->sendMessage("# " . OhMyPMMP::getLanguage()->translate("command.list.plugin.score", ["score" => $plugin->getScore()])); + $sender->sendMessage("# " . OhMyPMMP::getLanguage()->translate("command.list.plugin.license", ["license" => $plugin->getLicense()])); $sender->sendMessage("================" . PHP_EOL . PHP_EOL); } }