MiraiForum

    • Register
    • Login
    • Search
    • Popular
    • Recent
    • Unsolved
    • Tags
    • Groups
    • 友情链接

    Solved reloadPluginData加载不了数据

    开发交流
    2
    4
    51
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      oneoness last edited by

      数据

      public class UserMap extends JavaAutoSavePluginData {
          public UserMap() {
              super("bili_userMap");
          }
      }
      

      命令

      @Slf4j
      public class TestCommand extends JRawCommand {
          public TestCommand() {
              super(ConsoleCommandOwner.INSTANCE, "test", "test");
          }
      
          @Override
          public void onCommand(@NotNull CommandContext context, @NotNull MessageChain args) {
              UserMap userMap = new UserMap();
              AutoPlanPlugin.INSTANCE.reloadPluginData(userMap);
              log.info(String.valueOf(userMap.getValueNodes().size()));
              for (AbstractPluginData.ValueNode<?> valueNode : userMap.getValueNodes()) {
                  log.info(valueNode.getValueName() + "=" + valueNode.getValue());
              }
          }
      }
      

      yml文件内的数据

      test: test
      a: a
      b:
        c: c
      

      启动后使用命令的日志

      > /test
      2022-10-11 11:39:54 W/stderr: [DefaultDispatcher-worker-2] INFO cn.cimoc.mirai.plugin.bili.command.TestCommand - 0
      2022-10-11 11:39:54 W/stderr: 
      

      可以看到使用reloadPluginData方法后,这个数据对象中的数据依旧是空的,请问我哪里操作不当。

      1 Reply Last reply Reply Quote 0
      • Topic has been marked as a question  O oneoness 
      • StageGuard
        StageGuard last edited by StageGuard

        你要在你的 UserMap 里指定数据才能被正确读取。
        https://github.com/mamoe/mirai/blob/dev/mirai-console/backend/mirai-console/src/data/java/JavaAutoSavePluginData.kt#L49

        O 1 Reply Last reply Reply Quote 0
        • O
          oneoness @StageGuard last edited by

          @StageGuard 感谢,那如果我不指定,想读取全部数据,是不可以的吗

          1 Reply Last reply Reply Quote 0
          • StageGuard
            StageGuard last edited by StageGuard

            @oneoness 数据文件yml不应该被手动编辑,他是jautosaveplugin自动保存的,只需要在 usermap 修改对应的值,他就会自动保存到yml里

            1 Reply Last reply Reply Quote 0
            • Topic has been marked as solved  O oneoness 
            • 1 / 1
            • First post
              Last post
            Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact