4545#include < utility>
4646#include < vector>
4747
48+ template <>
49+ bool CommandRegistry::parse<std::pair<
50+ std::string,
51+ int >>(void * p, CommandRegistry::ParseToken const & token, CommandOrigin const &, int , std::string&, std::vector<std::string>&)
52+ const {
53+ *(std::pair<std::string, int >*)p = std::pair<std::string, int >{token.toString (), (int )getEnumData (token)};
54+ return true ;
55+ }
56+
4857#define logger lse::getSelfPluginInstance ().getLogger()
4958
5059#define ForEachParameterType (func ) \
@@ -457,7 +466,15 @@ DynamicCommand::preSetup(CommandRegistry& registry, std::unique_ptr<class Dynami
457466 if (commandInstance->enumRanges .count (param.description ) == 0 ) {
458467 if (!ll::command::CommandRegistrar::getInstance ().hasEnum (param.description ))
459468 throw std::runtime_error (" Enum " + param.description + " not found in command and BDS" );
460- commandInstance->setEnum (param.description , registry.getEnumValues (*iter));
469+ std::vector<std::string> results;
470+ auto & enums = registry.mEnums ;
471+ auto iter = std::find_if (enums.begin (), enums.end (), [&](CommandRegistry::Enum const & r) {
472+ return r.name == name;
473+ });
474+ if (iter != enums.end ())
475+ for (auto & i : iter->values ) results.push_back (registry.mEnumValues .at (i.second ));
476+
477+ commandInstance->setEnum (param.description , results);
461478 }
462479 } else if (param.type == ParameterType::SoftEnum) {
463480 // add empty Soft Enum if not found in command and BDS
@@ -498,12 +515,8 @@ DynamicCommand::preSetup(CommandRegistry& registry, std::unique_ptr<class Dynami
498515 values.emplace_back (*iter, index);
499516 ++index;
500517 }
501- registry._addEnumValuesInternal (
502- fixedView.data (),
503- values,
504- ++Bedrock::typeid_t <CommandRegistry>::_getCounter (),
505- &CommandRegistry::parseEnumStringAndInt
506- );
518+ registry
519+ ._addEnumValuesInternal (fixedView.data (), values, ++Bedrock::typeid_t <CommandRegistry>::_getCounter (), &CommandRegistry::parse<std::pair<std::string, int >>);
507520 }
508521 commandInstance->enumRanges .swap (convertedEnumRanges);
509522
@@ -522,7 +535,9 @@ DynamicCommand::preSetup(CommandRegistry& registry, std::unique_ptr<class Dynami
522535 if (!commandInstance->alias_ .empty ()) registry.registerAlias (commandInstance->name_ , commandInstance->alias_ );
523536 auto builder = commandInstance->builder ->get ();
524537 for (auto & overload : commandInstance->overloads ) {
525- registry.registerOverload (commandInstance->name_ , builder, commandInstance->buildOverload (overload));
538+ auto & si = *registry.findCommand (commandInstance->name_ );
539+ si.overloads .emplace_back (CommandVersion{}, builder).params = commandInstance->buildOverload (overload);
540+ registry.registerOverloadInternal (si, si.overloads .back ());
526541 }
527542 // commandInstance->overloads.clear();
528543 auto res = dynamicCommandInstances.emplace (commandInstance->name_ , std::move (commandInstance));
@@ -626,15 +641,6 @@ std::unique_ptr<class DynamicCommandInstance> DynamicCommand::createCommand(
626641 return std::move (command);
627642}
628643
629- bool DynamicCommand::unregisterCommand (CommandRegistry& registry, std::string const & name) {
630- if (registry.unregisterCommand (name)) {
631- dynamicCommandInstances.erase (name);
632- updateAvailableCommands (registry);
633- return true ;
634- }
635- return false ;
636- }
637-
638644void DynamicCommand::updateAvailableCommands (CommandRegistry& registry) {
639645 registry.serializeAvailableCommands ().sendToClients ();
640646}
0 commit comments