55namespace MCSets \command ;
66
77use CortexPE \Commando \BaseCommand ;
8+ use CortexPE \Commando \BaseSubCommand ;
89use MCSets \command \subcommand \APIKeySubCommand ;
910use MCSets \command \subcommand \DebugSubCommand ;
1011use MCSets \command \subcommand \HelpSubCommand ;
1314use MCSets \command \subcommand \ReloadSubCommand ;
1415use MCSets \command \subcommand \StatusSubCommand ;
1516use pocketmine \command \CommandSender ;
17+ use pocketmine \plugin \Plugin ;
18+ use pocketmine \plugin \PluginBase ;
1619use pocketmine \utils \TextFormat ;
1720
1821class 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