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,30 +15,34 @@ 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();
|
||||||
|
|
||||||
} else {
|
|
||||||
pm = this;
|
pm = this;
|
||||||
cm = new ConfigManager();
|
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();
|
registerListeners();
|
||||||
registerCommands();
|
registerCommands();
|
||||||
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));
|
|
||||||
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) {
|
if (PluginCfg.IS_METRICS) {
|
||||||
try {
|
try {
|
||||||
Metrics metrics = new Metrics(this);
|
Metrics metrics = new Metrics(this);
|
||||||
@ -46,8 +51,14 @@ public class PluginMain extends JavaPlugin {
|
|||||||
e.printStackTrace();
|
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() {
|
||||||
return pm;
|
return pm;
|
||||||
@ -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