1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-21 23:08:48 +00:00
This commit is contained in:
GeekFrog 2017-07-10 20:55:45 +08:00
parent 82cdd32945
commit 70f6de05e9
2 changed files with 44 additions and 7 deletions

View File

@ -112,6 +112,7 @@
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>org.mcstats.*:*</include>

View File

@ -4,6 +4,7 @@ import java.util.Locale;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.mcstats.Metrics;
@ -12,16 +13,20 @@ 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;
import lib.PatPeter.SQLibrary.SQLite;
import net.milkbowl.vault.permission.Permission;
public class PluginMain extends JavaPlugin {
public static String PLUGIN_NAME;
public static String PLUGIN_VERSION;
public static String PLUGIN_NAME_LOWER_CASE;
public static final String DEPEND_PLUGIN = "SQLibrary,Vault";
public static Logger LOG = Logger.getLogger("Minecraft");
private static PluginMain pm = null;
private ConfigManager cm = null;
public static PluginMain pm = null;
public static ConfigManager cm = null;
public static Permission permission = null;
public PluginMain() {
PLUGIN_NAME = getDescription().getName();
@ -40,8 +45,6 @@ public class PluginMain extends JavaPlugin {
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 {
@ -55,6 +58,9 @@ public class PluginMain extends JavaPlugin {
public void run() {
if (!checkPluginDepends()) {
getServer().getPluginManager().disablePlugin(pm);
} else {
registerListeners();
registerCommands();
}
}
}, 0L, 432000L);
@ -86,13 +92,21 @@ public class PluginMain extends JavaPlugin {
private boolean checkPluginDepends() {
boolean needDepend = false;
for(String name : getDescription().getSoftDepend()){
if(getServer().getPluginManager().getPlugin(name) == null){
for (String name : DEPEND_PLUGIN.split(",")) {
if (getServer().getPluginManager().getPlugin(name) == null) {
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Need depend plugins : " + name));
needDepend = true;
}
}
if(needDepend){
if (!setupPermissions()) {
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Cann't hook vault permission"));
needDepend = true;
}
if (!setupDatabase()) {
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Cann't setup database"));
needDepend = true;
}
if (needDepend) {
return false;
}
return true;
@ -104,4 +118,26 @@ public class PluginMain extends JavaPlugin {
getServer().getServicesManager().unregisterAll(this);
Bukkit.getScheduler().cancelTasks(this);
}
private boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
}
return (permission != null);
}
private boolean setupDatabase() {
try {
SQLite sql = new SQLite(Logger.getLogger("Minecraft"), "[" + PLUGIN_NAME + "] ", this.getDataFolder().getAbsolutePath(), PLUGIN_NAME, ".sqlite");
if(!sql.isOpen()){
sql.open();
}
sql.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
}