1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-26 10:38:53 +00:00
PermissionsTime/src/main/gg/frog/mc/permissionstime/PluginMain.java

108 lines
3.8 KiB
Java
Raw Normal View History

2017-07-06 10:17:54 +00:00
package gg.frog.mc.permissionstime;
import java.util.Locale;
import java.util.logging.Logger;
2017-07-10 05:06:41 +00:00
2017-07-10 12:20:24 +00:00
import org.bukkit.Bukkit;
2017-07-06 10:17:54 +00:00
import org.bukkit.plugin.java.JavaPlugin;
2017-07-10 05:06:41 +00:00
import org.mcstats.Metrics;
2017-07-06 10:17:54 +00:00
import gg.frog.mc.permissionstime.command.TheCommand;
import gg.frog.mc.permissionstime.config.ConfigManager;
import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.listener.TheListener;
import gg.frog.mc.permissionstime.utils.StrUtil;
public class PluginMain extends JavaPlugin {
2017-07-10 12:20:24 +00:00
public static String PLUGIN_NAME;
public static String PLUGIN_VERSION;
public static String PLUGIN_NAME_LOWER_CASE;
public static Logger LOG = Logger.getLogger("Minecraft");
2017-07-06 10:17:54 +00:00
private static PluginMain pm = null;
private ConfigManager cm = null;
2017-07-10 02:45:18 +00:00
2017-07-10 12:20:24 +00:00
public PluginMain() {
PLUGIN_NAME = getDescription().getName();
PLUGIN_VERSION = getDescription().getVersion();
PLUGIN_NAME_LOWER_CASE = PLUGIN_NAME.toLowerCase(Locale.ENGLISH);
}
2017-07-06 10:17:54 +00:00
@Override
public void onEnable() {
2017-07-10 12:20:24 +00:00
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();
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();
2017-07-10 05:06:41 +00:00
}
}
2017-07-10 12:20:24 +00:00
getServer().getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
public void run() {
if (!checkPluginDepends()) {
getServer().getPluginManager().disablePlugin(pm);
}
}
}, 0L, 432000L);
2017-07-06 10:17:54 +00:00
}
public static PluginMain getInstance() {
return pm;
}
/**
* 注册监听器 <br/>
* 这里可以注册多个
*/
private void registerListeners() {
this.getServer().getPluginManager().registerEvents(new TheListener(), this);
}
/**
* 注册命令 <br/>
* 这里可以注册多个一般注册一个就够用
*/
private void registerCommands() {
this.getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(new TheCommand());
}
public ConfigManager getConfigManager() {
return cm;
}
2017-07-10 05:06:41 +00:00
private boolean checkPluginDepends() {
2017-07-10 12:20:24 +00:00
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;
}
2017-07-10 05:06:41 +00:00
return true;
}
2017-07-10 12:20:24 +00:00
@Override
public void onDisable() {
super.onDisable();
getServer().getServicesManager().unregisterAll(this);
Bukkit.getScheduler().cancelTasks(this);
}
2017-07-06 10:17:54 +00:00
}