Skip to content

Commit

Permalink
Add list command
Browse files Browse the repository at this point in the history
  • Loading branch information
toby7002 committed Oct 4, 2023
1 parent 1cb273d commit 21cdf57
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
7 changes: 6 additions & 1 deletion resources/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"text.cache.failed": "§cCould not get Poggit plugins list from Poggit: {%reason}",
"text.cache.successfully": "§a{{count}} Poggit plugins has been cached successfully",

"command.version.description": "Get plugin version",
"command.version.api_version": "§aPocketMine-MP API v{{version}}",
"command.version.php_version": "§aPHP v{{version}}",
"command.version.plugin_version": "§aoh-my-pmmp v{{version}}"
"command.version.plugin_version": "§aoh-my-pmmp v{{version}}",

"command.help.description": "Print oh-my-pmmp command line options",

"command.list.description": "List the available, installed and, upgradeable plugins"
}
4 changes: 4 additions & 0 deletions src/thebigcrafter/omp/cache/PluginCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public function getHomepageByVersion(string $version) : string {
return "https://poggit.pmmp.io/p/" . $this->getName() . "/" . $version;
}

public function getHomepage() : string {
return "https://poggit.pmmp.io/p/" . $this->getName();
}

public function pushVersion(PluginVersion $version) : void {
$this->versions[$version->getVersion()] = $version;
}
Expand Down
6 changes: 4 additions & 2 deletions src/thebigcrafter/omp/commands/OMPCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use CortexPE\Commando\BaseCommand;
use pocketmine\command\CommandSender;
use thebigcrafter\omp\commands\subcommands\HelpCommand;
use thebigcrafter\omp\commands\subcommands\ListCommand;
use thebigcrafter\omp\commands\subcommands\VersionCommand;
use thebigcrafter\omp\OhMyPMMP;

Expand All @@ -24,8 +25,9 @@ protected function prepare() : void {
$this->setPermission($this->permission);

$subcommands = [
new VersionCommand(OhMyPMMP::getInstance(),"version", "Get plugin version", ["v", "-v", "--version"]),
new HelpCommand(OhMyPMMP::getInstance(), "help", "Print oh-my-pmmp command line options", ["h", "-h", "--help"])
new VersionCommand(OhMyPMMP::getInstance(),"version", OhMyPMMP::getLanguage()->translate("command.version.description"), ["v", "-v", "--version"]),
new HelpCommand(OhMyPMMP::getInstance(),"help", OhMyPMMP::getLanguage()->translate("command.help.description"), ["h", "-h", "--help"]),
new ListCommand(OhMyPMMP::getInstance(), "list", OhMyPMMP::getLanguage()->translate("command.list.description"), ["l", "-l", "--list"])
];

foreach ($subcommands as $subcommand) {
Expand Down
55 changes: 55 additions & 0 deletions src/thebigcrafter/omp/commands/subcommands/ListCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* This file is part of oh-my-pmmp.
* (c) thebigcrafter <[email protected]>
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/

declare(strict_types=1);

namespace thebigcrafter\omp\commands\subcommands;

use CortexPE\Commando\BaseSubCommand;
use pocketmine\command\CommandSender;
use pocketmine\Server;
use thebigcrafter\omp\cache\PluginCache;
use thebigcrafter\omp\cache\PluginsPool;
use thebigcrafter\omp\OhMyPMMP;
use function phpversion;

class ListCommand extends BaseSubCommand {
protected function prepare() : void {
$this->setPermission("oh-my-pmmp.list");
}

/**
* @param array<string> $args
*/
public function onRun(CommandSender $sender,string $aliasUsed,array $args) : void {
foreach (PluginsPool::getStorage() as $plugin) {
$this->renderBlock($sender, $plugin);
}
}

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();

$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("================" . PHP_EOL . PHP_EOL);
}
}

0 comments on commit 21cdf57

Please sign in to comment.