1
0
Fork 0

[+] 修改机器人启动时机到服务器完全加载完成

master
Taskeren 2019-07-10 23:40:41 +08:00
parent eefd64da20
commit 46b80345aa
4 changed files with 40 additions and 3 deletions

View File

@ -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();

View File

@ -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) {
}
}
}

View File

@ -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 {

View File

@ -1,5 +1,5 @@
name: NativeBot
main: ren.taske.nativebot.MinecraftPlugin
main: ren.taske.nativebot.NativeBotPlugin
version: 1.1.0
commands: