Skip to content

Commit 3ed50cc

Browse files
committed
feat: add workaround to add description for sub commands in LegacyCommand
fix: fix LegacyCommand's registration order
1 parent ebdb4f5 commit 3ed50cc

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/legacy/api/LegacyCommandAPI.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include "ll/api/command/CommandHandle.h"
1010
#include "ll/api/command/runtime/RuntimeCommand.h"
1111
#include "ll/api/command/runtime/RuntimeOverload.h"
12+
#include "mc/server/commands/CommandOutput.h"
1213

13-
#include <mc/server/commands/CommandOutput.h>
1414
#include <ranges>
1515
#include <string>
1616
#include <vector>
@@ -29,13 +29,14 @@ void registerLegacyCommand(
2929
EngineScope enter(engine.get());
3030
auto& plugin = getEngineData(engine)->plugin;
3131

32-
auto cmdParas = ll::string_utils::splitByPattern(name, " ");
32+
auto cmdParas = ll::string_utils::splitByPattern(name, " ");
33+
bool singleParam = cmdParas.size() == 1;
3334
auto& command =
3435
CommandRegistrar::getInstance(false)
3536
.getOrCreateCommand(std::string(cmdParas[0]), description, level, CommandFlagValue::NotCheat, plugin);
3637
auto overload = command.runtimeOverload(plugin);
3738
bool hasSubCommand = false;
38-
if (cmdParas.size() > 1) {
39+
if (!singleParam) {
3940
for (size_t i = 1; i < cmdParas.size(); ++i) {
4041
overload.text(cmdParas[i]);
4142
}
@@ -47,6 +48,10 @@ void registerLegacyCommand(
4748
if (!hasSubCommand) {
4849
overload.optional("args", ParamKind::RawText);
4950
}
51+
// Workaround to add description for sub commands
52+
if (!singleParam) {
53+
overload.optional("§e" + description + "§r", ParamKind::Bool);
54+
}
5055
overload.execute([playerFunc, consoleFunc, engine, hasSubCommand](
5156
CommandOrigin const& origin,
5257
CommandOutput& output,

src/legacy/engine/LocalShareData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct LocalDataType {
4242
std::map<std::string, CommandCallbackData, CommmandCallbackMapCmp> commandCallbacks;
4343

4444
// 命令延迟注册队列
45-
std::unordered_map<std::string, FakeCommandRegistrationData> fakeCommandsMap;
45+
std::map<std::string, FakeCommandRegistrationData> fakeCommandsMap;
4646
};
4747

4848
//////////////////// Externs ////////////////////

0 commit comments

Comments
 (0)