1111#include " ll/api/command/runtime/RuntimeOverload.h"
1212
1313#include < mc/server/commands/CommandOutput.h>
14+ #include < ranges>
1415#include < string>
1516#include < vector>
1617
@@ -32,37 +33,45 @@ void registerLegacyCommand(
3233 auto & command =
3334 CommandRegistrar::getInstance (false )
3435 .getOrCreateCommand (std::string (cmdParas[0 ]), description, level, CommandFlagValue::NotCheat, plugin);
35- auto overload = command.runtimeOverload (plugin);
36+ auto overload = command.runtimeOverload (plugin);
37+ bool hasSubCommand = false ;
3638 if (cmdParas.size () > 1 ) {
3739 for (size_t i = 1 ; i < cmdParas.size (); ++i) {
3840 overload.text (cmdParas[i]);
3941 }
4042 }
41- overload.optional (" args" , ParamKind::RawText)
42- .execute ([playerFunc,
43- consoleFunc,
44- engine](CommandOrigin const & origin, CommandOutput& output, RuntimeCommand const & command) {
45- if (!engine) return ;
46- EngineScope enterInner (engine.get ());
47- if (!playerFunc && !consoleFunc) return ;
48- Local<Array> params = Array::newArray ();
49- if (command[" args" ].hold (ParamKind::RawText)) {
50- for (auto & para :
51- ll::string_utils::splitByPattern (std::get<CommandRawText>(command[" args" ].value ()).mText , " " )) {
52- params.add (String::newString (para));
53- }
54- }
55- if (origin.getOriginType () == CommandOriginType::Player && playerFunc) {
56- if (origin.getPermissionsLevel () < command.mPermissionLevel ) {
57- output.error (" You don't have permission to use this command." _tr ());
58- return ;
59- }
60- playerFunc->get ().call ({}, PlayerClass::newPlayer (static_cast <Player*>(origin.getEntity ())), params);
43+ // To ensure compatibility for https://github.com/bricktea/iLand-Core
44+ hasSubCommand = std::ranges::any_of (localShareData->fakeCommandsMap | std::views::keys, [&](auto const & cmd) {
45+ return cmd.starts_with (name + " " );
46+ });
47+ if (!hasSubCommand) {
48+ overload.optional (" args" , ParamKind::RawText);
49+ }
50+ overload.execute ([playerFunc, consoleFunc, engine, hasSubCommand](
51+ CommandOrigin const & origin,
52+ CommandOutput& output,
53+ RuntimeCommand const & command
54+ ) {
55+ if (!engine || (!playerFunc && !consoleFunc)) return ;
56+ EngineScope enterInner (engine.get ());
57+ Local<Array> params = Array::newArray ();
58+ if (!hasSubCommand && command[" args" ].hold (ParamKind::RawText)) {
59+ for (auto & para :
60+ ll::string_utils::splitByPattern (std::get<CommandRawText>(command[" args" ].value ()).mText , " " )) {
61+ params.add (String::newString (para));
6162 }
62- if (origin.getOriginType () == CommandOriginType::DedicatedServer && consoleFunc) {
63- consoleFunc->get ().call ({}, params);
63+ }
64+ if (origin.getOriginType () == CommandOriginType::Player && playerFunc) {
65+ if (origin.getPermissionsLevel () < command.mPermissionLevel ) {
66+ output.error (" You don't have permission to use this command." _tr ());
67+ return ;
6468 }
65- });
69+ playerFunc->get ().call ({}, PlayerClass::newPlayer (static_cast <Player*>(origin.getEntity ())), params);
70+ }
71+ if (origin.getOriginType () == CommandOriginType::DedicatedServer && consoleFunc) {
72+ consoleFunc->get ().call ({}, params);
73+ }
74+ });
6675}
6776
6877void newLegacyCommand (
0 commit comments