Skip to content

Commit d46ced0

Browse files
committed
Fix Commando subcommand init and bump version
1 parent 26e3274 commit d46ced0

2 files changed

Lines changed: 38 additions & 9 deletions

File tree

plugin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: MCSets-PMMP
22
main: MCSets\Loader
33
api: 5.0.0
4-
version: 1.0.4
4+
version: 1.0.5
55

66
website: https://mcsets.com
77
author: MCSets - Remminiscent
@@ -11,4 +11,4 @@ permissions:
1111
mcsets.admin:
1212
default: op
1313
mcsets.verify:
14-
default: true
14+
default: true

src/MCSets/command/SetStoreCommand.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace MCSets\command;
66

77
use CortexPE\Commando\BaseCommand;
8+
use CortexPE\Commando\BaseSubCommand;
89
use MCSets\command\subcommand\APIKeySubCommand;
910
use MCSets\command\subcommand\DebugSubCommand;
1011
use MCSets\command\subcommand\HelpSubCommand;
@@ -13,6 +14,8 @@
1314
use MCSets\command\subcommand\ReloadSubCommand;
1415
use MCSets\command\subcommand\StatusSubCommand;
1516
use pocketmine\command\CommandSender;
17+
use pocketmine\plugin\Plugin;
18+
use pocketmine\plugin\PluginBase;
1619
use pocketmine\utils\TextFormat;
1720

1821
class SetStoreCommand extends BaseCommand
@@ -21,15 +24,41 @@ public function getPermission(): string
2124
{
2225
return "mcsets.admin";
2326
}
27+
28+
private function createSubCommand(string $class, string $name, string $description = "", array $aliases = []): BaseSubCommand
29+
{
30+
$plugin = $this->getOwningPlugin();
31+
$ctor = (new \ReflectionClass($class))->getConstructor();
32+
33+
if ($ctor !== null) {
34+
$params = $ctor->getParameters();
35+
if (isset($params[0]) && $params[0]->hasType()) {
36+
$type = $params[0]->getType();
37+
if ($type instanceof \ReflectionNamedType) {
38+
$typeName = $type->getName();
39+
if (
40+
$typeName === Plugin::class ||
41+
$typeName === PluginBase::class ||
42+
is_subclass_of($typeName, Plugin::class)
43+
) {
44+
return new $class($plugin, $name, $description, $aliases);
45+
}
46+
}
47+
}
48+
}
49+
50+
return new $class($name, $description, $aliases);
51+
}
52+
2453
protected function prepare(): void
2554
{
26-
$this->registerSubCommand(new APIKeySubCommand("apikey", "Set your API key", ["key", "token", "secret"]));
27-
$this->registerSubCommand(new DebugSubCommand("debug", "Toggle debug logging"));
28-
$this->registerSubCommand(new HelpSubCommand("help", "Show available commands"));
29-
$this->registerSubCommand(new QueueSubCommand("queue", "Process pending deliveries"));
30-
$this->registerSubCommand(new ReconnectSubCommand("reconnect", "Reconnect to MCSets"));
31-
$this->registerSubCommand(new ReloadSubCommand("reload", "Reload configuration"));
32-
$this->registerSubCommand(new StatusSubCommand("status", "View connection status"));
55+
$this->registerSubCommand($this->createSubCommand(APIKeySubCommand::class, "apikey", "Set your API key", ["key", "token", "secret"]));
56+
$this->registerSubCommand($this->createSubCommand(DebugSubCommand::class, "debug", "Toggle debug logging"));
57+
$this->registerSubCommand($this->createSubCommand(HelpSubCommand::class, "help", "Show available commands"));
58+
$this->registerSubCommand($this->createSubCommand(QueueSubCommand::class, "queue", "Process pending deliveries"));
59+
$this->registerSubCommand($this->createSubCommand(ReconnectSubCommand::class, "reconnect", "Reconnect to MCSets"));
60+
$this->registerSubCommand($this->createSubCommand(ReloadSubCommand::class, "reload", "Reload configuration"));
61+
$this->registerSubCommand($this->createSubCommand(StatusSubCommand::class, "status", "View connection status"));
3362
}
3463
public function onRun(CommandSender $sender, string $aliasUsed, array $args): void
3564
{

0 commit comments

Comments
 (0)