mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2024-12-23 05:18:47 +00:00
依赖判断
This commit is contained in:
parent
405deda1d5
commit
82cdd32945
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user