1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-22 07:28:47 +00:00

依赖判断

This commit is contained in:
GeekFrog 2017-07-10 20:20:24 +08:00
parent 405deda1d5
commit 82cdd32945

View File

@ -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,31 +15,35 @@ 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 {
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 + " authorGeekFrog QQ324747460"));
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " https://github.com/geekfrog/PermissionsTime/ "));
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
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 + " authorGeekFrog QQ324747460"));
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){
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
if (PluginCfg.IS_METRICS) {
try {
Metrics metrics = new Metrics(this);
metrics.start();
@ -46,8 +51,14 @@ public class PluginMain extends JavaPlugin {
e.printStackTrace();
}
}
getServer().getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
public void run() {
if (!checkPluginDepends()) {
getServer().getPluginManager().disablePlugin(pm);
}
}
}, 0L, 432000L);
}
public static PluginMain getInstance() {
return pm;
@ -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);
}
}