|
1 | 1 | #include "api/EventAPI.h"
|
2 | 2 |
|
| 3 | +#include "../main/BuiltinCommands.h" |
| 4 | +#include "CommandCompatibleAPI.h" |
3 | 5 | #include "EntityAPI.h"
|
4 | 6 | #include "api/APIHelp.h"
|
5 | 7 | #include "api/McAPI.h"
|
|
8 | 10 | #include "engine/GlobalShareData.h"
|
9 | 11 | #include "ll/api/chrono/GameChrono.h"
|
10 | 12 | #include "ll/api/event/EventBus.h"
|
| 13 | +#include "ll/api/event/command/ExecuteCommandEvent.h" |
11 | 14 | #include "ll/api/event/player/PlayerChatEvent.h"
|
12 | 15 | #include "ll/api/event/player/PlayerConnectEvent.h"
|
13 | 16 | #include "ll/api/event/player/PlayerDieEvent.h"
|
|
18 | 21 | #include "ll/api/schedule/Task.h"
|
19 | 22 | #include "ll/api/service/Bedrock.h"
|
20 | 23 | #include "main/Global.h"
|
| 24 | +#include "mc/server/commands/CommandOriginType.h" |
21 | 25 | #include "mc/world/actor/player/Player.h"
|
22 | 26 | #include "mc/world/level/dimension/Dimension.h"
|
23 | 27 |
|
24 | 28 | #include <exception>
|
25 | 29 | #include <list>
|
26 | 30 | #include <shared_mutex>
|
27 | 31 |
|
| 32 | + |
| 33 | + |
28 | 34 | //////////////////// Listeners ////////////////////
|
29 | 35 |
|
30 | 36 | enum class EVENT_TYPES : int {
|
@@ -1319,6 +1325,7 @@ void EnableEventListener(int eventId) {
|
1319 | 1325 |
|
1320 | 1326 | void InitBasicEventListeners() {
|
1321 | 1327 | using namespace ll::event;
|
| 1328 | + EventBus& bus = EventBus::getInstance(); |
1322 | 1329 |
|
1323 | 1330 | // Event::PlayerCmdEvent::subscribe([](const PlayerCmdEvent &ev) {
|
1324 | 1331 | // string cmd = ev.mCommand;
|
@@ -1356,49 +1363,38 @@ void InitBasicEventListeners() {
|
1356 | 1363 | // }
|
1357 | 1364 | // return true;
|
1358 | 1365 | // });
|
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 | + }); |
1402 | 1398 |
|
1403 | 1399 | // // Plugin Hot Management
|
1404 | 1400 | // Event::ScriptPluginManagerEvent::subscribe_ref(
|
|
0 commit comments