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.13k stars 115 forks source link

LLSE ob.setScore / pl.setScore 不会自动在计分板中创建目标 #860

Closed cngege closed 1 year ago

cngege commented 2 years ago

异常模块

ScriptEngine (脚本引擎)

操作系统

Windows 10

LiteLoader 版本

LiteLoaderBDS 2.7.2+2b8c54d25

BDS 版本

Version 1.19.31.01(ProtocolVersion 554)

发生了什么?

LLSE JS中(非Nodejs ,这里面没测试) ob.setScorepl.setScore 均不能自动创建计分板目标,即第一个函数里面的第一个参数 玩家,第二个函数里面的pl 比如 ob.setScore(player,1); (我确定这里的ob 不为null,且是有效的计分板对象,计分板也存在,计分板名称也无误,且player是真实有效的玩家对象) 这句函数在执行的时候 不会返回null,控制台也没有报错,游戏中的计分板(在右侧显示)除了显示标题空空如也 如果使用命令 /scoreboard players add XXX jifenban 将player玩家添加到该计分板中,则这条函数可以正常使用(正常设置分数) 如果ob.setScore()的第一个参数为字符串(这个字符串目标不在该计分板中的时候),执行函数控制台会报错 总结 :核心的问题是,这条函数(或许还有其他计分板函数)在之前的版本中是可以检测并创建计分板目标后然后再设置目标分数的,但现在并不会检测并创建计分板目标了(这里的计分板目标指的是计分板中的玩家名)

复现此问题的步骤

附上我的脚本作为参考

/*
 *  开发者 - CNGEGE
 */

(function(){
    //logger.setConsole(true);
    let ob = null;
    let obname = "onlineplayers";
    let obshowname = "在线玩家(ping)";
    let timerid = -1;
    let timeout = 1000 * 5;

    function ServerStarted(){
        ob = mc.getScoreObjective(obname);
        if(ob == null){
            logger.log("计分板为空");
            ob = mc.newScoreObjective(obname,obshowname);
            ob.setDisplay("sidebar");
        }else if(ob.displayName != obshowname)
        {
            logger.log("计分板名字不对应");
            mc.removeScoreObjective(obname);
            ob = mc.newScoreObjective(obname,obshowname);
            ob.setDisplay("sidebar");
        }
        logger.log("服务开启");
    }

    function Join(player){
        //logger.log("玩家加入游戏");
        //logger.log("当前玩家数量:",mc.getOnlinePlayers().length.toString());
        let device = player.getDevice();
        player.setScore(obname,device.avgPing);
        //如果 当前只有这一位玩家 则开启一个计时器,每5s计算一次玩家的ping值 直到没有玩家在线了,则关闭计时器

        if(mc.getOnlinePlayers().length == 1)
        {
            timerid = setInterval(()=>{
                let players = mc.getOnlinePlayers();
                if(players.length == 0){
                    clearInterval(timerid);
                }else{
                    for(i=0;i<players.length;i++){
                        let dev = players[i].getDevice();
                        //logger.log("玩家名字:"+players[i].name+" 延迟:"+dev.lastPing.toString());
                        //players[i].setScore(obname,dev.lastPing);
                        if(ob.setScore(players[i],dev.lastPing) == null){
                            logger.log("失败");
                        }
                    }
                }
            },timeout);
        }
    }

    function Left(player){
        //logger.log("玩家退出游戏");
        player.deleteScore(obname);
    }

    mc.listen("onJoin",Join);
    mc.listen("onLeft",Left);
    mc.listen("onServerStarted",ServerStarted);
})()

有关的日志/输出

No response

插件列表

22:20:58 INFO [Server] 插件列表 [12]
22:20:58 INFO [Server] - AutoFishing [v1.2.1] (AutoFishing.dll)
22:20:58 INFO [Server]   LL版 BDS服务器全自动挂机钓鱼
22:20:58 INFO [Server] - DispenserGetLavaFromCauldron [v3.2.1] (DispenserGetLavaFromCauldron.dll)
22:20:58 INFO [Server]   用发射器向装有岩浆的炼药锅发射空桶以装岩浆/反之亦然
22:20:58 INFO [Server] - TreeCuttingAndMining [v2.1.0] (TreeCuttingAndMining.dll)
22:20:58 INFO [Server]   砍树与挖矿插件
22:20:58 INFO [Server] - DispenserDestroyBlock [v2.1.1] (DispenserDestroyBlock.dll)
22:20:58 INFO [Server]   激活发射器利用工具破坏方块
22:20:58 INFO [Server] - LLMoney [v2.7.0] (LLMoney.dll)
22:20:58 INFO [Server]   EconomyCore for LiteLoaderBDS
22:20:58 INFO [Server] - Hundred_Times [v1.0.0] (Hundred_Times.dll)
22:20:58 INFO [Server]   百倍掉落物 by CNGEGE
22:20:58 INFO [Server] - PlayerKB [v1.2.0] (PlayerKB.dll)
22:20:58 INFO [Server]   玩家击退&间隔控制
22:20:58 INFO [Server] - PermissionAPI [v2.7.0] (PermissionAPI.dll)
22:20:58 INFO [Server]   Builtin & Powerful permission API for LiteLoaderBDS
22:20:58 INFO [Server] - ScriptEngine-QuickJs [v2.7.2] (LiteLoader.Js.dll)
22:20:58 INFO [Server]   Javascript ScriptEngine for LiteLoaderBDS
22:20:58 INFO [Server] - onLinePlayer [v1.0.0] (onLinePlayer.js)
22:20:58 INFO [Server]   onLinePlayer
22:20:58 INFO [Server] - ScriptEngine-Lua [v2.7.2] (LiteLoader.Lua.dll)
22:20:58 INFO [Server]   Lua ScriptEngine for LiteLoaderBDS
22:20:58 INFO [Server] - ScriptEngine-NodeJs [v2.7.2] (LiteLoader.NodeJs.dll)
22:20:58 INFO [Server]   Node.js ScriptEngine for LiteLoaderBDS
22:20:58 INFO [Server]
22:20:58 INFO [Server]
Redbeanw44602 commented 1 year ago

move to #971