From 9d802cda14676841edfd57635f3608370ba01eb3 Mon Sep 17 00:00:00 2001 From: ShrBox Date: Tue, 23 Jan 2024 19:05:39 +0800 Subject: [PATCH] fix: fix mc.runcmd & mc.runcmdEx --- src/api/CommandAPI.cpp | 18 ++++++++---------- src/api/EventAPI.cpp | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/api/CommandAPI.cpp b/src/api/CommandAPI.cpp index 6b11ee3..99340d3 100644 --- a/src/api/CommandAPI.cpp +++ b/src/api/CommandAPI.cpp @@ -164,7 +164,7 @@ Local McClass::runcmd(const Arguments& args) { ) ); try { - return Boolean::newBoolean(ll::service::getMinecraft()->getCommands().executeCommand(context, true)); + return Boolean::newBoolean(ll::service::getMinecraft()->getCommands().executeCommand(context, false)); } CATCH("Fail in RunCmd!") } @@ -179,10 +179,10 @@ Local McClass::runcmdEx(const Arguments& args) { ) ); try { - MCRESULT result = ll::service::getMinecraft()->getCommands().executeCommand(context, false); + MCRESULT result = ll::service::getMinecraft()->getCommands().executeCommand(context, true); Local resObj = Object::newObject(); resObj.set("success", result.isSuccess()); - resObj.set("output", {}); + resObj.set("output", result.getFullCode()); return resObj; } CATCH("Fail in RunCmdEx!") @@ -474,13 +474,11 @@ Local CommandClass::setCallback(const Arguments& args) { CHECK_ARGS_COUNT(args, 1); CHECK_ARG_TYPE(args[0], ValueKind::kFunction); try { - auto func = args[0].asFunction(); - DynamicCommandInstance* command = get(); - auto& commandName = command->getCommandName(); - localShareData->commandCallbacks[commandName] = { - EngineScope::currentEngine(), - 0, - script::Global(func)}; + auto func = args[0].asFunction(); + DynamicCommandInstance* command = get(); + auto& commandName = command->getCommandName(); + localShareData + ->commandCallbacks[commandName] = {EngineScope::currentEngine(), 0, script::Global(func)}; if (registered) return Boolean::newBoolean(true); get()->setCallback(onExecute); return Boolean::newBoolean(true); diff --git a/src/api/EventAPI.cpp b/src/api/EventAPI.cpp index 5cf8e87..df9ea40 100644 --- a/src/api/EventAPI.cpp +++ b/src/api/EventAPI.cpp @@ -1364,7 +1364,8 @@ void InitBasicEventListeners() { // }); bus.emplaceListener([](ExecutingCommandEvent& ev) { if (ev.commandContext().getCommandOrigin().getOriginType() == CommandOriginType::DedicatedServer) { - std::string cmd = ev.commandContext().mCommand.erase(0, 1); + std::string cmd = ev.commandContext().mCommand; + cmd.erase(0, 1); if (!ProcessDebugEngine(cmd)) { ev.cancel();