Skip to content

Commit

Permalink
Add some args for list command
Browse files Browse the repository at this point in the history
  • Loading branch information
toby7002 committed Oct 6, 2023
1 parent 21cdf57 commit ed4880f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
15 changes: 12 additions & 3 deletions resources/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -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}}",
Expand All @@ -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}}"
}
2 changes: 2 additions & 0 deletions src/thebigcrafter/omp/OhMyPMMP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
45 changes: 27 additions & 18 deletions src/thebigcrafter/omp/commands/subcommands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<string> $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()]));

Check failure on line 59 in src/thebigcrafter/omp/commands/subcommands/ListCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan analysis (ubuntu-latest, 8.1)

Parameter #2 $placeholders of method thebigcrafter\omp\lang\OMPLanguage::translate() expects array<string, string>, array<string, int> given.
$sender->sendMessage("# " . OhMyPMMP::getLanguage()->translate("command.list.plugin.score", ["score" => $plugin->getScore()]));

Check failure on line 60 in src/thebigcrafter/omp/commands/subcommands/ListCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan analysis (ubuntu-latest, 8.1)

Parameter #2 $placeholders of method thebigcrafter\omp\lang\OMPLanguage::translate() expects array<string, string>, array<string, int> given.
$sender->sendMessage("# " . OhMyPMMP::getLanguage()->translate("command.list.plugin.license", ["license" => $plugin->getLicense()]));
$sender->sendMessage("================" . PHP_EOL . PHP_EOL);
}
}

0 comments on commit ed4880f

Please sign in to comment.