diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/McBot.java b/fabric/src/main/java/cn/evole/mods/mcbot/McBot.java index 337e1a1f..136f5c16 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/McBot.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/McBot.java @@ -1,12 +1,9 @@ package cn.evole.mods.mcbot; import cn.evole.mods.mcbot.init.callbacks.IEvents; -import cn.evole.mods.mcbot.init.event.IChatEvent; -import cn.evole.mods.mcbot.init.event.ICmdEvent; -import cn.evole.mods.mcbot.init.event.IPlayerEvent; +import cn.evole.mods.mcbot.init.event.*; import cn.evole.mods.mcbot.init.handler.ConfigHandler; import cn.evole.mods.mcbot.init.handler.CustomCmdHandler; -import cn.evole.mods.mcbot.init.event.IBotEvent; import cn.evole.mods.mcbot.util.locale.I18n; import cn.evole.onebot.client.connection.ConnectFactory; import cn.evole.onebot.client.core.Bot; @@ -20,6 +17,7 @@ //$$ import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; //#endif import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.server.MinecraftServer; @@ -62,6 +60,8 @@ public void onInitialize() { ServerLifecycleEvents.SERVER_STOPPING.register(this::onServerStopping); ServerLifecycleEvents.SERVER_STOPPED.register(this::onServerStopped); + ServerTickEvents.END_SERVER_TICK.register(ITickEvent::register); + IEvents.PLAYER_LOGGED_IN.register(IPlayerEvent::loggedIn); IEvents.PLAYER_LOGGED_OUT.register(IPlayerEvent::loggedOut); IEvents.PLAYER_ADVANCEMENT.register(IPlayerEvent::advancement); diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java index f02389f7..92dedf84 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/IBotEvent.java @@ -59,7 +59,7 @@ public void onMessage(GroupMessageEvent event) { ? String.format("§b[§l%s§r(§5%s§b)]§a<%s>§f %s", ConfigHandler.cached().getCmd().getQqGamePrefix(), event.getGroupId(), groupNick, send) : String.format("§b[§l%s§b]§a<%s>§f %s", ConfigHandler.cached().getCmd().getQqGamePrefix(), groupNick, send) : String.format("§a<%s>§f %s", groupNick, send); - ITickEvent.getToSendQueue().add(toSend); + ITickEvent.getSendQueue().add(toSend); } } }); @@ -135,7 +135,7 @@ public void onMessage(GuildMessageEvent event) { ? String.format("§b[§l%s§r(§5%s§b)]§a<%s>§f %s", ConfigHandler.cached().getCmd().getGuildGamePrefix(), event.getChannelId(), guildNick, send) : String.format("§b[§l%s§b]§a<%s>§f %s", ConfigHandler.cached().getCmd().getGuildGamePrefix(), guildNick, send) : String.format("§a<%s>§f %s", guildNick, send); - ITickEvent.getToSendQueue().add(toSend); + ITickEvent.getSendQueue().add(toSend); } } diff --git a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java index 6da40e0a..7485927d 100644 --- a/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java +++ b/fabric/src/main/java/cn/evole/mods/mcbot/init/event/ITickEvent.java @@ -25,16 +25,15 @@ * Version: 1.0 */ public class ITickEvent { - private static final Queue toSendQueue = new LinkedList<>(); - ; + private static final Queue SEND_QUEUE = new LinkedList<>(); - public static Queue getToSendQueue() { - return toSendQueue; + public static Queue getSendQueue() { + return SEND_QUEUE; } - public static void init(MinecraftServer server) { - String toSend = toSendQueue.poll(); + public static void register(MinecraftServer server) { + String toSend = SEND_QUEUE.poll(); if (ConfigHandler.cached() != null && server.isDedicatedServer() && toSend != null