mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2024-11-22 15:48:51 +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.Locale;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.mcstats.Metrics;
|
import org.mcstats.Metrics;
|
||||||
|
|
||||||
@ -14,39 +15,49 @@ import gg.frog.mc.permissionstime.utils.StrUtil;
|
|||||||
|
|
||||||
public class PluginMain extends JavaPlugin {
|
public class PluginMain extends JavaPlugin {
|
||||||
|
|
||||||
public static final String PLUGIN_NAME = "PermissionsTime";
|
public static String PLUGIN_NAME;
|
||||||
public static final String PLUGIN_VERSION = "0.0.1";
|
public static String PLUGIN_VERSION;
|
||||||
public static final String PLUGIN_NAME_LOWER_CASE = PLUGIN_NAME.toLowerCase(Locale.ENGLISH);
|
public static String PLUGIN_NAME_LOWER_CASE;
|
||||||
public static final Logger LOG = Logger.getLogger("Minecraft");
|
public static Logger LOG = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
private static PluginMain pm = null;
|
private static PluginMain pm = null;
|
||||||
private ConfigManager cm = 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
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
if (!checkPluginDepends()) {
|
super.onEnable();
|
||||||
|
pm = this;
|
||||||
} else {
|
cm = new ConfigManager();
|
||||||
pm = this;
|
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
|
||||||
cm = new ConfigManager();
|
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
|
||||||
registerListeners();
|
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " " + PluginMain.PLUGIN_NAME + " v" + PluginMain.PLUGIN_VERSION));
|
||||||
registerCommands();
|
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " author:GeekFrog QQ:324747460"));
|
||||||
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
|
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " https://github.com/geekfrog/PermissionsTime/ "));
|
||||||
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
|
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
|
||||||
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " " + PluginMain.PLUGIN_NAME + " v" + PluginMain.PLUGIN_VERSION));
|
registerListeners();
|
||||||
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " author:GeekFrog QQ:324747460"));
|
registerCommands();
|
||||||
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " https://github.com/geekfrog/PermissionsTime/ "));
|
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
|
||||||
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
|
if (PluginCfg.IS_METRICS) {
|
||||||
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
|
try {
|
||||||
if(PluginCfg.IS_METRICS){
|
Metrics metrics = new Metrics(this);
|
||||||
try {
|
metrics.start();
|
||||||
Metrics metrics = new Metrics(this);
|
} catch (Exception e) {
|
||||||
metrics.start();
|
e.printStackTrace();
|
||||||
} 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() {
|
public static PluginMain getInstance() {
|
||||||
@ -74,7 +85,23 @@ public class PluginMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkPluginDepends() {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
super.onDisable();
|
||||||
|
getServer().getServicesManager().unregisterAll(this);
|
||||||
|
Bukkit.getScheduler().cancelTasks(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user