|
6 | 6 | #include "ll/api/service/Bedrock.h" |
7 | 7 | #include "lse/Entry.h" |
8 | 8 | #include "mc/server/commands/CommandPermissionLevel.h" |
| 9 | +#include "ll/api/command/Command.h" |
| 10 | +#include "ll/api/command/CommandHandle.h" |
| 11 | +#include "ll/api/command/CommandRegistrar.h" |
9 | 12 |
|
10 | 13 | #include <string> |
11 | 14 |
|
@@ -42,37 +45,71 @@ bool ProcessDebugEngine(const std::string& cmd) { |
42 | 45 | return true; |
43 | 46 | } |
44 | 47 |
|
| 48 | +struct EngineDebugCommand { |
| 49 | + std::string eval; |
| 50 | +}; |
| 51 | + |
45 | 52 | void RegisterDebugCommand() { |
46 | | - auto command = |
47 | | - DynamicCommand::createCommand(LLSE_DEBUG_CMD, "Debug LegacyScriptEngine", CommandPermissionLevel::Owner); |
48 | | - command->optional("eval", DynamicCommand::ParameterType::RawText); |
49 | | - command->addOverload("eval"); |
50 | | - command->setCallback([](DynamicCommand const&, |
51 | | - CommandOrigin const&, |
52 | | - CommandOutput&, |
53 | | - std::unordered_map<std::string, DynamicCommand::Result>& results) { |
54 | | - if (results["eval"].isSet) { |
55 | | - EngineScope enter(debugEngine); |
56 | | - try { |
57 | | - auto result = debugEngine->eval(results["eval"].getRaw<std::string>()); |
58 | | - std::ostringstream sout; |
59 | | - PrintValue(sout, result); |
60 | | - lse::getSelfPluginInstance().getLogger().info(sout.str()); |
61 | | - } catch (Exception& e) { |
62 | | - PrintException(e); |
63 | | - } |
64 | | - } else { |
65 | | - if (isInConsoleDebugMode) { |
66 | | - // EndDebug |
67 | | - lse::getSelfPluginInstance().getLogger().info("Debug mode ended"); |
68 | | - isInConsoleDebugMode = false; |
| 53 | + // Old dynamic command, just for testing |
| 54 | + |
| 55 | + // auto command = |
| 56 | + // DynamicCommand::createCommand(LLSE_DEBUG_CMD, "Debug LegacyScriptEngine", CommandPermissionLevel::Owner); |
| 57 | + // command->optional("eval", DynamicCommand::ParameterType::RawText); |
| 58 | + // command->addOverload("eval"); |
| 59 | + // command->setCallback([](DynamicCommand const&, |
| 60 | + // CommandOrigin const&, |
| 61 | + // CommandOutput& output, |
| 62 | + // std::unordered_map<std::string, DynamicCommand::Result>& results) { |
| 63 | + // if (results["eval"].isSet) { |
| 64 | + // EngineScope enter(debugEngine); |
| 65 | + // try { |
| 66 | + // auto result = debugEngine->eval(results["eval"].getRaw<std::string>()); |
| 67 | + // std::ostringstream sout; |
| 68 | + // PrintValue(sout, result); |
| 69 | + // output.success(sout.str()); |
| 70 | + // } catch (Exception& e) { |
| 71 | + // PrintException(e); |
| 72 | + // } |
| 73 | + // } else { |
| 74 | + // if (isInConsoleDebugMode) { |
| 75 | + // // EndDebug |
| 76 | + // lse::getSelfPluginInstance().getLogger().info("Debug mode ended"); |
| 77 | + // isInConsoleDebugMode = false; |
| 78 | + // } else { |
| 79 | + // // StartDebug |
| 80 | + // lse::getSelfPluginInstance().getLogger().info("Debug mode begins"); |
| 81 | + // isInConsoleDebugMode = true; |
| 82 | + // std::cout << "> " << std::flush; |
| 83 | + // } |
| 84 | + // } |
| 85 | + // }); |
| 86 | + // DynamicCommand::setup(ll::service::getCommandRegistry(), std::move(command)); |
| 87 | + auto& command = ll::command::CommandRegistrar::getInstance() |
| 88 | + .getOrCreateCommand(LLSE_DEBUG_CMD, "Debug LegacyScriptEngine", CommandPermissionLevel::Owner); |
| 89 | + command.overload<EngineDebugCommand>().optional("eval").execute( |
| 90 | + [](CommandOrigin const&, CommandOutput& output, EngineDebugCommand const& param) { |
| 91 | + if (!param.eval.empty()) { |
| 92 | + EngineScope enter(debugEngine); |
| 93 | + try { |
| 94 | + auto result = debugEngine->eval(param.eval); |
| 95 | + std::ostringstream sout; |
| 96 | + PrintValue(sout, result); |
| 97 | + output.success(sout.str()); |
| 98 | + } catch (Exception& e) { |
| 99 | + PrintException(e); |
| 100 | + } |
69 | 101 | } else { |
70 | | - // StartDebug |
71 | | - lse::getSelfPluginInstance().getLogger().info("Debug mode begins"); |
72 | | - isInConsoleDebugMode = true; |
73 | | - std::cout << "> " << std::flush; |
| 102 | + if (isInConsoleDebugMode) { |
| 103 | + // EndDebug |
| 104 | + lse::getSelfPluginInstance().getLogger().info("Debug mode ended"); |
| 105 | + isInConsoleDebugMode = false; |
| 106 | + } else { |
| 107 | + // StartDebug |
| 108 | + lse::getSelfPluginInstance().getLogger().info("Debug mode begins"); |
| 109 | + isInConsoleDebugMode = true; |
| 110 | + std::cout << "> " << std::flush; |
| 111 | + } |
74 | 112 | } |
75 | 113 | } |
76 | | - }); |
77 | | - DynamicCommand::setup(ll::service::getCommandRegistry(), std::move(command)); |
| 114 | + ); |
78 | 115 | } |
0 commit comments