From 82cdd32945d592b4f018dd69398a904c203202d6 Mon Sep 17 00:00:00 2001 From: GeekFrog Date: Mon, 10 Jul 2017 20:20:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=9D=E8=B5=96=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frog/mc/permissionstime/PluginMain.java | 79 +++++++++++++------ 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/src/main/gg/frog/mc/permissionstime/PluginMain.java b/src/main/gg/frog/mc/permissionstime/PluginMain.java index 072f9f3..c60c79b 100644 --- a/src/main/gg/frog/mc/permissionstime/PluginMain.java +++ b/src/main/gg/frog/mc/permissionstime/PluginMain.java @@ -3,6 +3,7 @@ package gg.frog.mc.permissionstime; import java.util.Locale; import java.util.logging.Logger; +import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.mcstats.Metrics; @@ -14,39 +15,49 @@ import gg.frog.mc.permissionstime.utils.StrUtil; public class PluginMain extends JavaPlugin { - public static final String PLUGIN_NAME = "PermissionsTime"; - public static final String PLUGIN_VERSION = "0.0.1"; - public static final String PLUGIN_NAME_LOWER_CASE = PLUGIN_NAME.toLowerCase(Locale.ENGLISH); - public static final Logger LOG = Logger.getLogger("Minecraft"); + public static String PLUGIN_NAME; + public static String PLUGIN_VERSION; + public static String PLUGIN_NAME_LOWER_CASE; + public static Logger LOG = Logger.getLogger("Minecraft"); private static PluginMain pm = null; private ConfigManager cm = null; + public PluginMain() { + PLUGIN_NAME = getDescription().getName(); + PLUGIN_VERSION = getDescription().getVersion(); + PLUGIN_NAME_LOWER_CASE = PLUGIN_NAME.toLowerCase(Locale.ENGLISH); + } + @Override public void onEnable() { - if (!checkPluginDepends()) { - - } else { - pm = this; - cm = new ConfigManager(); - registerListeners(); - registerCommands(); - pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "===============================")); - pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX)); - pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " " + PluginMain.PLUGIN_NAME + " v" + PluginMain.PLUGIN_VERSION)); - pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " author:GeekFrog QQ:324747460")); - pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " https://github.com/geekfrog/PermissionsTime/ ")); - pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX)); - pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "===============================")); - if(PluginCfg.IS_METRICS){ - try { - Metrics metrics = new Metrics(this); - metrics.start(); - } catch (Exception e) { - e.printStackTrace(); - } + super.onEnable(); + pm = this; + cm = new ConfigManager(); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "===============================")); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX)); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " " + PluginMain.PLUGIN_NAME + " v" + PluginMain.PLUGIN_VERSION)); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " author:GeekFrog QQ:324747460")); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " https://github.com/geekfrog/PermissionsTime/ ")); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX)); + registerListeners(); + registerCommands(); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "===============================")); + if (PluginCfg.IS_METRICS) { + try { + Metrics metrics = new Metrics(this); + metrics.start(); + } catch (Exception e) { + e.printStackTrace(); } } + getServer().getScheduler().runTaskTimerAsynchronously(this, new Runnable() { + public void run() { + if (!checkPluginDepends()) { + getServer().getPluginManager().disablePlugin(pm); + } + } + }, 0L, 432000L); } public static PluginMain getInstance() { @@ -74,7 +85,23 @@ public class PluginMain extends JavaPlugin { } private boolean checkPluginDepends() { - // return false; + boolean needDepend = false; + for(String name : getDescription().getSoftDepend()){ + if(getServer().getPluginManager().getPlugin(name) == null){ + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Need depend plugins : " + name)); + needDepend = true; + } + } + if(needDepend){ + return false; + } return true; } + + @Override + public void onDisable() { + super.onDisable(); + getServer().getServicesManager().unregisterAll(this); + Bukkit.getScheduler().cancelTasks(this); + } }