Skip to content

Commit 8e57b13

Browse files
committed
fix: fix debug command
1 parent c682c34 commit 8e57b13

File tree

3 files changed

+39
-72
lines changed

3 files changed

+39
-72
lines changed

src/api/EventAPI.cpp

+39-43
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "api/EventAPI.h"
22

3+
#include "../main/BuiltinCommands.h"
4+
#include "CommandCompatibleAPI.h"
35
#include "EntityAPI.h"
46
#include "api/APIHelp.h"
57
#include "api/McAPI.h"
@@ -8,6 +10,7 @@
810
#include "engine/GlobalShareData.h"
911
#include "ll/api/chrono/GameChrono.h"
1012
#include "ll/api/event/EventBus.h"
13+
#include "ll/api/event/command/ExecuteCommandEvent.h"
1114
#include "ll/api/event/player/PlayerChatEvent.h"
1215
#include "ll/api/event/player/PlayerConnectEvent.h"
1316
#include "ll/api/event/player/PlayerDieEvent.h"
@@ -18,13 +21,16 @@
1821
#include "ll/api/schedule/Task.h"
1922
#include "ll/api/service/Bedrock.h"
2023
#include "main/Global.h"
24+
#include "mc/server/commands/CommandOriginType.h"
2125
#include "mc/world/actor/player/Player.h"
2226
#include "mc/world/level/dimension/Dimension.h"
2327

2428
#include <exception>
2529
#include <list>
2630
#include <shared_mutex>
2731

32+
33+
2834
//////////////////// Listeners ////////////////////
2935

