diff --git a/pom.xml b/pom.xml index a0f6cb7..c3492be 100644 --- a/pom.xml +++ b/pom.xml @@ -34,10 +34,14 @@ bstats-repo http://repo.bstats.org/content/repositories/releases/ - - placeholderapi - http://repo.extendedclip.com/content/repositories/placeholderapi/ - + + placeholderapi + http://repo.extendedclip.com/content/repositories/placeholderapi/ + + + filoghost-repo + https://ci.filoghost.me/plugin/repository/everything/ + @@ -58,17 +62,23 @@ 1.6 provided - - me.clip - placeholderapi - 2.0.8 - provided - + + me.clip + placeholderapi + LATEST + provided + lib.PatPeter.SQLibrary SQLibrary 7.1 + + com.gmail.filoghost.holographicdisplays + holographicdisplays-api + 2.2.7-SNAPSHOT + provided + PermissionsTime-${project.version} diff --git a/src/main/gg/frog/mc/permissionstime/PluginMain.java b/src/main/gg/frog/mc/permissionstime/PluginMain.java index f2c8fbd..febaa58 100644 --- a/src/main/gg/frog/mc/permissionstime/PluginMain.java +++ b/src/main/gg/frog/mc/permissionstime/PluginMain.java @@ -2,7 +2,8 @@ package gg.frog.mc.permissionstime; import java.text.MessageFormat; import java.util.Locale; -import java.util.UUID; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; import org.bstats.bukkit.Metrics; @@ -16,182 +17,196 @@ import gg.frog.mc.permissionstime.config.ConfigManager; import gg.frog.mc.permissionstime.config.PluginCfg; import gg.frog.mc.permissionstime.database.SqlManager; import gg.frog.mc.permissionstime.listener.MainListener; +import gg.frog.mc.permissionstime.placeholder.TagPlaceholder; import gg.frog.mc.permissionstime.utils.FileUtil; import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.UpdateCheck; -import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; public class PluginMain extends JavaPlugin { - public String PLUGIN_NAME; - public String PLUGIN_VERSION; - public String PLUGIN_NAME_LOWER_CASE; - public static final String DEPEND_PLUGIN = "SQLibrary,Vault"; - public static final Logger LOG = Logger.getLogger("Minecraft"); + public String PLUGIN_NAME; + public String PLUGIN_VERSION; + public String PLUGIN_NAME_LOWER_CASE; + public static final String DEPEND_PLUGIN = "SQLibrary,Vault"; + public static final Logger LOG = Logger.getLogger("Minecraft"); - private ConfigManager cm = null; - private PluginMain pm = null; - private SqlManager sm = null; - private Permission permission = null; - private Chat chat = null; + private ConfigManager cm = null; + private PluginMain pm = null; + private SqlManager sm = null; + private Permission permission = null; + public static boolean enabledHdPlugin; + public static boolean enabledPlaceholder; + private static Map playerMap = new ConcurrentHashMap<>(); - public PluginMain() { - PLUGIN_NAME = getDescription().getName(); - PLUGIN_VERSION = getDescription().getVersion(); - PLUGIN_NAME_LOWER_CASE = PLUGIN_NAME.toLowerCase(Locale.ENGLISH); - } + public PluginMain() { + PLUGIN_NAME = getDescription().getName(); + PLUGIN_VERSION = getDescription().getVersion(); + PLUGIN_NAME_LOWER_CASE = PLUGIN_NAME.toLowerCase(Locale.ENGLISH); + } - @Override - public void onEnable() { - pm = this; - 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 + " " + 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 + "===============================")); - getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void onEnable() { + pm = this; + 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 + " " + 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 + "===============================")); + getServer().getScheduler().runTask(pm, new Runnable() { public void run() { - if (!checkPluginDepends()) { - getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Startup failure!")); - getServer().getPluginManager().disablePlugin(pm); - } else { - registerListeners(); - registerCommands(); - getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&2Startup successful!")); - } - if (PluginCfg.IS_METRICS) { - try { - new Metrics(pm); - } catch (Exception e) { - e.printStackTrace(); - } - } - getServer().getScheduler().runTaskAsynchronously(pm, new UpdateCheck(pm)); - } - }); - } + if (!checkPluginDepends()) { + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Startup failure!")); + getServer().getPluginManager().disablePlugin(pm); + } else { + registerListeners(); + registerCommands(); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&2Startup successful!")); + } + if (PluginCfg.IS_METRICS) { + try { + new Metrics(pm); + } catch (Exception e) { + e.printStackTrace(); + } + } + getServer().getScheduler().runTaskAsynchronously(pm, new UpdateCheck(pm)); + } + }); + } - /** - * 注册监听器
- * 这里可以注册多个 - */ - private void registerListeners() { - pm.getServer().getPluginManager().registerEvents(new MainListener(pm), pm); - } + /** + * 注册监听器
+ * 这里可以注册多个 + */ + private void registerListeners() { + pm.getServer().getPluginManager().registerEvents(new MainListener(pm), pm); + } - /** - * 注册命令
- * 这里可以注册多个,一般注册一个就够用 - */ - private void registerCommands() { - MainCommand mcmd = new MainCommand(pm); - if (getDescription().getCommands().containsKey(PLUGIN_NAME_LOWER_CASE)) { - getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(mcmd); - } - if (getDescription().getCommands().containsKey("pt")) { - getCommand("pt").setExecutor(mcmd); - } - } + /** + * 注册命令
+ * 这里可以注册多个,一般注册一个就够用 + */ + private void registerCommands() { + MainCommand mcmd = new MainCommand(pm); + if (getDescription().getCommands().containsKey(PLUGIN_NAME_LOWER_CASE)) { + getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(mcmd); + } + if (getDescription().getCommands().containsKey("pt")) { + getCommand("pt").setExecutor(mcmd); + } + } - public ConfigManager getConfigManager() { - return cm; - } + public ConfigManager getConfigManager() { + return cm; + } - public SqlManager getSqlManager() { - return sm; - } + public SqlManager getSqlManager() { + return sm; + } - public Permission getPermission() { - return permission; - } - - public Chat getChat() { - return chat; + public Permission getPermission() { + return permission; } private boolean checkPluginDepends() { - boolean needDepend = false; - for (String name : DEPEND_PLUGIN.split(",")) { - if (getServer().getPluginManager().getPlugin(name) == null) { - getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Need depend plugins : " + name)); - needDepend = true; - } - } - if (!needDepend && !setupPermissions()) { - getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook vault permission")); - needDepend = true; - } - if (!needDepend && !setupChat()) { - getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook vault chat")); - needDepend = true; - } - if (!needDepend && !setupDatabase()) { - getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t setup database")); - needDepend = true; - } - if (needDepend) { - return false; - } - return true; - } + boolean needDepend = false; + for (String name : DEPEND_PLUGIN.split(",")) { + if (!getServer().getPluginManager().isPluginEnabled(name)) { + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Need depend plugins : " + name + ".")); + needDepend = true; + } + } + if (!needDepend && !setupPermissions()) { + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook vault permission.")); + needDepend = true; + } + if (!needDepend && !setupDatabase()) { + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t setup database.")); + needDepend = true; + } + enabledPlaceholder = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"); + if (!enabledPlaceholder) { + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&ePlaceholder is not installed or not enabled.")); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&eSome func will be disabled.")); + } else { + boolean placeholdersHook = false; + try { + placeholdersHook = new TagPlaceholder(pm).register(); + } catch (Exception e) { - @Override - public void onDisable() { - getServer().getServicesManager().unregisterAll(pm); - Bukkit.getScheduler().cancelTasks(pm); - try { - sm.getDb().close(); - } catch (Exception e) { - } - } + } + if (!placeholdersHook) { + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook placeholders")); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4The placeholders '%permissionstime_displayname%' Cann''t use.")); + } + } + enabledHdPlugin = Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays"); + if (!enabledHdPlugin) { + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&eHolographicDisplays is not installed or not enabled.")); + getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&eSome func will be disabled.")); + } - private boolean setupPermissions() { - RegisteredServiceProvider permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); - if (permissionProvider != null) { - permission = permissionProvider.getProvider(); - } - return (permission != null); - } + if (needDepend) { + return false; + } + return true; + } - private boolean setupChat() { - RegisteredServiceProvider chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class); - if (chatProvider != null) { - chat = chatProvider.getProvider(); - } - return (chat != null); - } + @Override + public void onDisable() { + getServer().getServicesManager().unregisterAll(pm); + Bukkit.getScheduler().cancelTasks(pm); + try { + sm.getDb().close(); + } catch (Exception e) { + } + } - private boolean setupDatabase() { - sm = new SqlManager(pm); - return sm.updateDatabase(); - } + private boolean setupPermissions() { + RegisteredServiceProvider permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); + if (permissionProvider != null) { + permission = permissionProvider.getProvider(); + } + return (permission != null); + } - public UUID getPlayerUUIDByName(String name) { - OfflinePlayer p = getOfflinePlayer(name); - if (p == null) { - return null; - } else { - return p.getUniqueId(); - } - } + private boolean setupDatabase() { + sm = new SqlManager(pm); + return sm.updateDatabase(); + } - public OfflinePlayer getOfflinePlayer(String name) { - for (OfflinePlayer p : getServer().getOfflinePlayers()) { - if(p==null) - continue; - if (p.getName().equalsIgnoreCase(name)) { - return p; - } - } - return null; - } + public String getPlayerUUIDByName(String name) { + OfflinePlayer p = getOfflinePlayer(name); + if (p == null) { + return null; + } else { + return p.getUniqueId().toString(); + } + } - public void writeFailLog(String content, Object... args) { - FileUtil.writeOnFile(getDataFolder() + "/failure.log", "[" + StrUtil.nowTimeString() + "] " + MessageFormat.format(content, args)); - } + public OfflinePlayer getOfflinePlayer(String name) { + if (name != null) { + OfflinePlayer p1 = playerMap.get(name); + if (p1 != null) + return p1; + for (OfflinePlayer p2 : getServer().getOfflinePlayers()) { + if (p2 == null) + continue; + if (p2.getName().equalsIgnoreCase(name)) { + playerMap.put(name, p2); + return p2; + } + } + } + return null; + } + + public void writeFailLog(String content, Object... args) { + FileUtil.writeOnFile(getDataFolder() + "/failure.log", "[" + StrUtil.nowTimeString() + "] " + MessageFormat.format(content, args)); + } } diff --git a/src/main/gg/frog/mc/permissionstime/command/GetCmd.java b/src/main/gg/frog/mc/permissionstime/command/GetCmd.java index 4113889..ce8ef0b 100644 --- a/src/main/gg/frog/mc/permissionstime/command/GetCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/GetCmd.java @@ -2,7 +2,6 @@ package gg.frog.mc.permissionstime.command; import java.util.List; -import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import gg.frog.mc.permissionstime.PluginMain; @@ -32,9 +31,9 @@ public class GetCmd implements Runnable { public void run() { if (args.length == 2) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); - OfflinePlayer p = pm.getOfflinePlayer(args[1]); - if (p != null) { - List ps = sm.getTime(p.getUniqueId().toString()); + String uuid = pm.getPlayerUUIDByName(args[1]); + if (uuid != null) { + List ps = sm.getTime(uuid); if (ps.size() > 0) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NUM_OF_PACKAGES, args[1], ps.size())); diff --git a/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java b/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java index c61a5d1..e210d2f 100644 --- a/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java @@ -1,7 +1,6 @@ package gg.frog.mc.permissionstime.command; import java.util.List; -import java.util.UUID; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -18,90 +17,90 @@ import gg.frog.mc.permissionstime.utils.StrUtil; public class GiveCmd implements Runnable { - private PluginMain pm; - private SqlManager sm; - private String[] args; - private CommandSender sender; + private PluginMain pm; + private SqlManager sm; + private String[] args; + private CommandSender sender; - public GiveCmd(PluginMain pm, CommandSender sender, String[] args) { - this.pm = pm; - this.sm = pm.getSqlManager(); - this.sender = sender; - this.args = args; - } + public GiveCmd(PluginMain pm, CommandSender sender, String[] args) { + this.pm = pm; + this.sm = pm.getSqlManager(); + this.sender = sender; + this.args = args; + } - @Override - public void run() { - if (args.length == 5) { - String playerName = args[1]; - String packageName = args[2]; - String time = args[3]; - String unit = args[4]; - final String unitName; - int minutes = 0; - try { - minutes = Integer.parseInt(time); - if (minutes == 0) { - throw new RuntimeException("not a nonzero integer."); - } - } catch (Exception e) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_PARAMETER_INCORRECT)); - sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE)); - return; - } - if ("d".equalsIgnoreCase(unit)) { - minutes *= 24 * 60; - unitName = LangCfg.TIME_UNIT_D; - } else if ("h".equalsIgnoreCase(unit)) { - minutes *= 60; - unitName = LangCfg.TIME_UNIT_H; - } else if ("m".equalsIgnoreCase(unit)) { - unitName = LangCfg.TIME_UNIT_M; - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_UNIT_PARAMETER_INCORRECT)); - sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE)); - return; - } - PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); - if (pack != null) { - OfflinePlayer player = pm.getOfflinePlayer(playerName); - if (player != null) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); - UUID uuid = player.getUniqueId(); - if (PluginCfg.IS_DEBUG) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + unitName + ".")); - } - if (sm.giveTime(((PluginCfg.USE_MYSQL && pack.getGlobal()) ? "g:" : "") + uuid.toString(), packageName, minutes)) { - if (player.isOnline()) { - Player p = player.getPlayer(); - try { - List pdbList = sm.getTime(player.getUniqueId().toString()); - PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); - } catch (Exception e) { - e.printStackTrace(); - p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); - } - p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_GIVE_PACKAGE, sender.getName(), time + unitName, pack.getDisplayName())); - } - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE, playerName, time + unitName, pack.getDisplayName())); - } else { - pm.getServer().getScheduler().runTask(pm, new Runnable() { - @Override - public void run() { - pm.writeFailLog("Command execution failed. Give {0}({1}) {2} {3} Executor: {4}", playerName, player.getUniqueId().toString(), time + unitName, pack.getDisplayName(), sender.getName()); - } - }); - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE_FAIL, playerName, time + unitName, pack.getDisplayName())); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName)); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); - sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE)); - } - } + @Override + public void run() { + if (args.length == 5) { + String playerName = args[1]; + String packageName = args[2]; + String time = args[3]; + String unit = args[4]; + final String unitName; + int minutes = 0; + try { + minutes = Integer.parseInt(time); + if (minutes == 0) { + throw new RuntimeException("not a nonzero integer."); + } + } catch (Exception e) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_PARAMETER_INCORRECT)); + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE)); + return; + } + if ("d".equalsIgnoreCase(unit)) { + minutes *= 24 * 60; + unitName = LangCfg.TIME_UNIT_D; + } else if ("h".equalsIgnoreCase(unit)) { + minutes *= 60; + unitName = LangCfg.TIME_UNIT_H; + } else if ("m".equalsIgnoreCase(unit)) { + unitName = LangCfg.TIME_UNIT_M; + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_UNIT_PARAMETER_INCORRECT)); + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE)); + return; + } + PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); + if (pack != null) { + OfflinePlayer player = pm.getOfflinePlayer(playerName); + if (player != null) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); + String uuid = player.getUniqueId().toString(); + if (PluginCfg.IS_DEBUG) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid + "\n" + pack.toString() + "\n" + time + unitName + ".")); + } + if (sm.giveTime(((PluginCfg.USE_MYSQL && pack.getGlobal()) ? "g:" : "") + uuid, packageName, minutes)) { + if (player.isOnline()) { + Player p = player.getPlayer(); + try { + List pdbList = sm.getTime(uuid); + PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); + } + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_GIVE_PACKAGE, sender.getName(), time + unitName, pack.getDisplayName())); + } + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE, playerName, time + unitName, pack.getDisplayName())); + } else { + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + pm.writeFailLog("Command execution failed. Give {0}({1}) {2} {3} Executor: {4}", playerName, uuid, time + unitName, pack.getDisplayName(), sender.getName()); + } + }); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE_FAIL, playerName, time + unitName, pack.getDisplayName())); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE)); + } + } } diff --git a/src/main/gg/frog/mc/permissionstime/command/MeCmd.java b/src/main/gg/frog/mc/permissionstime/command/MeCmd.java index e178eee..b4b97a8 100644 --- a/src/main/gg/frog/mc/permissionstime/command/MeCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/MeCmd.java @@ -2,7 +2,6 @@ package gg.frog.mc.permissionstime.command; import java.util.List; -import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,34 +15,34 @@ import gg.frog.mc.permissionstime.utils.StrUtil; public class MeCmd implements Runnable { - private PluginMain pm; - private SqlManager sm; - private String[] args; - private CommandSender sender; - private boolean isPlayer; + private PluginMain pm; + private SqlManager sm; + private String[] args; + private CommandSender sender; + private boolean isPlayer; - public MeCmd(PluginMain pm, CommandSender sender, boolean isPlayer, String[] args) { - this.pm = pm; - this.sm = pm.getSqlManager(); - this.sender = sender; - this.isPlayer = isPlayer; - this.args = args; - } + public MeCmd(PluginMain pm, CommandSender sender, boolean isPlayer, String[] args) { + this.pm = pm; + this.sm = pm.getSqlManager(); + this.sender = sender; + this.isPlayer = isPlayer; + this.args = args; + } - @Override - public void run() { - if (isPlayer) { - if (args.length == 1) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); - OfflinePlayer p = this.pm.getOfflinePlayer(sender.getName()); - List ps = sm.getTime(p.getUniqueId().toString()); - PlayerPermissionShow.show((Player) sender, ps); - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); - sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_ME, pm.PLUGIN_NAME_LOWER_CASE)); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Only player can use this command.")); - } - } + @Override + public void run() { + if (isPlayer) { + if (args.length == 1) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); + String uuid = pm.getPlayerUUIDByName(sender.getName()); + List ps = sm.getTime(uuid); + PlayerPermissionShow.show((Player) sender, ps); + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_ME, pm.PLUGIN_NAME_LOWER_CASE)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Only player can use this command.")); + } + } } diff --git a/src/main/gg/frog/mc/permissionstime/command/RemoveAllCmd.java b/src/main/gg/frog/mc/permissionstime/command/RemoveAllCmd.java index 62da176..46375ef 100644 --- a/src/main/gg/frog/mc/permissionstime/command/RemoveAllCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/RemoveAllCmd.java @@ -1,7 +1,6 @@ package gg.frog.mc.permissionstime.command; import java.util.List; -import java.util.UUID; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -17,61 +16,61 @@ import gg.frog.mc.permissionstime.utils.StrUtil; public class RemoveAllCmd implements Runnable { - private PluginMain pm; - private SqlManager sm; - private String[] args; - private CommandSender sender; + private PluginMain pm; + private SqlManager sm; + private String[] args; + private CommandSender sender; - public RemoveAllCmd(PluginMain pm, CommandSender sender, String[] args) { - this.pm = pm; - this.sm = pm.getSqlManager(); - this.sender = sender; - this.args = args; - } + public RemoveAllCmd(PluginMain pm, CommandSender sender, String[] args) { + this.pm = pm; + this.sm = pm.getSqlManager(); + this.sender = sender; + this.args = args; + } - @Override - public void run() { - if (args.length == 2 || args.length == 3) { - String playerName = args[1]; - boolean delGlobal = false; - if (args.length == 3 && "t".equalsIgnoreCase(args[2]) && PluginCfg.USE_MYSQL) { - delGlobal = true; - } - OfflinePlayer player = pm.getOfflinePlayer(playerName); - if (player != null) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); - UUID uuid = player.getUniqueId(); - if (PluginCfg.IS_DEBUG) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString())); - } - if (sm.removeAllTime((delGlobal ? "g:" : "") + uuid.toString())) { - if (player.isOnline()) { - Player p = player.getPlayer(); - try { - List pdbList = sm.getTime(player.getUniqueId().toString()); - PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); - } catch (Exception e) { - e.printStackTrace(); - p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); - } - p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_DEL_ALL, sender.getName())); - } - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_ALL, playerName)); - } else { - pm.getServer().getScheduler().runTask(pm, new Runnable() { - @Override - public void run() { - pm.writeFailLog("Command execution failed. Delete {0}({1})'s all packages. Executor: {2}", playerName, player.getUniqueId().toString(), sender.getName()); - } - }); - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_ALL_FAIL, playerName)); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); - sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVEALL, pm.PLUGIN_NAME_LOWER_CASE)); - } - } + @Override + public void run() { + if (args.length == 2 || args.length == 3) { + String playerName = args[1]; + boolean delGlobal = false; + if (args.length == 3 && "t".equalsIgnoreCase(args[2]) && PluginCfg.USE_MYSQL) { + delGlobal = true; + } + OfflinePlayer player = pm.getOfflinePlayer(playerName); + if (player != null) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); + String uuid = player.getUniqueId().toString(); + if (PluginCfg.IS_DEBUG) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid)); + } + if (sm.removeAllTime((delGlobal ? "g:" : "") + uuid)) { + if (player.isOnline()) { + Player p = player.getPlayer(); + try { + List pdbList = sm.getTime(uuid); + PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); + } + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_DEL_ALL, sender.getName())); + } + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_ALL, playerName)); + } else { + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + pm.writeFailLog("Command execution failed. Delete {0}({1})'s all packages. Executor: {2}", playerName, uuid, sender.getName()); + } + }); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_ALL_FAIL, playerName)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVEALL, pm.PLUGIN_NAME_LOWER_CASE)); + } + } } diff --git a/src/main/gg/frog/mc/permissionstime/command/RemoveCmd.java b/src/main/gg/frog/mc/permissionstime/command/RemoveCmd.java index 2a8f8bd..4f71eb8 100644 --- a/src/main/gg/frog/mc/permissionstime/command/RemoveCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/RemoveCmd.java @@ -1,7 +1,6 @@ package gg.frog.mc.permissionstime.command; import java.util.List; -import java.util.UUID; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -18,67 +17,67 @@ import gg.frog.mc.permissionstime.utils.StrUtil; public class RemoveCmd implements Runnable { - private PluginMain pm; - private SqlManager sm; - private String[] args; - private CommandSender sender; + private PluginMain pm; + private SqlManager sm; + private String[] args; + private CommandSender sender; - public RemoveCmd(PluginMain pm, CommandSender sender, String[] args) { - this.pm = pm; - this.sm = pm.getSqlManager(); - this.sender = sender; - this.args = args; - } + public RemoveCmd(PluginMain pm, CommandSender sender, String[] args) { + this.pm = pm; + this.sm = pm.getSqlManager(); + this.sender = sender; + this.args = args; + } - @Override - public void run() { - if (args.length == 3 || args.length == 4) { - String playerName = args[1]; - String packageName = args[2]; - boolean delGlobal = false; - if (args.length == 4 && "t".equalsIgnoreCase(args[3]) && PluginCfg.USE_MYSQL) { - delGlobal = true; - } - PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); - if (pack != null) { - OfflinePlayer player = pm.getOfflinePlayer(playerName); - if (player != null) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); - UUID uuid = player.getUniqueId(); - if (PluginCfg.IS_DEBUG) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString())); - } - if (sm.removeTime((delGlobal ? "g:" : "") + uuid.toString(), packageName)) { - if (player.isOnline()) { - Player p = player.getPlayer(); - try { - List pdbList = sm.getTime(player.getUniqueId().toString()); - PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); - } catch (Exception e) { - e.printStackTrace(); - p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); - } - p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_DEL_PACKAGE, sender.getName(), pack.getDisplayName())); - } - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_PACKAGE, playerName, pack.getDisplayName())); - } else { - pm.getServer().getScheduler().runTask(pm, new Runnable() { - @Override - public void run() { - pm.writeFailLog("Command execution failed. Delete {0}({1})'s packages which be named {2} Executor: {3}", playerName, player.getUniqueId().toString(), pack.getDisplayName(), sender.getName()); - } - }); - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_PACKAGE_FAIL, playerName, pack.getDisplayName())); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName)); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); - sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVE, pm.PLUGIN_NAME_LOWER_CASE)); - } - } + @Override + public void run() { + if (args.length == 3 || args.length == 4) { + String playerName = args[1]; + String packageName = args[2]; + boolean delGlobal = false; + if (args.length == 4 && "t".equalsIgnoreCase(args[3]) && PluginCfg.USE_MYSQL) { + delGlobal = true; + } + PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); + if (pack != null) { + OfflinePlayer player = pm.getOfflinePlayer(playerName); + if (player != null) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); + String uuid = player.getUniqueId().toString(); + if (PluginCfg.IS_DEBUG) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid + "\n" + pack.toString())); + } + if (sm.removeTime((delGlobal ? "g:" : "") + uuid, packageName)) { + if (player.isOnline()) { + Player p = player.getPlayer(); + try { + List pdbList = sm.getTime(uuid); + PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); + } + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_DEL_PACKAGE, sender.getName(), pack.getDisplayName())); + } + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_PACKAGE, playerName, pack.getDisplayName())); + } else { + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + pm.writeFailLog("Command execution failed. Delete {0}({1})'s packages which be named {2} Executor: {3}", playerName, uuid, pack.getDisplayName(), sender.getName()); + } + }); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_PACKAGE_FAIL, playerName, pack.getDisplayName())); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVE, pm.PLUGIN_NAME_LOWER_CASE)); + } + } } diff --git a/src/main/gg/frog/mc/permissionstime/command/SetCmd.java b/src/main/gg/frog/mc/permissionstime/command/SetCmd.java index 5463fa5..ff1dcd4 100644 --- a/src/main/gg/frog/mc/permissionstime/command/SetCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/SetCmd.java @@ -1,7 +1,6 @@ package gg.frog.mc.permissionstime.command; import java.util.List; -import java.util.UUID; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -18,90 +17,93 @@ import gg.frog.mc.permissionstime.utils.StrUtil; public class SetCmd implements Runnable { - private PluginMain pm; - private SqlManager sm; - private String[] args; - private CommandSender sender; + private PluginMain pm; + private SqlManager sm; + private String[] args; + private CommandSender sender; - public SetCmd(PluginMain pm, CommandSender sender, String[] args) { - this.pm = pm; - this.sm = pm.getSqlManager(); - this.sender = sender; - this.args = args; - } + public SetCmd(PluginMain pm, CommandSender sender, String[] args) { + this.pm = pm; + this.sm = pm.getSqlManager(); + this.sender = sender; + this.args = args; + } - @Override - public void run() { - if (args.length == 5) { - String playerName = args[1]; - String packageName = args[2]; - String time = args[3]; - String unit = args[4]; - final String unitName; - int minutes = 0; - try { - minutes = Integer.parseInt(time); - if (minutes == 0) { - throw new RuntimeException("not a nonzero integer."); - } - } catch (Exception e) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_PARAMETER_INCORRECT)); - sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE)); - return; - } - if ("d".equalsIgnoreCase(unit)) { - minutes *= 24 * 60; - unitName = LangCfg.TIME_UNIT_D; - } else if ("h".equalsIgnoreCase(unit)) { - minutes *= 60; - unitName = LangCfg.TIME_UNIT_H; - } else if ("m".equalsIgnoreCase(unit)) { - unitName = LangCfg.TIME_UNIT_M; - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_UNIT_PARAMETER_INCORRECT)); - sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE)); - return; - } - PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); - if (pack != null) { - OfflinePlayer player = pm.getOfflinePlayer(playerName); - if (player != null) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); - UUID uuid = player.getUniqueId(); - if (PluginCfg.IS_DEBUG) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + unitName + " .")); - } - if (sm.setTime(((PluginCfg.USE_MYSQL && pack.getGlobal()) ? "g:" : "") + uuid.toString(), packageName, minutes)) { - if (player.isOnline()) { - Player p = player.getPlayer(); - try { - List pdbList = sm.getTime(player.getUniqueId().toString()); - PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); - } catch (Exception e) { - e.printStackTrace(); - p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); - } - p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_SET_PACKAGE, sender.getName(), time + unitName, pack.getDisplayName())); - } - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_SET_PACKAGE, playerName, time + unitName, pack.getDisplayName())); - } else { - pm.getServer().getScheduler().runTask(pm, new Runnable() { - @Override - public void run() { - pm.writeFailLog("Command execution failed. Set {0}({1}) {2} {3} Executor: {4}", playerName, player.getUniqueId().toString(), time + unitName, pack.getDisplayName(), sender.getName()); - } - }); - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_SET_PACKAGE_FAIL, playerName, time + unitName, pack.getDisplayName())); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName)); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); - sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE)); - } - } + @Override + public void run() { + if (args.length == 5) { + String playerName = args[1]; + String packageName = args[2]; + String time = args[3]; + String unit = args[4]; + final String unitName; + int minutes = 0; + try { + minutes = Integer.parseInt(time); + if (minutes == 0) { + throw new RuntimeException("not a nonzero integer."); + } + } catch (Exception e) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_PARAMETER_INCORRECT)); + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE)); + return; + } + if ("d".equalsIgnoreCase(unit)) { + minutes *= 24 * 60; + unitName = LangCfg.TIME_UNIT_D; + } else if ("h".equalsIgnoreCase(unit)) { + minutes *= 60; + unitName = LangCfg.TIME_UNIT_H; + } else if ("m".equalsIgnoreCase(unit)) { + unitName = LangCfg.TIME_UNIT_M; + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_UNIT_PARAMETER_INCORRECT)); + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE)); + return; + } + PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); + if (pack != null) { + OfflinePlayer player = pm.getOfflinePlayer(playerName); + if (player != null) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); + String uuid = player.getUniqueId().toString(); + if (PluginCfg.IS_DEBUG) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid + "\n" + pack.toString() + "\n" + time + unitName + " .")); + } + if (sm.setTime(((PluginCfg.USE_MYSQL && pack.getGlobal()) ? "g:" : "") + uuid, packageName, minutes)) { + if (player.isOnline()) { + Player p = player.getPlayer(); + if (p != null) { + try { + List pdbList = sm.getTime(uuid); + PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); + } catch (Exception e) { + e.printStackTrace(); + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); + } + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_SET_PACKAGE, sender.getName(), time + unitName, pack.getDisplayName())); + } + + } + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_SET_PACKAGE, playerName, time + unitName, pack.getDisplayName())); + } else { + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + pm.writeFailLog("Command execution failed. Set {0}({1}) {2} {3} Executor: {4}", playerName, uuid, time + unitName, pack.getDisplayName(), sender.getName()); + } + }); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_SET_PACKAGE_FAIL, playerName, time + unitName, pack.getDisplayName())); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); + sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE)); + } + } } diff --git a/src/main/gg/frog/mc/permissionstime/command/TagCmd.java b/src/main/gg/frog/mc/permissionstime/command/TagCmd.java index 0cba439..e1a94ad 100644 --- a/src/main/gg/frog/mc/permissionstime/command/TagCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/TagCmd.java @@ -6,6 +6,7 @@ import java.util.Map; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import gg.frog.mc.permissionstime.PluginMain; @@ -58,7 +59,10 @@ public class TagCmd implements Runnable { } } OfflinePlayer player = pm.getOfflinePlayer(sender.getName()); - PlayerTagShow.show(player.getPlayer(), type, itemList); + Player p = player.getPlayer(); + if (p != null) { + PlayerTagShow.show(p, type, itemList); + } } else { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE)); diff --git a/src/main/gg/frog/mc/permissionstime/config/LangCfg.java b/src/main/gg/frog/mc/permissionstime/config/LangCfg.java index 9b71135..4828bdc 100644 --- a/src/main/gg/frog/mc/permissionstime/config/LangCfg.java +++ b/src/main/gg/frog/mc/permissionstime/config/LangCfg.java @@ -11,119 +11,122 @@ import gg.frog.mc.permissionstime.utils.config.PluginConfig; */ public class LangCfg extends PluginConfig { - public static String INVENTORY_NAME = null; - public static String TAG_INVENTORY_NAME = null; - public static String EXPIRATION_TIME = null; - public static String LEFT_TIME = null; - public static String TIME_UNIT_D = null; - public static String TIME_UNIT_H = null; - public static String TIME_UNIT_M = null; - public static String TIME_FOREVER = null; - public static String TAG = null; + public static String INVENTORY_NAME = null; + public static String TAG_INVENTORY_NAME = null; + public static String EXPIRATION_TIME = null; + public static String LEFT_TIME = null; + public static String TIME_UNIT_D = null; + public static String TIME_UNIT_H = null; + public static String TIME_UNIT_M = null; + public static String TIME_FOREVER = null; + public static String TAG = null; - public static String MSG_PARAMETER_MISMATCH = null; - public static String MSG_TIME_PARAMETER_INCORRECT = null; - public static String MSG_TIME_UNIT_PARAMETER_INCORRECT = null; - public static String MSG_PROCESSING = null; - public static String MSG_NO_DATA = null; - public static String MSG_PACKAGE_NUM = null; - public static String MSG_PACKAGE_LIST = null; - public static String MSG_PACKAGE_DETAIL = null; - public static String MSG_NO_PERMISSION = null; - public static String MSG_CONFIG_RELOADED = null; - public static String MSG_FAIL_SET_PERMISSION = null; - public static String MSG_NO_FIND_PLAYER = null; - public static String MSG_NO_FIND_PACKAGE = null; - public static String MSG_TELL_GIVE_PACKAGE = null; - public static String MSG_GIVE_PACKAGE = null; - public static String MSG_GIVE_PACKAGE_FAIL = null; - public static String MSG_TELL_SET_PACKAGE = null; - public static String MSG_SET_PACKAGE = null; - public static String MSG_SET_PACKAGE_FAIL = null; - public static String MSG_TELL_DEL_PACKAGE = null; - public static String MSG_DEL_PACKAGE = null; - public static String MSG_DEL_PACKAGE_FAIL = null; - public static String MSG_TELL_DEL_ALL = null; - public static String MSG_DEL_ALL = null; - public static String MSG_DEL_ALL_FAIL = null; - public static String MSG_NUM_OF_PACKAGES = null; - public static String MSG_EXPIRATION_DATE = null; - public static String MSG_UNKNOWN_PACKAGE = null; - public static String MSG_IS_EXPIRATION_DATE = null; - public static String MSG_FUNC_DISABLED = null; - public static String MSG_TAG_SET_SUCCESS = null; + public static String MSG_PARAMETER_MISMATCH = null; + public static String MSG_TIME_PARAMETER_INCORRECT = null; + public static String MSG_TIME_UNIT_PARAMETER_INCORRECT = null; + public static String MSG_PROCESSING = null; + public static String MSG_NO_DATA = null; + public static String MSG_NO_TAG_DATA = null; + public static String MSG_PACKAGE_NUM = null; + public static String MSG_PACKAGE_LIST = null; + public static String MSG_PACKAGE_DETAIL = null; + public static String MSG_NO_PERMISSION = null; + public static String MSG_CONFIG_RELOADED = null; + public static String MSG_FAIL_SET_PERMISSION = null; + public static String MSG_NO_FIND_PLAYER = null; + public static String MSG_NO_FIND_PACKAGE = null; + public static String MSG_TELL_GIVE_PACKAGE = null; + public static String MSG_GIVE_PACKAGE = null; + public static String MSG_GIVE_PACKAGE_FAIL = null; + public static String MSG_TELL_SET_PACKAGE = null; + public static String MSG_SET_PACKAGE = null; + public static String MSG_SET_PACKAGE_FAIL = null; + public static String MSG_TELL_DEL_PACKAGE = null; + public static String MSG_DEL_PACKAGE = null; + public static String MSG_DEL_PACKAGE_FAIL = null; + public static String MSG_TELL_DEL_ALL = null; + public static String MSG_DEL_ALL = null; + public static String MSG_DEL_ALL_FAIL = null; + public static String MSG_NUM_OF_PACKAGES = null; + public static String MSG_EXPIRATION_DATE = null; + public static String MSG_UNKNOWN_PACKAGE = null; + public static String MSG_IS_EXPIRATION_DATE = null; + public static String MSG_FUNC_DISABLED = null; + public static String MSG_TAG_SET_SUCCESS = null; - public static String CMD_HELP = null; - public static String CMD_ME = null; - public static String CMD_TAG = null; - public static String CMD_PACKAGES = null; - public static String CMD_GET = null; - public static String CMD_GIVE = null; - public static String CMD_SET = null; - public static String CMD_REMOVE = null; - public static String CMD_REMOVEALL = null; - public static String CMD_RELOAD = null; + public static String CMD_HELP = null; + public static String CMD_ME = null; + public static String CMD_TAG = null; + public static String CMD_PACKAGES = null; + public static String CMD_GET = null; + public static String CMD_GIVE = null; + public static String CMD_SET = null; + public static String CMD_REMOVE = null; + public static String CMD_REMOVEALL = null; + public static String CMD_RELOAD = null; - public LangCfg(String fileName, PluginMain pm) { - super(fileName, pm); - } + public LangCfg(String fileName, PluginMain pm) { + super(fileName, pm); + } - @Override - protected void init() {} + @Override + protected void init() { + } - @Override - protected void loadToDo() { - INVENTORY_NAME = getConfig().getString("inventoryName", "&4===Permissions Packages==="); - TAG_INVENTORY_NAME = getConfig().getString("tagInventoryName", "&4===Tag Packages==="); - EXPIRATION_TIME = getConfig().getString("expirationTime", "&4Expiration time: {0}"); - LEFT_TIME = getConfig().getString("leftTime", "&4Left time: About {0}{1} {2}{3} {4}{5}"); - TIME_UNIT_D = getConfig().getString("timeUnitD", "day(s)"); - TIME_UNIT_H = getConfig().getString("timeUnitH", "hour(s)"); - TIME_UNIT_M = getConfig().getString("timeUnitM", "minute(s)"); - TIME_FOREVER = getConfig().getString("timeForever", "Forever"); - TAG = getConfig().getString("tag", "Tag/Prefix"); + @Override + protected void loadToDo() { + INVENTORY_NAME = getConfig().getString("inventoryName", "&4===Permissions Packages==="); + TAG_INVENTORY_NAME = getConfig().getString("tagInventoryName", "&4===Tag Packages==="); + EXPIRATION_TIME = getConfig().getString("expirationTime", "&4Expiration time: {0}"); + LEFT_TIME = getConfig().getString("leftTime", "&4Left time: About {0}{1} {2}{3} {4}{5}"); + TIME_UNIT_D = getConfig().getString("timeUnitD", "day(s)"); + TIME_UNIT_H = getConfig().getString("timeUnitH", "hour(s)"); + TIME_UNIT_M = getConfig().getString("timeUnitM", "minute(s)"); + TIME_FOREVER = getConfig().getString("timeForever", "Forever"); + TAG = getConfig().getString("tag", "Tag/Prefix"); - MSG_PARAMETER_MISMATCH = getConfig().getString("msg.parameterMismatch", "&4Parameter mismatch."); - MSG_TIME_PARAMETER_INCORRECT = getConfig().getString("msg.timeParameterIncorrect", "&4The number of time is incorrect. Please enter a nonzero integer."); - MSG_TIME_UNIT_PARAMETER_INCORRECT = getConfig().getString("msg.timeUnitParameterIncorrect", "&4The number of time unit is incorrect. Please use d/h/m. (d=day, h=hour, m=minute)"); - MSG_PROCESSING = getConfig().getString("msg.processing", "&2Please wait for processing..."); - MSG_NO_DATA = getConfig().getString("msg.noData", "&4No data for packages."); - MSG_PACKAGE_NUM = getConfig().getString("msg.packageNum", "&4There are {0} kinds of permissions packages."); - MSG_PACKAGE_LIST = getConfig().getString("msg.packageList", "{0}packageName: {1}, displayName: {2}"); - MSG_PACKAGE_DETAIL = getConfig().getString("msg.packageDetail", "packageName: {0}, displayName: {1}&r\\nPermissions: {2}\\nGroups: {3}"); - MSG_NO_PERMISSION = getConfig().getString("msg.nopermission", "&4You do not have permission to do this."); - MSG_CONFIG_RELOADED = getConfig().getString("msg.configReloaded", "&2Configuration overload is complete."); - MSG_FAIL_SET_PERMISSION = getConfig().getString("msg.failSetPermission", "&4Failed to modify permissions. Please re-enter the server!"); - MSG_NO_FIND_PLAYER = getConfig().getString("msg.noFindPlayer", "&4Can not find player named &2{0}"); - MSG_NO_FIND_PACKAGE = getConfig().getString("msg.noFindPackage", "&4Can not find package named &2{0}"); - MSG_TELL_GIVE_PACKAGE = getConfig().getString("msg.tellGivePackage", "&2{0} give you {1} package of {2}"); - MSG_GIVE_PACKAGE = getConfig().getString("msg.givePackage", "&2Give the player {0} {1} package of {2}"); - MSG_GIVE_PACKAGE_FAIL = getConfig().getString("msg.givePackageFail", "&4Failed to give players {0} {1} package of {2}"); - MSG_TELL_SET_PACKAGE = getConfig().getString("msg.tellSetPackage", "&2{0} set your package of {2} to {1}"); - MSG_SET_PACKAGE = getConfig().getString("msg.setPackage", "&2Set the player {0} {1} package of {2}"); - MSG_SET_PACKAGE_FAIL = getConfig().getString("msg.setPackageFail", "&4Failed to set the player {0} {1} package of {2}"); - MSG_TELL_DEL_PACKAGE = getConfig().getString("msg.tellDelPackage", "&4{0} deleted your package of {1}"); - MSG_DEL_PACKAGE = getConfig().getString("msg.delPackage", "&2Remove package of {1}&2 for player {0}"); - MSG_DEL_PACKAGE_FAIL = getConfig().getString("msg.delPackageFail", "&4Failed to delete package of {1}&2 for player {0}"); - MSG_TELL_DEL_ALL = getConfig().getString("msg.tellDelAll", "&4{0} remove all your packages"); - MSG_DEL_ALL = getConfig().getString("msg.delAll", "&2Remove all packages for player {0}"); - MSG_DEL_ALL_FAIL = getConfig().getString("msg.delAllFail", "&4Failed to remove all packages for player {0}"); - MSG_NUM_OF_PACKAGES = getConfig().getString("msg.numOfPackages", "====={0} has {1} packages====="); - MSG_EXPIRATION_DATE = getConfig().getString("msg.expirationDate", "{0}packages: {1}({2}), Expiration date: {3}, {4}"); - MSG_UNKNOWN_PACKAGE = getConfig().getString("msg.unknownPackage", "Unknown Packages"); - MSG_IS_EXPIRATION_DATE = getConfig().getString("msg.isExpirationDate", "Your package: {0}({1})&r has expired."); - MSG_FUNC_DISABLED = getConfig().getString("msg.funcDisabled", "{0} functionality disabled."); - MSG_TAG_SET_SUCCESS = getConfig().getString("msg.tagSetSuccess", "&2Tag Set Success."); + MSG_PARAMETER_MISMATCH = getConfig().getString("msg.parameterMismatch", "&4Parameter mismatch."); + MSG_TIME_PARAMETER_INCORRECT = getConfig().getString("msg.timeParameterIncorrect", "&4The number of time is incorrect. Please enter a nonzero integer."); + MSG_TIME_UNIT_PARAMETER_INCORRECT = getConfig().getString("msg.timeUnitParameterIncorrect", "&4The number of time unit is incorrect. Please use d/h/m. (d=day, h=hour, m=minute)"); + MSG_PROCESSING = getConfig().getString("msg.processing", "&2Please wait for processing..."); + MSG_NO_DATA = getConfig().getString("msg.noData", "&4No data for packages."); + MSG_NO_TAG_DATA = getConfig().getString("msg.noTagData", "&4No data for tag packages."); + MSG_PACKAGE_NUM = getConfig().getString("msg.packageNum", "&4There are {0} kinds of permissions packages."); + MSG_PACKAGE_LIST = getConfig().getString("msg.packageList", "{0}packageName: {1}, displayName: {2}"); + MSG_PACKAGE_DETAIL = getConfig().getString("msg.packageDetail", "packageName: {0}, displayName: {1}&r\\nPermissions: {2}\\nGroups: {3}"); + MSG_NO_PERMISSION = getConfig().getString("msg.nopermission", "&4You do not have permission to do this."); + MSG_CONFIG_RELOADED = getConfig().getString("msg.configReloaded", "&2Configuration overload is complete."); + MSG_FAIL_SET_PERMISSION = getConfig().getString("msg.failSetPermission", "&4Failed to modify permissions. Please re-enter the server!"); + MSG_NO_FIND_PLAYER = getConfig().getString("msg.noFindPlayer", "&4Can not find player named &2{0}"); + MSG_NO_FIND_PACKAGE = getConfig().getString("msg.noFindPackage", "&4Can not find package named &2{0}"); + MSG_TELL_GIVE_PACKAGE = getConfig().getString("msg.tellGivePackage", "&2{0} give you {1} package of {2}"); + MSG_GIVE_PACKAGE = getConfig().getString("msg.givePackage", "&2Give the player {0} {1} package of {2}"); + MSG_GIVE_PACKAGE_FAIL = getConfig().getString("msg.givePackageFail", "&4Failed to give players {0} {1} package of {2}"); + MSG_TELL_SET_PACKAGE = getConfig().getString("msg.tellSetPackage", "&2{0} set your package of {2} to {1}"); + MSG_SET_PACKAGE = getConfig().getString("msg.setPackage", "&2Set the player {0} {1} package of {2}"); + MSG_SET_PACKAGE_FAIL = getConfig().getString("msg.setPackageFail", "&4Failed to set the player {0} {1} package of {2}"); + MSG_TELL_DEL_PACKAGE = getConfig().getString("msg.tellDelPackage", "&4{0} deleted your package of {1}"); + MSG_DEL_PACKAGE = getConfig().getString("msg.delPackage", "&2Remove package of {1}&2 for player {0}"); + MSG_DEL_PACKAGE_FAIL = getConfig().getString("msg.delPackageFail", "&4Failed to delete package of {1}&2 for player {0}"); + MSG_TELL_DEL_ALL = getConfig().getString("msg.tellDelAll", "&4{0} remove all your packages"); + MSG_DEL_ALL = getConfig().getString("msg.delAll", "&2Remove all packages for player {0}"); + MSG_DEL_ALL_FAIL = getConfig().getString("msg.delAllFail", "&4Failed to remove all packages for player {0}"); + MSG_NUM_OF_PACKAGES = getConfig().getString("msg.numOfPackages", "====={0} has {1} packages====="); + MSG_EXPIRATION_DATE = getConfig().getString("msg.expirationDate", "{0}packages: {1}({2}), Expiration date: {3}, {4}"); + MSG_UNKNOWN_PACKAGE = getConfig().getString("msg.unknownPackage", "Unknown Packages"); + MSG_IS_EXPIRATION_DATE = getConfig().getString("msg.isExpirationDate", "Your package: {0}({1})&r has expired."); + MSG_FUNC_DISABLED = getConfig().getString("msg.funcDisabled", "{0} functionality disabled."); + MSG_TAG_SET_SUCCESS = getConfig().getString("msg.tagSetSuccess", "&2Tag Set Success."); - CMD_HELP = getConfig().getString("cmd.help", "/{0} help \\n&7 - Show commands."); - CMD_ME = getConfig().getString("cmd.me", "&6/{0} me \\n&7 - View your packages."); - CMD_TAG = getConfig().getString("cmd.tag", "&6/{0} tag \\n&7 - View your color/prefix/suffix tags."); - CMD_PACKAGES = getConfig().getString("cmd.packages", "&6/{0} packages [packageName] \\n&7 - View packages."); - CMD_GET = getConfig().getString("cmd.get", "&6/{0} get \\n&7 - View player packages."); - CMD_GIVE = getConfig().getString("cmd.give", "&6/{0} give