mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2024-11-21 23:08:48 +00:00
fix bugs
This commit is contained in:
parent
f00284314f
commit
e39fad59ef
@ -1,9 +1,12 @@
|
||||
package gg.frog.mc.permissionstime;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.mcstats.Metrics;
|
||||
@ -18,16 +21,16 @@ 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 String PLUGIN_NAME;
|
||||
public String PLUGIN_VERSION;
|
||||
public String PLUGIN_NAME_LOWER_CASE;
|
||||
public static final String DEPEND_PLUGIN = "SQLibrary,Vault";
|
||||
public static Logger LOG = Logger.getLogger("Minecraft");
|
||||
|
||||
public static PluginMain pm = null;
|
||||
public static ConfigManager cm = null;
|
||||
public static SqlManager sm = null;
|
||||
public static Permission permission = null;
|
||||
private ConfigManager cm = null;
|
||||
private PluginMain pm = null;
|
||||
private SqlManager sm = null;
|
||||
private Permission permission = null;
|
||||
|
||||
public PluginMain() {
|
||||
PLUGIN_NAME = getDescription().getName();
|
||||
@ -39,23 +42,23 @@ public class PluginMain extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
super.onEnable();
|
||||
pm = this;
|
||||
cm = new ConfigManager();
|
||||
cm = new ConfigManager(pm);
|
||||
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 + " " + PLUGIN_NAME + " v" + 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));
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
|
||||
if (PluginCfg.IS_METRICS) {
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
Metrics metrics = new Metrics(pm);
|
||||
metrics.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
getServer().getScheduler().runTask(this, new Runnable() {
|
||||
getServer().getScheduler().runTask(pm, new Runnable() {
|
||||
public void run() {
|
||||
if (!checkPluginDepends()) {
|
||||
getServer().getPluginManager().disablePlugin(pm);
|
||||
@ -67,16 +70,12 @@ public class PluginMain extends JavaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
public static PluginMain getInstance() {
|
||||
return pm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册监听器 <br/>
|
||||
* 这里可以注册多个
|
||||
*/
|
||||
private void registerListeners() {
|
||||
this.getServer().getPluginManager().registerEvents(new TheListener(), this);
|
||||
pm.getServer().getPluginManager().registerEvents(new TheListener(pm), pm);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,13 +83,17 @@ public class PluginMain extends JavaPlugin {
|
||||
* 这里可以注册多个,一般注册一个就够用
|
||||
*/
|
||||
private void registerCommands() {
|
||||
this.getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(new MainCommand());
|
||||
pm.getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(new MainCommand(pm));
|
||||
}
|
||||
|
||||
public ConfigManager getConfigManager() {
|
||||
return cm;
|
||||
}
|
||||
|
||||
public SqlManager getSqlManager() {
|
||||
return sm;
|
||||
}
|
||||
|
||||
private boolean checkPluginDepends() {
|
||||
boolean needDepend = false;
|
||||
for (String name : DEPEND_PLUGIN.split(",")) {
|
||||
@ -99,12 +102,12 @@ public class PluginMain extends JavaPlugin {
|
||||
needDepend = true;
|
||||
}
|
||||
}
|
||||
if (!setupPermissions()) {
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Cann't hook vault permission"));
|
||||
if (!needDepend && !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"));
|
||||
if (!needDepend && !setupDatabase()) {
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "Cann''t setup database"));
|
||||
needDepend = true;
|
||||
}
|
||||
if (needDepend) {
|
||||
@ -116,9 +119,12 @@ public class PluginMain extends JavaPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
getServer().getServicesManager().unregisterAll(this);
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
SqlManager.getDb().close();
|
||||
getServer().getServicesManager().unregisterAll(pm);
|
||||
Bukkit.getScheduler().cancelTasks(pm);
|
||||
try {
|
||||
sm.getDb().close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setupPermissions() {
|
||||
@ -130,7 +136,21 @@ public class PluginMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
private boolean setupDatabase() {
|
||||
sm = SqlManager.getInstance();
|
||||
sm = new SqlManager(pm);
|
||||
return sm.updateDatabase();
|
||||
}
|
||||
|
||||
public UUID getPlayerUUIDByName(String name) {
|
||||
for (Player p : getServer().getOnlinePlayers()) {
|
||||
if (p.getName().equals(name)) {
|
||||
return p.getUniqueId();
|
||||
}
|
||||
}
|
||||
for (OfflinePlayer p : getServer().getOfflinePlayers()) {
|
||||
if (p.getName().equals(name)) {
|
||||
return p.getUniqueId();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,19 @@ import gg.frog.mc.permissionstime.config.PackagesCfg;
|
||||
import gg.frog.mc.permissionstime.config.PluginCfg;
|
||||
import gg.frog.mc.permissionstime.database.SqlManager;
|
||||
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
|
||||
import gg.frog.mc.permissionstime.utils.PluginUtil;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
|
||||
public class GiveCmd {
|
||||
|
||||
private static SqlManager sm = PluginMain.sm;
|
||||
private PluginMain pm;
|
||||
private SqlManager sm;
|
||||
|
||||
public static boolean onCommand(CommandSender sender, boolean isPlayer, String[] args) {
|
||||
public GiveCmd(PluginMain pm) {
|
||||
this.pm = pm;
|
||||
this.sm = pm.getSqlManager();
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, boolean isPlayer, String[] args) {
|
||||
if (args.length == 4) {
|
||||
String playerName = args[1];
|
||||
String packageName = args[2];
|
||||
@ -34,21 +39,21 @@ public class GiveCmd {
|
||||
}
|
||||
PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName);
|
||||
if (pack != null) {
|
||||
UUID uuid = PluginUtil.getPlayerUUIDByName(playerName);
|
||||
UUID uuid = pm.getPlayerUUIDByName(playerName);
|
||||
if (uuid != null) {
|
||||
if (PluginCfg.IS_DEBUG) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + "天"));
|
||||
}
|
||||
if (sm.giveTime(uuid.toString(), packageName, days)) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "给予玩家{0} {1}天的{2}", playerName, time, pack.getDisplayName()));
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "给予玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName()));
|
||||
} else {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未给予玩家{0} {1}天的{2}", playerName, time, pack.getDisplayName()));
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未给予玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName()));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'{0}'的玩家", playerName));
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的玩家", playerName));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'{0}'的权限包", packageName));
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的权限包", packageName));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确"));
|
||||
|
@ -13,12 +13,21 @@ import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
|
||||
public class MainCommand implements CommandExecutor {
|
||||
|
||||
private PluginMain pm = PluginMain.getInstance();
|
||||
private SqlManager sm = PluginMain.sm;
|
||||
private PluginMain pm;
|
||||
private SqlManager sm;
|
||||
private GiveCmd giveCmd;
|
||||
private PackagesCmd packagesCmd;
|
||||
|
||||
public MainCommand(PluginMain pm) {
|
||||
this.pm = pm;
|
||||
this.sm = pm.getSqlManager();
|
||||
giveCmd = new GiveCmd(pm);
|
||||
packagesCmd = new PackagesCmd(pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
|
||||
if (commandLabel.equalsIgnoreCase(PluginMain.PLUGIN_NAME_LOWER_CASE)) {
|
||||
if (commandLabel.equalsIgnoreCase(pm.PLUGIN_NAME_LOWER_CASE)) {
|
||||
boolean isPlayer = false;
|
||||
if (sender instanceof Player) {
|
||||
isPlayer = true;
|
||||
@ -50,23 +59,23 @@ public class MainCommand implements CommandExecutor {
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("me")) {
|
||||
if (hasPermission(sender, isPlayer, "permissionstime.me")) {
|
||||
return GiveCmd.onCommand(sender, isPlayer, args);
|
||||
return giveCmd.onCommand(sender, isPlayer, args);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("give")) {
|
||||
if (hasPermission(sender, isPlayer, "permissionstime.give")) {
|
||||
return GiveCmd.onCommand(sender, isPlayer, args);
|
||||
return giveCmd.onCommand(sender, isPlayer, args);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("set")) {
|
||||
if (hasPermission(sender, isPlayer, "permissionstime.set")) {
|
||||
return GiveCmd.onCommand(sender, isPlayer, args);
|
||||
return giveCmd.onCommand(sender, isPlayer, args);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
||||
if (hasPermission(sender, isPlayer, "permissionstime.remove")) {
|
||||
return GiveCmd.onCommand(sender, isPlayer, args);
|
||||
return giveCmd.onCommand(sender, isPlayer, args);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("packages")) {
|
||||
if (hasPermission(sender, isPlayer, "permissionstime.packages")) {
|
||||
return PackagesCmd.onCommand(sender, isPlayer, args);
|
||||
return packagesCmd.onCommand(sender, isPlayer, args);
|
||||
}
|
||||
} else {
|
||||
getHelp(sender, isPlayer);
|
||||
@ -78,21 +87,21 @@ public class MainCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
private void getHelp(CommandSender sender, boolean isPlayer) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&a===== " + PluginMain.PLUGIN_NAME + " Version:" + PluginMain.PLUGIN_VERSION + " ====="));
|
||||
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".reload")) {
|
||||
sender.sendMessage(StrUtil.messageFormat("/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " reload \n\t-Reloads the config file."));
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&a===== " + pm.PLUGIN_NAME + " Version:" + pm.PLUGIN_VERSION + " ====="));
|
||||
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload")) {
|
||||
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " reload \n -Reloads the config file."));
|
||||
}
|
||||
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".give")) {
|
||||
sender.sendMessage(StrUtil.messageFormat("/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " give <playerName> <packageName> <time> \n\t- Give player package <time>day."));
|
||||
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give")) {
|
||||
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " give <playerName> <packageName> <time> \n - Give player package <time>day."));
|
||||
}
|
||||
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".set")) {
|
||||
sender.sendMessage(StrUtil.messageFormat("/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " set <playerName> <packageName> <time> \n\t- Set player package <time>day."));
|
||||
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".set")) {
|
||||
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " set <playerName> <packageName> <time> \n - Set player package <time>day."));
|
||||
}
|
||||
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".remove")) {
|
||||
sender.sendMessage(StrUtil.messageFormat("/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " remove <playerName> <packageName> \n\t- Remove player package."));
|
||||
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove")) {
|
||||
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " remove <playerName> <packageName> \n - Remove player package."));
|
||||
}
|
||||
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".packages")) {
|
||||
sender.sendMessage(StrUtil.messageFormat("/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " packages [packageName] \n\t- View packages."));
|
||||
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages")) {
|
||||
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " packages [packageName] \n - View packages."));
|
||||
}
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.config.PackagesCfg;
|
||||
import gg.frog.mc.permissionstime.config.PluginCfg;
|
||||
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
|
||||
@ -11,7 +12,13 @@ import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
|
||||
public class PackagesCmd {
|
||||
|
||||
public static boolean onCommand(CommandSender sender, boolean isPlayer, String[] args) {
|
||||
private PluginMain pm;
|
||||
|
||||
public PackagesCmd(PluginMain pm) {
|
||||
this.pm = pm;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, boolean isPlayer, String[] args) {
|
||||
if (args.length == 1) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "共有{0}种权限包", PackagesCfg.PACKAGES.size()));
|
||||
for (Entry<String, PermissionPackageBean> e : PackagesCfg.PACKAGES.entrySet()) {
|
||||
@ -24,7 +31,7 @@ public class PackagesCmd {
|
||||
PermissionPackageBean p = PackagesCfg.PACKAGES.get(packageName);
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "PackgeName: {0}, DisplayName: {1}\n" + "Permissions: {2}\n" + "Groups: {3}\n" + "Prefixs: {4}\n" + "Suffixs: {5}\n" + "", packageName, p.getDisplayName(), p.getPermissions(), p.getGroups(), p.getPrefixs(), p.getSuffixs()));
|
||||
} else {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'{0}'的权限包",packageName));
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的权限包", packageName));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -1,9 +1,7 @@
|
||||
package gg.frog.mc.permissionstime.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -24,25 +22,26 @@ import gg.frog.mc.permissionstime.utils.config.PluginConfig;
|
||||
*
|
||||
*/
|
||||
public class ConfigManager {
|
||||
|
||||
private PluginMain pm = PluginMain.getInstance();
|
||||
|
||||
private PluginMain pm;
|
||||
private Map<String, PluginConfig> cfgMap = new LinkedHashMap<>();
|
||||
|
||||
public ConfigManager() {
|
||||
public ConfigManager(PluginMain pm) {
|
||||
this.pm = pm;
|
||||
File langFolder = new File(pm.getDataFolder(), "lang/");
|
||||
if (!langFolder.exists()) {
|
||||
copyLangFilesFromJar();
|
||||
}
|
||||
// 添加到配置列表
|
||||
cfgMap.put("plugin", new PluginCfg());
|
||||
cfgMap.put("lang", new LangCfg("lang/" + PluginCfg.LANG + ".yml"));
|
||||
cfgMap.put("packages", new PackagesCfg("packages.yml"));
|
||||
cfgMap.put("plugin", new PluginCfg(pm));
|
||||
cfgMap.put("lang", new LangCfg("lang/" + PluginCfg.LANG + ".yml", pm));
|
||||
cfgMap.put("packages", new PackagesCfg("packages.yml", pm));
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
for (Entry<String, PluginConfig> entry : cfgMap.entrySet()) {
|
||||
if ("lang".equals(entry.getKey())) {
|
||||
entry.setValue(new LangCfg("lang/" + PluginCfg.LANG + ".yml"));
|
||||
entry.setValue(new LangCfg("lang/" + PluginCfg.LANG + ".yml", pm));
|
||||
}
|
||||
entry.getValue().reloadConfig();
|
||||
}
|
||||
@ -57,7 +56,7 @@ public class ConfigManager {
|
||||
|
||||
@Override
|
||||
public void process(String fileName, InputStream is) {
|
||||
File f = new File(pm.getDataFolder(),fileName);
|
||||
File f = new File(pm.getDataFolder(), fileName);
|
||||
File parentFolder = f.getParentFile();
|
||||
if (!parentFolder.exists()) {
|
||||
parentFolder.mkdirs();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package gg.frog.mc.permissionstime.config;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.utils.config.PluginConfig;
|
||||
|
||||
/**
|
||||
@ -13,18 +14,17 @@ public class LangCfg extends PluginConfig {
|
||||
public static String NO_PERMISSION = null;
|
||||
public static String CONFIG_RELOADED = null;
|
||||
|
||||
public LangCfg(String fileName) {
|
||||
super(fileName);
|
||||
public LangCfg(String fileName, PluginMain pm) {
|
||||
super(fileName, pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
}
|
||||
protected void init() {}
|
||||
|
||||
@Override
|
||||
protected void loadToDo() {
|
||||
NO_PERMISSION = setGetDefault("nopermission","&4你没有权限这么做");
|
||||
CONFIG_RELOADED = setGetDefault("configReloaded","&a配置重载完成");
|
||||
NO_PERMISSION = setGetDefault("nopermission", "&4你没有权限这么做");
|
||||
CONFIG_RELOADED = setGetDefault("configReloaded", "&a配置重载完成");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
|
||||
import gg.frog.mc.permissionstime.utils.config.PluginConfig;
|
||||
|
||||
@ -13,8 +14,8 @@ public class PackagesCfg extends PluginConfig {
|
||||
public static String DEFAULT_GROUP = null;
|
||||
public static Map<String, PermissionPackageBean> PACKAGES = new HashMap<>();
|
||||
|
||||
public PackagesCfg(String fileName) {
|
||||
super(fileName);
|
||||
public PackagesCfg(String fileName, PluginMain pm) {
|
||||
super(fileName, pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,7 +11,7 @@ import gg.frog.mc.permissionstime.utils.config.PluginConfig;
|
||||
*/
|
||||
public class PluginCfg extends PluginConfig {
|
||||
|
||||
public static String PLUGIN_PREFIX ;
|
||||
public static String PLUGIN_PREFIX;
|
||||
public static boolean IS_METRICS = true;
|
||||
public static boolean IS_DEBUG = false;
|
||||
public static String LANG;
|
||||
@ -23,8 +23,8 @@ public class PluginCfg extends PluginConfig {
|
||||
public static String SQL_PASSWORD;
|
||||
public static String SQL_TABLE_PREFIX;
|
||||
|
||||
public PluginCfg() {
|
||||
super();
|
||||
public PluginCfg(PluginMain pm) {
|
||||
super(pm);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,7 +43,7 @@ public class PluginCfg extends PluginConfig {
|
||||
|
||||
@Override
|
||||
protected void loadToDo() {
|
||||
PLUGIN_PREFIX = setGetDefault("pluginPrefix", "&b[" + PluginMain.PLUGIN_NAME + "]&r");
|
||||
PLUGIN_PREFIX = setGetDefault("pluginPrefix", "&b[" + pm.PLUGIN_NAME + "]&r");
|
||||
IS_DEBUG = setGetDefault("debug", false);
|
||||
IS_METRICS = setGetDefault("metrics", true);
|
||||
LANG = setGetDefault("lang", "zh-cn");
|
||||
|
@ -10,18 +10,15 @@ import lib.PatPeter.SQLibrary.SQLite;
|
||||
|
||||
public class SqlManager {
|
||||
|
||||
private PluginMain pm = PluginMain.getInstance();
|
||||
private static SqlManager sm = new SqlManager();
|
||||
private static Database db = null;
|
||||
private static IPlayerDataService pds = null;
|
||||
private PluginMain pm;
|
||||
private Database db = null;
|
||||
private IPlayerDataService pds = null;
|
||||
|
||||
private SqlManager() {}
|
||||
|
||||
public static SqlManager getInstance() {
|
||||
return sm;
|
||||
public SqlManager(PluginMain pm) {
|
||||
this.pm = pm;
|
||||
}
|
||||
|
||||
public static Database getDb() {
|
||||
public Database getDb() {
|
||||
return db;
|
||||
}
|
||||
|
||||
@ -30,10 +27,10 @@ public class SqlManager {
|
||||
db.close();
|
||||
}
|
||||
if (PluginCfg.USE_MYSQL) {
|
||||
db = new MySQL(PluginMain.LOG, "[" + PluginMain.PLUGIN_NAME + "] ", PluginCfg.SQL_HOSTNAME, PluginCfg.SQL_PORT, PluginCfg.SQL_DATABASE, PluginCfg.SQL_USERNAME, PluginCfg.SQL_PASSWORD);
|
||||
db = new MySQL(PluginMain.LOG, "[" + pm.PLUGIN_NAME + "] ", PluginCfg.SQL_HOSTNAME, PluginCfg.SQL_PORT, PluginCfg.SQL_DATABASE, PluginCfg.SQL_USERNAME, PluginCfg.SQL_PASSWORD);
|
||||
} else {
|
||||
db = new SQLite(PluginMain.LOG, "[" + PluginMain.PLUGIN_NAME + "] ", PluginMain.pm.getDataFolder().getAbsolutePath(), "playerData", ".db");
|
||||
pds = new SqlitePlayerDataService();
|
||||
db = new SQLite(PluginMain.LOG, "[" + pm.PLUGIN_NAME + "] ", pm.getDataFolder().getAbsolutePath(), "playerData", ".db");
|
||||
pds = new SqlitePlayerDataService(pm, this);
|
||||
}
|
||||
db.open();
|
||||
try {
|
||||
|
@ -8,13 +8,19 @@ import java.util.List;
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.config.PluginCfg;
|
||||
import gg.frog.mc.permissionstime.database.IPlayerDataService;
|
||||
import gg.frog.mc.permissionstime.database.SqlManager;
|
||||
import gg.frog.mc.permissionstime.model.db.PlayerDataBean;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
import gg.frog.mc.permissionstime.utils.database.DatabaseUtil;
|
||||
|
||||
public class SqlitePlayerDataService extends DatabaseUtil implements IPlayerDataService {
|
||||
|
||||
private PluginMain pm = PluginMain.getInstance();
|
||||
private PluginMain pm;
|
||||
|
||||
public SqlitePlayerDataService(PluginMain pm, SqlManager sm) {
|
||||
super(sm);
|
||||
this.pm = pm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tableExist() throws Exception {
|
||||
@ -66,8 +72,8 @@ public class SqlitePlayerDataService extends DatabaseUtil implements IPlayerData
|
||||
public boolean addTime(String uuid, String packageName, int days) throws Exception {
|
||||
PlayerDataBean pdb = queryPlayerData(uuid, packageName);
|
||||
long now = new Date().getTime();
|
||||
long addTime = days * 24 * 60 * 60 * 1000;
|
||||
long expire = 0;
|
||||
long addTime = days * 24 * 60 * 60 * 1000L;
|
||||
long expire = 0L;
|
||||
if (pdb == null) {
|
||||
expire = now + addTime;
|
||||
pdb = new PlayerDataBean(null, uuid, packageName, expire);
|
||||
|
@ -9,8 +9,12 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
|
||||
public class TheListener implements Listener {
|
||||
|
||||
private PluginMain pm = PluginMain.getInstance();
|
||||
|
||||
private PluginMain pm;
|
||||
|
||||
public TheListener(PluginMain pm) {
|
||||
this.pm = pm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 一个监听器例子
|
||||
|
@ -1,27 +0,0 @@
|
||||
package gg.frog.mc.permissionstime.utils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
|
||||
public class PluginUtil {
|
||||
|
||||
private static PluginMain pm = PluginMain.getInstance();
|
||||
|
||||
public static UUID getPlayerUUIDByName(String name) {
|
||||
for (Player p : pm.getServer().getOnlinePlayers()) {
|
||||
if (p.getName().equals(name)) {
|
||||
return p.getUniqueId();
|
||||
}
|
||||
}
|
||||
for (OfflinePlayer p : pm.getServer().getOfflinePlayers()) {
|
||||
if (p.getName().equals(name)) {
|
||||
return p.getUniqueId();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -25,22 +25,24 @@ import gg.frog.mc.permissionstime.PluginMain;
|
||||
*/
|
||||
public abstract class PluginConfig {
|
||||
|
||||
private PluginMain pm = PluginMain.getInstance();
|
||||
protected PluginMain pm;
|
||||
private FileConfiguration config = null;
|
||||
private File folder = null;
|
||||
private String fileName = null;
|
||||
private File configFile = null;
|
||||
|
||||
|
||||
protected PluginConfig() {
|
||||
protected PluginConfig(PluginMain pm) {
|
||||
this.pm = pm;
|
||||
initConfig(pm.getDataFolder(), "config.yml");
|
||||
}
|
||||
|
||||
protected PluginConfig(String fileName) {
|
||||
protected PluginConfig(String fileName, PluginMain pm) {
|
||||
this.pm = pm;
|
||||
initConfig(pm.getDataFolder(), fileName);
|
||||
}
|
||||
|
||||
protected PluginConfig(File folder, String fileName) {
|
||||
protected PluginConfig(File folder, String fileName, PluginMain pm) {
|
||||
this.pm = pm;
|
||||
initConfig(folder, fileName);
|
||||
}
|
||||
|
||||
@ -128,7 +130,7 @@ public abstract class PluginConfig {
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
if (useRes) {
|
||||
final InputStream defConfigStream = PluginMain.getInstance().getResource(fileName);
|
||||
final InputStream defConfigStream = pm.getResource(fileName);
|
||||
if (defConfigStream == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -5,8 +5,14 @@ import lib.PatPeter.SQLibrary.Database;
|
||||
|
||||
public abstract class DatabaseUtil {
|
||||
|
||||
private SqlManager sm;
|
||||
|
||||
public DatabaseUtil(SqlManager sm) {
|
||||
this.sm = sm;
|
||||
}
|
||||
|
||||
protected Database getDB() {
|
||||
Database db = SqlManager.getDb();
|
||||
Database db = sm.getDb();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!db.isOpen()) {
|
||||
if (db.open()) {
|
||||
|
Loading…
Reference in New Issue
Block a user