LiteLDev / LeviLamina

A lightweight, modular and versatile mod loader for Minecraft Bedrock Edition, formerly known as LiteLoaderBDS
https://levimc.org/software/levilamina
GNU Lesser General Public License v3.0
1.14k stars 117 forks source link

Command.setCallback()回调函数使用异步无法正常使用参数 #1284

Closed CatsLoveTw closed 1 year ago

CatsLoveTw commented 1 year ago

异常模块

ScriptEngine (脚本引擎)

操作系统

Windows 11

LiteLoader 版本

2.13.1

BDS 版本

1.19.81

发生了什么?

语言:NodeJs

回调函数使用await后,CommandOrigin和CommandOutput参数便失去功用。

复现此问题的步骤

function promiseExample () {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve("success")
        }, 1000)
    })
}

// command是利用mc.newCommand()函数返回后取得的值
// 测试1 => 测试output
command.setCallback(async (cmd, ori, output, result) => {
                output.addMessage("test1") // 正常执行
                let message = await promiseExample()
                output.success(message) // 执行错误,请见输出1
})

// 测试2 => 测试origin
command2.setCallback(async (cmd, ori, output, result) => {
                output.addMessage("test2") // 正常执行
                log("test1:" + ori.player.realName) // 正常执行
                await promiseExample()
                if (ori.player) log("test2:3 " + ori.player.realName) // 执行错误,请见输出2
})

有关的日志/输出

输出1
14:58:25 INFO [testPlugin] test1
14:58:25 ERROR [LiteLoader] C++ Uncaught Exception Detected!
14:58:25 ERROR [LiteLoader] SEH_UNKNOW_ERROR
14:58:25 ERROR [LiteLoader]
14:58:25 ERROR [LiteLoader] In API: CommandOutputClass::success
14:58:25 ERROR [LiteLoader] In Plugin: testPlugin
输出2
15:00:23 INFO [testPlugin] test1:Cat1238756
15:00:23 ERROR [LiteLoader] C++ Uncaught Exception Detected!
15:00:23 ERROR [LiteLoader] SEH_UNKNOW_ERROR
15:00:23 ERROR [LiteLoader]
15:00:23 ERROR [LiteLoader] In API: CommandOriginClass::getPlayer
15:00:23 ERROR [LiteLoader] In Plugin: testPlugin

插件列表

15:04:37 INFO [Server] 插件列表[8]
15:04:37 INFO [Server] - LLMoney [v2.13.0] (LLMoney.dll)
15:04:37 INFO [Server]   EconomyCore for LiteLoaderBDS
15:04:37 INFO [Server] - ScriptEngine-Lua [v2.13.1] (LiteLoader.Lua.dll)
15:04:37 INFO [Server]   Lua ScriptEngine for LiteLoaderBDS
15:04:37 INFO [Server] - QueryTPS [v1.0.1] (QueryTPS.dll)
15:04:37 INFO [Server]   查询TPS
15:04:37 INFO [Server] - ScriptEngine-NodeJs [v2.13.1] (LiteLoader.NodeJs.dll)
15:04:37 INFO [Server]   Node.js ScriptEngine for LiteLoaderBDS
15:04:37 INFO [Server] - PermissionAPI [v2.9.0] (PermissionAPI.dll)
15:04:37 INFO [Server]   Builtin & Powerful permission API for LiteLoaderBDS
15:04:37 INFO [Server] - testPlugin [v0.0.1] (index)
15:04:37 INFO [Server]   testCode for issue
15:04:37 INFO [Server] - ScriptEngine-QuickJs [v2.13.1] (LiteLoader.Js.dll)
15:04:37 INFO [Server]   Javascript ScriptEngine for LiteLoaderBDS
15:04:37 INFO [Server] - ScriptEngine-Python [v2.13.1] (LiteLoader.Python.dll)
15:04:37 INFO [Server]   Python ScriptEngine for LiteLoaderBDS
dreamguxiang commented 1 year ago

不能异步