@@ -235,17 +235,6 @@ Local<Value> McClass::newCommand(const Arguments& args) {
235235 try {
236236 auto name = args[0 ].asString ().toString ();
237237
238- auto registry = ll::service::getCommandRegistry ();
239- if (registry) {
240- auto instance = registry->findCommand (name);
241- if (instance) {
242- lse::getSelfPluginInstance ().getLogger ().info (
243- " Runtime command {} already exists, changes will not beapplied except for setOverload!" _tr (name)
244- );
245- return CommandClass::newCommand (name);
246- }
247- }
248-
249238 auto desc = args[1 ].asString ().toString ();
250239 CommandPermissionLevel permission = CommandPermissionLevel::Admin;
251240 CommandFlag flag = {(CommandFlagValue)0x80 };
@@ -261,20 +250,33 @@ Local<Value> McClass::newCommand(const Arguments& args) {
261250 }
262251 }
263252 }
264- if (ll::getGamingStatus () == ll::GamingStatus::Starting) {
265- EventBus::getInstance ().emplaceListener <ServerStartedEvent>(
266- [name, desc, permission, flag, alias](ServerStartedEvent&) {
267- auto & command = CommandRegistrar::getInstance ().getOrCreateCommand (name, desc, permission, flag);
268- if (!alias.empty ()) {
269- command.alias (alias);
270- }
253+ auto newCommandFunc = [](std::string const & name,
254+ std::string const & desc,
255+ CommandPermissionLevel const & permission,
256+ CommandFlag const & flag,
257+ std::string const & alias) {
258+ auto registry = ll::service::getCommandRegistry ();
259+ if (registry) {
260+ auto instance = registry->findCommand (name);
261+ if (instance) {
262+ lse::getSelfPluginInstance ().getLogger ().info (
263+ " Runtime command {} already exists, changes will not beapplied except for setOverload!" _tr (name)
264+ );
271265 }
272- );
273- } else {
266+ }
274267 auto & command = CommandRegistrar::getInstance ().getOrCreateCommand (name, desc, permission, flag);
275268 if (!alias.empty ()) {
276269 command.alias (alias);
277270 }
271+ };
272+ if (ll::getGamingStatus () == ll::GamingStatus::Starting) {
273+ EventBus::getInstance ().emplaceListener <ServerStartedEvent>(
274+ [name, desc, permission, flag, alias, newCommandFunc](ServerStartedEvent&) {
275+ newCommandFunc (name, desc, permission, flag, alias);
276+ }
277+ );
278+ } else {
279+ newCommandFunc (name, desc, permission, flag, alias);
278280 }
279281 return CommandClass::newCommand (name);
280282 }
@@ -471,8 +473,9 @@ Local<Value> CommandClass::optional(const Arguments& args) {
471473Local<Value> CommandClass::addOverload (const Arguments& args) {
472474 try {
473475 if (args.size () == 0 ) return Boolean::newBoolean (true );
474- auto overloadFunc = [](RuntimeOverload& cmd, std::string const & commandName, std::string const & paramName) {
475- auto & paramList = getEngineOwnData ()->plugin ->registeredCommands [commandName];
476+ auto overloadFunc = [e (EngineScope::currentEngine ()
477+ )](RuntimeOverload& cmd, std::string const & commandName, std::string const & paramName) {
478+ auto & paramList = getEngineData (e)->plugin ->registeredCommands [commandName];
476479 for (auto & info : paramList) {
477480 if (info.name == paramName || info.enumName == paramName) {
478481 if (info.optional ) {
@@ -501,24 +504,7 @@ Local<Value> CommandClass::addOverload(const Arguments& args) {
501504 .getOrCreateCommand (commandName)
502505 .runtimeOverload (getEngineData (e)->plugin );
503506 for (auto & paramName : enumValues) {
504- auto & paramList = getEngineData (e)->plugin ->registeredCommands [commandName];
505- for (auto & info : paramList) {
506- if (info.name == paramName || info.enumName == paramName) {
507- if (info.optional ) {
508- if (info.type == ParamKind::Kind::Enum || info.type == ParamKind::Kind::SoftEnum) {
509- cmd.optional (info.enumName , info.type , info.enumName ).option (info.option );
510- } else {
511- cmd.optional (info.name , info.type ).option (info.option );
512- }
513- } else {
514- if (info.type == ParamKind::Kind::Enum || info.type == ParamKind::Kind::SoftEnum) {
515- cmd.required (info.enumName , info.type , info.enumName ).option (info.option );
516- } else {
517- cmd.required (info.name , info.type ).option (info.option );
518- }
519- }
520- }
521- }
507+ overloadFunc (cmd, commandName, paramName);
522508 }
523509 cmd.execute (onExecute);
524510 });
0 commit comments