-
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 21, 2023
1 parent
f550898
commit 95f2405
Showing
6 changed files
with
134 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
{ | ||
"messages.pool.fetching": "Fetching data from Poggit...", | ||
"messages.pool.fetched": "Fetched {{amount}} plugins from Poggit successfully", | ||
|
||
"commands.version.message_1": "OMP v{{version}}", | ||
"commands.version.message_2": "PHP v{{phpVersion}} {{arch}}", | ||
|
||
"commands.remove.successfully": "{{name}} was removed successfully, please restart the server to apply changes", | ||
"commands.remove.failed": "{{name}} not found" | ||
"commands.remove.failed": "{{name}} not found", | ||
|
||
"commands.list.form.name": "Name: {{name}}", | ||
"commands.list.form.license": "License: {{license}}", | ||
"commands.list.form.versions": "Versions: {{versions}}" | ||
} |
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 |
---|---|---|
@@ -1,36 +1,58 @@ | ||
<?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\IntegerArgument; | ||
use CortexPE\Commando\BaseSubCommand; | ||
use pocketmine\command\CommandSender; | ||
use thebigcrafter\omp\Language; | ||
use thebigcrafter\omp\OhMyPMMP; | ||
use thebigcrafter\omp\pool\PoggitPluginsPool; | ||
use function array_slice; | ||
use function ceil; | ||
use function count; | ||
use function implode; | ||
use function max; | ||
use function min; | ||
|
||
class ListCommand extends BaseSubCommand { | ||
protected function prepare() : void | ||
class ListCommand extends BaseSubCommand | ||
{ | ||
protected function prepare() : void | ||
{ | ||
$this->setPermission("oh-my-pmmp.list"); | ||
|
||
$this->registerArgument(0, new IntegerArgument("page", true)); | ||
$this->registerArgument(0, new IntegerArgument("page", true)); | ||
} | ||
|
||
/** | ||
* @param array<string> $args | ||
*/ | ||
public function onRun(CommandSender $sender, string $aliasUsed, array $args) : void | ||
{ | ||
$page = isset($args["page"]) ? $args["page"] : 0; | ||
$pluginsPerPage = OhMyPMMP::getInstance()->getConfig()->get("pluginsPerPage"); | ||
$totalPages = ceil(count(PoggitPluginsPool::getPool()) / $pluginsPerPage); | ||
$page = max(0, min($page, $totalPages - 1)); | ||
$offset = $page * $pluginsPerPage; | ||
/** @var array{name: string, plugin: Plugin} $pluginsOnPage */ | ||
$pluginsOnPage = array_slice(PoggitPluginsPool::getPool(), $offset, $pluginsPerPage); | ||
|
||
foreach ($pluginsOnPage as $name => $info) { | ||
// TODO: make a beautiful table :D | ||
} | ||
$page = isset($args["page"]) ? $args["page"] : 0; | ||
$pluginsPerPage = OhMyPMMP::getInstance()->getConfig()->get("pluginsPerPage"); | ||
$totalPages = ceil(count(PoggitPluginsPool::getPool()) / $pluginsPerPage); | ||
$page = max(0, min($page, $totalPages - 1)); | ||
$offset = $page * $pluginsPerPage; | ||
/** @var array{name: string, plugin: Plugin} $pluginsOnPage */ | ||
$pluginsOnPage = array_slice(PoggitPluginsPool::getPool(), $offset, $pluginsPerPage); | ||
|
||
foreach ($pluginsOnPage as $name => $plugin) { | ||
$sender->sendMessage(Language::translate("commands.list.form.name", ["name" => $name])); | ||
$sender->sendMessage(Language::translate("commands.list.form.license", ["license" => $plugin->getLicense()])); | ||
$sender->sendMessage(Language::translate("commands.list.form.versions", ["versions" => implode(", ", $plugin->getVersionsOnly())])); | ||
$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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
<?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\BooleanArgument; | ||
|
@@ -10,61 +21,61 @@ | |
use thebigcrafter\omp\Language; | ||
use thebigcrafter\omp\OhMyPMMP; | ||
use function Amp\File\deleteDirectory; | ||
use function Amp\File\exists; | ||
use function Amp\File\deleteFile; | ||
use function Amp\File\exists; | ||
|
||
class RemoveCommand extends BaseSubCommand | ||
{ | ||
protected function prepare(): void | ||
{ | ||
$this->setPermission("oh-my-pmmp.remove"); | ||
protected function prepare() : void | ||
{ | ||
$this->setPermission("oh-my-pmmp.remove"); | ||
|
||
$this->registerArgument(0, new RawStringArgument("name", false)); | ||
$this->registerArgument(1, new BooleanArgument("wipeData", true)); | ||
} | ||
$this->registerArgument(0, new RawStringArgument("name", false)); | ||
$this->registerArgument(1, new BooleanArgument("wipeData", true)); | ||
} | ||
|
||
/** | ||
* @param array<string> $args | ||
*/ | ||
public function onRun(CommandSender $sender, string $aliasUsed, array $args): void | ||
{ | ||
$name = $args["name"]; | ||
$wipeData = isset($args["wipeData"]) ? $args["wipeData"] : false; | ||
/** | ||
* @param array<string> $args | ||
*/ | ||
public function onRun(CommandSender $sender, string $aliasUsed, array $args) : void | ||
{ | ||
$name = $args["name"]; | ||
$wipeData = isset($args["wipeData"]) ? $args["wipeData"] : false; | ||
|
||
$exec = $this->removePlugin($name, $wipeData); | ||
$exec = $this->removePlugin($name, $wipeData); | ||
|
||
if (!$exec) { | ||
$sender->sendMessage(Language::translate("commands.remove.failed", ["name" => $name])); | ||
return; | ||
} | ||
$sender->sendMessage(Language::translate("commands.remove.successfully", ["name" => $name])); | ||
return; | ||
} | ||
if (!$exec) { | ||
$sender->sendMessage(Language::translate("commands.remove.failed", ["name" => $name])); | ||
return; | ||
} | ||
$sender->sendMessage(Language::translate("commands.remove.successfully", ["name" => $name])); | ||
return; | ||
} | ||
|
||
/** | ||
* Return false if plugin not found | ||
*/ | ||
private function removePlugin(string $name, bool $wipeData): bool | ||
{ | ||
$pluginFilePath = Path::join(OhMyPMMP::getInstance()->getServer()->getDataPath(), "plugins", "$name.phar"); | ||
$pluginFolderPath = Path::join(OhMyPMMP::getInstance()->getServer()->getDataPath(), "plugins", $name); | ||
/** | ||
* Return false if plugin not found | ||
*/ | ||
private function removePlugin(string $name, bool $wipeData) : bool | ||
{ | ||
$pluginFilePath = Path::join(OhMyPMMP::getInstance()->getServer()->getDataPath(), "plugins", "$name.phar"); | ||
$pluginFolderPath = Path::join(OhMyPMMP::getInstance()->getServer()->getDataPath(), "plugins", $name); | ||
|
||
if (exists($pluginFilePath)) { | ||
deleteFile($pluginFilePath); | ||
} elseif (exists($pluginFolderPath)) { | ||
deleteDirectory($pluginFolderPath); | ||
} else { | ||
return false; | ||
} | ||
if ($wipeData) { | ||
$this->wipeData($name); | ||
} | ||
return true; | ||
} | ||
if (exists($pluginFilePath)) { | ||
deleteFile($pluginFilePath); | ||
} elseif (exists($pluginFolderPath)) { | ||
deleteDirectory($pluginFolderPath); | ||
} else { | ||
return false; | ||
} | ||
if ($wipeData) { | ||
$this->wipeData($name); | ||
} | ||
return true; | ||
} | ||
|
||
private function wipeData(string $name): void | ||
{ | ||
$pluginDataFolder = Path::join(OhMyPMMP::getInstance()->getDataFolder(), "..", $name); | ||
deleteDirectory($pluginDataFolder); | ||
} | ||
private function wipeData(string $name) : void | ||
{ | ||
$pluginDataFolder = Path::join(OhMyPMMP::getInstance()->getDataFolder(), "..", $name); | ||
deleteDirectory($pluginDataFolder); | ||
} | ||
} |
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