diff --git a/src/main/java/ren/taske/nativebot/NativeBotPlugin.java b/src/main/java/ren/taske/nativebot/NativeBotPlugin.java index 694553d..abae4a9 100644 --- a/src/main/java/ren/taske/nativebot/NativeBotPlugin.java +++ b/src/main/java/ren/taske/nativebot/NativeBotPlugin.java @@ -10,6 +10,7 @@ import cn.glycol.t18n.I18n; import ren.taske.nativebot.bot.chatting.Chatting; import ren.taske.nativebot.bot.chatting.MinecraftMessage; import ren.taske.nativebot.bot.chatting.TencentMessage; +import ren.taske.nativebot.bot.listener.ServerLoadEventListener; import ren.taske.nativebot.core.NativeBot; import ren.taske.nativebot.i18n.I18nInit; import ren.taske.nativebot.minecraft.command.CommandQQ; @@ -23,6 +24,8 @@ public class NativeBotPlugin extends JavaPlugin { protected final MinecraftMessage mcevent = new MinecraftMessage(this); protected final TencentMessage tencentevent = new TencentMessage(this); + protected final ServerLoadEventListener botstartevent = new ServerLoadEventListener(); + protected final CommandQQ cmdqq = new CommandQQ(this); protected final CommandQQAdmin cmdqqadmin = new CommandQQAdmin(); @@ -41,6 +44,9 @@ public class NativeBotPlugin extends JavaPlugin { nativebot.getBot().register(tencentevent); getServer().getPluginManager().registerEvents(mcevent, this); + + getServer().getPluginManager().registerEvents(botstartevent, this); + super.onEnable(); } @@ -62,7 +68,7 @@ public class NativeBotPlugin extends JavaPlugin { chatting.onMinecraftMessage(evt); } - public static JavaPlugin nativebotJavaPlugin; + public static NativeBotPlugin nativebotJavaPlugin; public static Logger logger() { return nativebotJavaPlugin.getLogger(); diff --git a/src/main/java/ren/taske/nativebot/bot/listener/ServerLoadEventListener.java b/src/main/java/ren/taske/nativebot/bot/listener/ServerLoadEventListener.java new file mode 100644 index 0000000..b846907 --- /dev/null +++ b/src/main/java/ren/taske/nativebot/bot/listener/ServerLoadEventListener.java @@ -0,0 +1,27 @@ +package ren.taske.nativebot.bot.listener; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.ServerLoadEvent; +import org.bukkit.event.server.ServerLoadEvent.LoadType; + +import ren.taske.nativebot.NativeBotPlugin; + +public class ServerLoadEventListener implements Listener { + + @EventHandler + public void onServerLoad(ServerLoadEvent evt) { + + LoadType type = evt.getType(); + + if(type == LoadType.STARTUP) { + NativeBotPlugin.nativebotJavaPlugin.getBot().start(); + } + + if(type == LoadType.RELOAD) { + + } + + } + +} diff --git a/src/main/java/ren/taske/nativebot/core/NativeBot.java b/src/main/java/ren/taske/nativebot/core/NativeBot.java index b9f0dcc..e3bf90f 100644 --- a/src/main/java/ren/taske/nativebot/core/NativeBot.java +++ b/src/main/java/ren/taske/nativebot/core/NativeBot.java @@ -41,7 +41,6 @@ public class NativeBot { public void onEnable() { bot.register(ClassUtils.instantiate(COMMANDS)); handleRegistrationEvent(); - bot.start(); for(String cmd : bot.getCommands()) logger.info("[C] "+cmd); } @@ -52,6 +51,11 @@ public class NativeBot { EventBotRegistration.newEventAndCall(getBot()); } + /** 启动机器人 */ + public void start() { + bot.start(); + } + @SuppressWarnings("deprecation") public void onDisable() { try { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d55ea80..e5699df 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: NativeBot -main: ren.taske.nativebot.MinecraftPlugin +main: ren.taske.nativebot.NativeBotPlugin version: 1.1.0 commands: