使用java开发时JAutoSavePluginData不保存东西
-
data文件里只有"{}"两个字符
-
Plugin.java:package top.yuyanmc;
import net.mamoe.mirai.console.data.Value;
import net.mamoe.mirai.console.plugin.jvm.JavaPlugin;
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescriptionBuilder;
import net.mamoe.mirai.event.GlobalEventChannel;
import net.mamoe.mirai.event.events.GroupMessageEvent;
import net.mamoe.mirai.message.data.*;
import top.yuyanmc.data.Data;import java.util.Map;
public final class Plugin extends JavaPlugin {
public static final Plugin INSTANCE = new Plugin();private Plugin() { super(new JvmPluginDescriptionBuilder("top.yuyanmc.plugin", "1.1-beta") .name("Misuka Server Plugin") .author("yuyanMC") .build()); } @Override public void onEnable() { this.reloadPluginData(Data.INSTANCE); getLogger().info("Plugin loaded!"); GlobalEventChannel.INSTANCE.subscribeAlways(GroupMessageEvent.class, (GroupMessageEvent event) ->{ if(event.getMessage().contentToString().contains("awa")) { event.getGroup().sendMessage("awa"); } if(event.getMessage().contentEquals("签到",false)) { getLogger().info(event.getSender().getNick() + "signed."); Value<Map<Long, Long>> signed_warped = Data.INSTANCE.signed; Map<Long, Long> signed = signed_warped.get(); if(signed.containsKey(event.getSender().getId()) && signed.get(event.getSender().getId())/86400000 >= System.currentTimeMillis()/86400000) { MessageContent messageContent; MessageContent messageContent2; messageContent = new At(event.getSender().getId()); messageContent2 = new PlainText("你已经签到过了!"); MessageChain messageChain = MessageUtils.newChain(messageContent, messageContent2); event.getGroup().sendMessage(messageChain); } else { MessageContent messageContent; MessageContent messageContent2; messageContent = new At(event.getSender().getId()); signed.put(event.getSender().getId(), System.currentTimeMillis()); Value<Map<Long, Long>> point_warped = Data.INSTANCE.point; Map<Long, Long> point = point_warped.get(); if(point.containsKey(event.getSender().getId())){ point.put(event.getSender().getId(), point.get(event.getSender().getId())+10); }else{ point.put(event.getSender().getId(), 10L); } messageContent2 = new PlainText("签到成功!\n当前积分:"+point.get(event.getSender().getId()).toString()); point_warped.set(point); Data.INSTANCE.onValueChanged(point_warped); MessageChain messageChain = MessageUtils.newChain(messageContent, messageContent2); event.getGroup().sendMessage(messageChain); } signed_warped.set(signed); Data.INSTANCE.onValueChanged(signed_warped); savePluginData(Data.INSTANCE); } }); }
}
-
Data.java:package top.yuyanmc.data;
import net.mamoe.mirai.console.data.Value;
import net.mamoe.mirai.console.data.java.JAutoSavePluginData;
import org.jetbrains.annotations.NotNull;import java.util.HashMap;
import java.util.Map;public class Data extends JAutoSavePluginData {
public static final Data INSTANCE = new Data("Misuka_data");
public final Value<Map<Long, Long>> signed = typedValue(createKType(Map.class, createKType(Long.class), createKType(Long.class)));
public final Value<Map<Long, Long>> point = typedValue(createKType(Map.class, createKType(Long.class), createKType(Long.class)));public Data(@NotNull String saveName) { super(saveName); }
}
-
请问执行 /stop 后是否还有此问题,如果还有请前往仓库发issue
-