-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nmtho
committed
Nov 24, 2023
1 parent
95f2405
commit e8b6222
Showing
4 changed files
with
125 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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\args\RawStringArgument; | ||
use CortexPE\Commando\BaseSubCommand; | ||
use pocketmine\command\CommandSender; | ||
use thebigcrafter\omp\Language; | ||
use thebigcrafter\omp\pool\PoggitPluginsPool; | ||
use function is_null; | ||
|
||
class ShowCommand extends BaseSubCommand | ||
{ | ||
protected function prepare() : void | ||
{ | ||
$this->setPermission("oh-my-pmmp.show"); | ||
|
||
$this->registerArgument(0, new RawStringArgument("name", false)); | ||
$this->registerArgument(1, new RawStringArgument("version", true)); | ||
} | ||
|
||
/** | ||
* @param array<string> $args | ||
*/ | ||
public function onRun(CommandSender $sender, string $aliasUsed, array $args) : void | ||
{ | ||
$name = $args["name"]; | ||
$version = isset($args["version"]) ? $args["version"] : null; | ||
|
||
$plugin = PoggitPluginsPool::getItem($name); | ||
|
||
if (!isset($plugin)) { | ||
$sender->sendMessage(Language::translate("commands.show.failed_1", ["name" => $name])); | ||
return; | ||
} | ||
|
||
$pluginVersion = $plugin->getVersion($version); | ||
|
||
if (is_null($pluginVersion["plugin"])) { | ||
$sender->sendMessage(Language::translate("commands.show.failed_2", ["version" => $version])); | ||
return; | ||
} | ||
|
||
$info = $pluginVersion["plugin"]; | ||
|
||
// aka $version if user provides a specified version | ||
$latestVersion = $pluginVersion["version"]; | ||
|
||
$sender->sendMessage(Language::translate("commands.show.form.name", ["name" => $name])); | ||
$sender->sendMessage(Language::translate("commands.show.form.version", ["version" => $latestVersion])); | ||
$sender->sendMessage(Language::translate("commands.show.form.homepage", ["homepage" => $info->getHtmlUrl()])); | ||
$sender->sendMessage(Language::translate("commands.show.form.license", ["license" => $plugin->getLicense()])); | ||
$sender->sendMessage(Language::translate("commands.show.form.download_url", ["download_url" => $info->getArtifactUrl()])); | ||
$sender->sendMessage(Language::translate("commands.show.form.downloads", ["downloads" => $info->getDownloads()])); | ||
$sender->sendMessage(Language::translate("commands.show.form.score", ["score" => $info->getScore()])); | ||
$sender->sendMessage(Language::translate("commands.show.form.description_url", ["description_url" => $info->getDescriptionUrl()])); | ||
$sender->sendMessage(Language::translate("commands.show.form.changelog_url", ["changelog_url" => $info->getChangelogUrl()])); | ||
$sender->sendMessage(Language::translate("commands.show.form.api", ["name" => $name])); | ||
$sender->sendMessage(Language::translate("commands.show.form.deps", ["name" => $name])); | ||
$sender->sendMessage("===================="); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters