Skip to content

Commit

Permalink
feat: implement CommandRegistry::describe
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Mar 6, 2025
1 parent 0a4d5ad commit f4bf693
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
20 changes: 15 additions & 5 deletions src/bedrock/server/commands/command_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,22 @@ std::string CommandRegistry::describe(const CommandParameterData &param) const
return BEDROCK_CALL(fp, this, param);
}

std::string CommandRegistry::describe(const Signature &signature, const std::string &name, const Overload &overload,
unsigned int a4, unsigned int *a5, unsigned int *a6) const
std::string CommandRegistry::describe(const Signature & /*command*/, const std::string &alias, const Overload &overload,
unsigned int highlight, unsigned int *start, unsigned int *length) const
{
std::string (CommandRegistry::*fp)(const Signature &, const std::string &, const Overload &, unsigned int,
unsigned int *, unsigned int *) const = &CommandRegistry::describe;
return BEDROCK_CALL(fp, this, signature, name, overload, a4, a5, a6);
std::stringstream ss;
ss << "/" << alias;
for (auto i = 0; i < overload.params.size(); i++) {
if (i == highlight && start != nullptr) {
*start = ss.tellp();
}
auto param_syntax = describe(overload.params[i]);
if (i == highlight && length != nullptr) {
*length = param_syntax.size();
}
ss << " " << param_syntax;
}
return ss.str();
}

std::string CommandRegistry::symbolToString(Symbol symbol) const
Expand Down
6 changes: 3 additions & 3 deletions src/bedrock/server/commands/command_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ class CommandRegistry {
int version, std::string &error_message,
std::vector<std::string> &error_params) const;
[[nodiscard]] std::string describe(CommandParameterData const &) const;
[[nodiscard]] std::string describe(const Signature &signature, const std::string &name, const Overload &overload,
unsigned int a4, unsigned int *a5, unsigned int *a6) const;
[[nodiscard]] std::string symbolToString(CommandRegistry::Symbol) const;
[[nodiscard]] std::string describe(const Signature &command, const std::string &alias, const Overload &overload,
unsigned int highlight, unsigned int *start, unsigned int *length) const;
[[nodiscard]] std::string symbolToString(Symbol) const;
void registerOverloadInternal(Signature &signature, Overload &overload);

std::function<void(Packet const &)> network_update_callback_; // +0
Expand Down
2 changes: 0 additions & 2 deletions src/bedrock/symbol_generator/symbols.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ version = "1.21.60"
"?addEnumValues@CommandRegistry@@QEAAHAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@3@@Z" = 24082352
"?createCommand@CommandRegistry@@AEBA?AV?$unique_ptr@VCommand@@U?$default_delete@VCommand@@@std@@@std@@AEBUParseToken@1@AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@3@@Z" = 24001760
"?describe@CommandRegistry@@AEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVCommandParameterData@@@Z" = 24094768
"?describe@CommandRegistry@@AEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBUSignature@1@AEBV23@AEBUOverload@1@IPEAI3@Z" = 24096640
"?findCommand@CommandRegistry@@AEBAPEBUSignature@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z" = 24063232
"?registerAlias@CommandRegistry@@QEAAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z" = 24052080
"?registerCommand@CommandRegistry@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBDW4CommandPermissionLevel@@UCommandFlag@@3@Z" = 24049776
Expand Down Expand Up @@ -109,7 +108,6 @@ version = "1.21.60"
"_ZN15CommandRegistry13addEnumValuesERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERKNS0_6vectorIS6_NS4_IS6_EEEE" = 96782304
"_ZNK15CommandRegistry13createCommandERKNS_10ParseTokenERK13CommandOriginiRNSt3__112basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEERNS6_6vectorISC_NSA_ISC_EEEE" = 96672480
"_ZNK15CommandRegistry8describeERK20CommandParameterData" = 96860960
"_ZNK15CommandRegistry8describeERKNS_9SignatureERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEERKNS_8OverloadEjPjSF_" = 96862752
"_ZNK15CommandRegistry11findCommandERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE" = 96681328
"_ZN15CommandRegistry13registerAliasENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES6_" = 96790752
"_ZN15CommandRegistry15registerCommandERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEPKc22CommandPermissionLevel11CommandFlagSC_" = 96784912
Expand Down

0 comments on commit f4bf693

Please sign in to comment.