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);
}
});
}
}