3036
enum class EVENT_TYPES : int {
@@ -1319,6 +1325,7 @@ void EnableEventListener(int eventId) {
13191325

13201326
void InitBasicEventListeners() {
13211327
using namespace ll::event;
1328+
EventBus& bus = EventBus::getInstance();
13221329

13231330
// Event::PlayerCmdEvent::subscribe([](const PlayerCmdEvent &ev) {
13241331
// string cmd = ev.mCommand;
@@ -1356,49 +1363,38 @@ void InitBasicEventListeners() {
13561363
// }
13571364
// return true;
13581365
// });
1359-
1360-
// Event::ConsoleCmdEvent::subscribe_ref([](ConsoleCmdEvent &ev) {
1361-
// string cmd = ev.mCommand;
1362-
1363-
// // PreProcess
1364-
// if (!ProcessDebugEngine(cmd))
1365-
// return false;
1366-
// if (!ProcessOldHotManageCommand(ev.mCommand))
1367-
// return false;
1368-
// #ifdef LLSE_BACKEND_NODEJS
1369-
// if (!NodeJsHelper::processConsoleNpmCmd(ev.mCommand))
1370-
// return false;
1371-
// #elif defined(LLSE_BACKEND_PYTHON)
1372-
// if (!PythonHelper::processConsolePipCmd(ev.mCommand))
1373-
// return false;
1374-
// #endif
1375-
// // CallEvents
1376-
// vector<string> paras;
1377-
// bool isFromOtherEngine = false;
1378-
// string prefix = LLSEFindCmdReg(false, cmd, paras, &isFromOtherEngine);
1379-
1380-
// if (!prefix.empty()) {
1381-
// // LLSE Registered Cmd
1382-
1383-
// bool callbackRes = CallServerCmdCallback(prefix, paras);
1384-
// IF_LISTENED(EVENT_TYPES::onConsoleCmd) {
1385-
// CallEvent(EVENT_TYPES::onConsoleCmd, String::newString(cmd));
1386-
// }
1387-
// IF_LISTENED_END(EVENT_TYPES::onConsoleCmd);
1388-
// if (!callbackRes)
1389-
// return false;
1390-
// } else {
1391-
// if (isFromOtherEngine)
1392-
// return false;
1393-
1394-
// // Other Cmd
1395-
// IF_LISTENED(EVENT_TYPES::onConsoleCmd) {
1396-
// CallEvent(EVENT_TYPES::onConsoleCmd, String::newString(cmd));
1397-
// }
1398-
// IF_LISTENED_END(EVENT_TYPES::onConsoleCmd);
1399-
// }
1400-
// return true;
1401-
// });
1366+
bus.emplaceListener<ExecuteCommandEvent>([](ExecuteCommandEvent& ev) {
1367+
if (ev.commandContext().getCommandOrigin().getOriginType() == CommandOriginType::DedicatedServer) {
1368+
string cmd = ev.commandContext().mCommand;
1369+
1370+
if (!ProcessDebugEngine(cmd)) return false;
1371+
#ifdef LLSE_BACKEND_NODEJS
1372+
if (!NodeJsHelper::processConsoleNpmCmd(ev.mCommand)) return false;
1373+
#elif defined(LLSE_BACKEND_PYTHON)
1374+
if (!PythonHelper::processConsolePipCmd(ev.mCommand)) return false;
1375+
#endif
1376+
// CallEvents
1377+
vector<string> paras;
1378+
bool isFromOtherEngine = false;
1379+
string prefix = LLSEFindCmdReg(false, cmd, paras, &isFromOtherEngine);
1380+
1381+
if (!prefix.empty()) {
1382+
// LLSE Registered Cmd
1383+
1384+
bool callbackRes = CallServerCmdCallback(prefix, paras);
1385+
IF_LISTENED(EVENT_TYPES::onConsoleCmd) { CallEvent(EVENT_TYPES::onConsoleCmd, String::newString(cmd)); }
1386+
IF_LISTENED_END(EVENT_TYPES::onConsoleCmd);
1387+
if (!callbackRes) return false;
1388+
} else {
1389+
if (isFromOtherEngine) return false;
1390+
1391+
// Other Cmd
1392+
IF_LISTENED(EVENT_TYPES::onConsoleCmd) { CallEvent(EVENT_TYPES::onConsoleCmd, String::newString(cmd)); }
1393+
IF_LISTENED_END(EVENT_TYPES::onConsoleCmd);
1394+
}
1395+
}
1396+
return true;
1397+
});
14021398

14031399
// // Plugin Hot Management
14041400
// Event::ScriptPluginManagerEvent::subscribe_ref(

src/main/BuiltinCommands.cpp

-28
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,3 @@ bool ProcessDebugEngine(const std::string& cmd) {
5454
}
5555
return true;
5656
}
57-
58-
bool StartsWith(const std::string& str, const std::string& start) {
59-
size_t srcLen = str.size();
60-
size_t startLen = start.size();
61-
if (srcLen >= startLen) {
62-
string temp = str.substr(0, startLen);
63-
if (temp == start) return true;
64-
}
65-
66-
return false;
67-
}
68-
69-
#define FIX_OLD_COMMAND(OLDCMD, NEWCMD) \
70-
if (StartsWith(cmd, OLDCMD)) { \
71-
logger.warn("* Please use command " #NEWCMD " instead."); \
72-
cmd.replace(0, 3, "ll"); \
73-
}
74-
75-
bool ProcessOldHotManageCommand(std::string& cmd) {
76-
FIX_OLD_COMMAND("lxl list", "ll list");
77-
FIX_OLD_COMMAND("lxl load", "ll load");
78-
FIX_OLD_COMMAND("lxl unload", "ll unload");
79-
FIX_OLD_COMMAND("lxl reload", "ll reload");
80-
FIX_OLD_COMMAND("lxl version", "ll version");
81-
FIX_OLD_COMMAND("lxl update", "ll upgrade");
82-
83-
return true;
84-
}

src/main/BuiltinCommands.h

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
#include <string>
33

44
bool ProcessDebugEngine(const std::string& cmd);
5-
bool ProcessOldHotManageCommand(std::string& cmd);

0 commit comments

Comments
 (0)