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

获取离线玩家计分板数值空 #1308

Closed EpsilonZunsat closed 1 year ago

EpsilonZunsat commented 1 year ago

异常模块

LiteLoader (本体)

操作系统

Windows 11

LiteLoader 版本

LiteLoaderBDS 2.14.1-dev.0+612c3fc

BDS 版本

Version: 1.20.0.01(ProtocolVersion 589)

发生了什么?

使用获取离线玩家计分板函数无法取得正确的std::opt

复现此问题的步骤

int getScoreMoney(string xuid, string name) {
        auto sc=Scoreboard::queryPlayerScore(xuid, name);
        if (sc.has_value()) {
            return sc.value();
        }
        else {
            return 0;
        }
}
bool addScoreMoney(string xuid,string name,long long money) {
    auto addscoremoney = Scoreboard::forceModifyPlayerScore(xuid, name, money, PlayerScoreSetFunction::Add);
    return addscoremoney;
}
bool reduceScoreMoney(string xuid, string name, long long money) {
    auto reducescoremoney = Scoreboard::forceModifyPlayerScore(xuid, name, money, PlayerScoreSetFunction::Remove);
    return reducescoremoney;
}
Event::PlayerJoinEvent::subscribe([](const Event::PlayerJoinEvent& ev) {
         auto xuid = ev.mPlayer->getXuid();
         auto pl = ev.mPlayer;
         logger.info("money:{}", getScoreMoney(ev.mPlayer->getXuid(),"in"));
         logger.info("{}", pl->getScore("in"));
         logger.info("money:{}", getScoreMoney(ev.mPlayer->getXuid(), "inb"));
         auto aa = reduceScoreMoney(xuid,"in", 800);
         logger.info("{}", pl->getScore("in"));
         logger.info("money:{},aa{}", getScoreMoney(ev.mPlayer->getXuid(),"in"), aa);
         auto bb = addScoreMoney(xuid, "in", 8000);
         logger.info("money:{},bb{}", getScoreMoney(ev.mPlayer->getXuid(),"in"), bb);
         logger.info("{}", pl->getScore("in"));
         return true;
         });

获取不到名为"in"的积分板参数,但是可以看到加减不影响

有关的日志/输出

参数内容

插件列表

无影响插件
ShrBox commented 1 year ago

离线计分板API为社区贡献,目前已缺乏维护,我们也没有精力去修复这个API 另外此API可能不会被移植到LL3中 如果您想要实现一个经济系统,最佳方案是使用sqlite或mysql,而不是使用计分板

EpsilonZunsat commented 1 year ago

感谢各位开发者对社区的贡献,我理解你们的难处,我再自行研究尝试复现相关内容