mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2024-11-22 15:48:51 +00:00
hook api
This commit is contained in:
parent
82cdd32945
commit
70f6de05e9
1
pom.xml
1
pom.xml
@ -112,6 +112,7 @@
|
|||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.0.0</version>
|
<version>3.0.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<artifactSet>
|
<artifactSet>
|
||||||
<includes>
|
<includes>
|
||||||
<include>org.mcstats.*:*</include>
|
<include>org.mcstats.*:*</include>
|
||||||
|
@ -4,6 +4,7 @@ import java.util.Locale;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.mcstats.Metrics;
|
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.config.PluginCfg;
|
||||||
import gg.frog.mc.permissionstime.listener.TheListener;
|
import gg.frog.mc.permissionstime.listener.TheListener;
|
||||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||||
|
import lib.PatPeter.SQLibrary.SQLite;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin {
|
public class PluginMain extends JavaPlugin {
|
||||||
|
|
||||||
public static String PLUGIN_NAME;
|
public static String PLUGIN_NAME;
|
||||||
public static String PLUGIN_VERSION;
|
public static String PLUGIN_VERSION;
|
||||||
public static String PLUGIN_NAME_LOWER_CASE;
|
public static String PLUGIN_NAME_LOWER_CASE;
|
||||||
|
public static final String DEPEND_PLUGIN = "SQLibrary,Vault";
|
||||||
public static Logger LOG = Logger.getLogger("Minecraft");
|
public static Logger LOG = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
private static PluginMain pm = null;
|
public static PluginMain pm = null;
|
||||||
private ConfigManager cm = null;
|
public static ConfigManager cm = null;
|
||||||
|
public static Permission permission = null;
|
||||||
|
|
||||||
public PluginMain() {
|
public PluginMain() {
|
||||||
PLUGIN_NAME = getDescription().getName();
|
PLUGIN_NAME = getDescription().getName();
|
||||||
@ -40,8 +45,6 @@ public class PluginMain extends JavaPlugin {
|
|||||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " author:GeekFrog QQ:324747460"));
|
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 + " https://github.com/geekfrog/PermissionsTime/ "));
|
||||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
|
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
|
||||||
registerListeners();
|
|
||||||
registerCommands();
|
|
||||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
|
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
|
||||||
if (PluginCfg.IS_METRICS) {
|
if (PluginCfg.IS_METRICS) {
|
||||||
try {
|
try {
|
||||||
@ -55,6 +58,9 @@ public class PluginMain extends JavaPlugin {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (!checkPluginDepends()) {
|
if (!checkPluginDepends()) {
|
||||||
getServer().getPluginManager().disablePlugin(pm);
|
getServer().getPluginManager().disablePlugin(pm);
|
||||||
|
} else {
|
||||||
|
registerListeners();
|
||||||
|
registerCommands();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0L, 432000L);
|
}, 0L, 432000L);
|
||||||
@ -86,13 +92,21 @@ public class PluginMain extends JavaPlugin {
|
|||||||
|
|
||||||
private boolean checkPluginDepends() {
|
private boolean checkPluginDepends() {
|
||||||
boolean needDepend = false;
|
boolean needDepend = false;
|
||||||
for(String name : getDescription().getSoftDepend()){
|
for (String name : DEPEND_PLUGIN.split(",")) {
|
||||||
if(getServer().getPluginManager().getPlugin(name) == null){
|
if (getServer().getPluginManager().getPlugin(name) == null) {
|
||||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Need depend plugins : " + name));
|
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Need depend plugins : " + name));
|
||||||
needDepend = true;
|
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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -104,4 +118,26 @@ public class PluginMain extends JavaPlugin {
|
|||||||
getServer().getServicesManager().unregisterAll(this);
|
getServer().getServicesManager().unregisterAll(this);
|
||||||
Bukkit.getScheduler().cancelTasks(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user