From a545520d586e71fdd8ce0d9af2028132476860e2 Mon Sep 17 00:00:00 2001 From: GeekFrog Date: Thu, 13 Jul 2017 23:19:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9F=A5=E7=9C=8B=E8=87=AA?= =?UTF-8?q?=E8=BA=AB=E6=9D=83=E9=99=90=E5=8C=85=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../permissionstime/command/MainCommand.java | 11 +++- .../command/{ => packages}/GiveCmd.java | 3 +- .../command/packages/MeCmd.java | 57 +++++++++++++++++++ .../command/{ => packages}/PackagesCmd.java | 2 +- .../command/{ => packages}/RemoveAllCmd.java | 3 +- .../command/{ => packages}/RemoveCmd.java | 3 +- .../command/{ => packages}/SetCmd.java | 3 +- .../database/IPlayerDataService.java | 2 +- .../permissionstime/database/SqlManager.java | 15 +++++ .../impl/SqlitePlayerDataService.java | 22 +++++++ .../model/cfg/PermissionPackageBean.java | 25 +++++++- .../mc/permissionstime/utils/StrUtil.java | 9 ++- src/resources/packages.yml | 4 ++ 14 files changed, 150 insertions(+), 11 deletions(-) rename src/main/gg/frog/mc/permissionstime/command/{ => packages}/GiveCmd.java (95%) create mode 100644 src/main/gg/frog/mc/permissionstime/command/packages/MeCmd.java rename src/main/gg/frog/mc/permissionstime/command/{ => packages}/PackagesCmd.java (97%) rename src/main/gg/frog/mc/permissionstime/command/{ => packages}/RemoveAllCmd.java (91%) rename src/main/gg/frog/mc/permissionstime/command/{ => packages}/RemoveCmd.java (92%) rename src/main/gg/frog/mc/permissionstime/command/{ => packages}/SetCmd.java (94%) diff --git a/README.md b/README.md index 9a84685..64e5f75 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ - **时间可以累加** - **支持重载** - **支持UUID** -- 命令支持给玩家**添加**、**设置**、**移除**、查询自身权限包时间 +- **命令支持给玩家添加、设置、移除、查询自身权限包时间** - 添加、设置、移除-命令执行失败记录 - 手动删除过期的数据 - 调用vault API 设置玩家权限(登录时、游戏中、退出时) diff --git a/src/main/gg/frog/mc/permissionstime/command/MainCommand.java b/src/main/gg/frog/mc/permissionstime/command/MainCommand.java index e5e133b..ee88906 100644 --- a/src/main/gg/frog/mc/permissionstime/command/MainCommand.java +++ b/src/main/gg/frog/mc/permissionstime/command/MainCommand.java @@ -6,6 +6,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import gg.frog.mc.permissionstime.PluginMain; +import gg.frog.mc.permissionstime.command.packages.GiveCmd; +import gg.frog.mc.permissionstime.command.packages.MeCmd; +import gg.frog.mc.permissionstime.command.packages.PackagesCmd; +import gg.frog.mc.permissionstime.command.packages.RemoveAllCmd; +import gg.frog.mc.permissionstime.command.packages.RemoveCmd; +import gg.frog.mc.permissionstime.command.packages.SetCmd; import gg.frog.mc.permissionstime.config.LangCfg; import gg.frog.mc.permissionstime.config.PluginCfg; import gg.frog.mc.permissionstime.database.SqlManager; @@ -33,6 +39,7 @@ public class MainCommand implements CommandExecutor { return true; } else { if (args[0].equalsIgnoreCase("reload")) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "执行中,请等待...")); if (isPlayer) { Player player = (Player) sender; if (sender.isOp() || player.hasPermission("permissionstime.reload")) { @@ -55,8 +62,8 @@ public class MainCommand implements CommandExecutor { return true; } else if (args[0].equalsIgnoreCase("me")) { if (hasPermission(sender, isPlayer, "permissionstime.me")) { - GiveCmd giveCmd = new GiveCmd(pm, sender, args); - new Thread(giveCmd).start(); + MeCmd meCmd = new MeCmd(pm, sender, isPlayer, args); + new Thread(meCmd).start(); } } else if (args[0].equalsIgnoreCase("give")) { if (hasPermission(sender, isPlayer, "permissionstime.give")) { diff --git a/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java b/src/main/gg/frog/mc/permissionstime/command/packages/GiveCmd.java similarity index 95% rename from src/main/gg/frog/mc/permissionstime/command/GiveCmd.java rename to src/main/gg/frog/mc/permissionstime/command/packages/GiveCmd.java index 74c9861..3c27830 100644 --- a/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/packages/GiveCmd.java @@ -1,4 +1,4 @@ -package gg.frog.mc.permissionstime.command; +package gg.frog.mc.permissionstime.command.packages; import java.util.UUID; @@ -47,6 +47,7 @@ public class GiveCmd implements Runnable { if (pack != null) { OfflinePlayer player = pm.getOfflinePlayer(playerName); if (player != null) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "执行中,请等待...")); UUID uuid = player.getUniqueId(); if (PluginCfg.IS_DEBUG) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + "天")); diff --git a/src/main/gg/frog/mc/permissionstime/command/packages/MeCmd.java b/src/main/gg/frog/mc/permissionstime/command/packages/MeCmd.java new file mode 100644 index 0000000..0ff962e --- /dev/null +++ b/src/main/gg/frog/mc/permissionstime/command/packages/MeCmd.java @@ -0,0 +1,57 @@ +package gg.frog.mc.permissionstime.command.packages; + +import java.util.List; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +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.database.SqlManager; +import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean; +import gg.frog.mc.permissionstime.model.db.PlayerDataBean; +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; + + 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 < 2) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "执行中,请等待...")); + // String page = args[1]; + Player p = (Player) sender; + List ps = sm.getTime(p.getUniqueId().toString()); + if (ps.size() > 0) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "=====你共有{0}种权限包=====", ps.size())); + for (PlayerDataBean pdb : ps) { + PermissionPackageBean pc = PackagesCfg.PACKAGES.get(pdb.getPackageName()); + String expireString = StrUtil.timestampToString(pdb.getExpire()); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "权限包: {0}({1}), 到期时间: {2}", pc.getDisplayName(), pdb.getPackageName(), expireString)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "暂时无数据")); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确")); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "此命令只能玩家执行")); + } + } +} diff --git a/src/main/gg/frog/mc/permissionstime/command/PackagesCmd.java b/src/main/gg/frog/mc/permissionstime/command/packages/PackagesCmd.java similarity index 97% rename from src/main/gg/frog/mc/permissionstime/command/PackagesCmd.java rename to src/main/gg/frog/mc/permissionstime/command/packages/PackagesCmd.java index b131f3b..46c770c 100644 --- a/src/main/gg/frog/mc/permissionstime/command/PackagesCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/packages/PackagesCmd.java @@ -1,4 +1,4 @@ -package gg.frog.mc.permissionstime.command; +package gg.frog.mc.permissionstime.command.packages; import java.util.Map.Entry; diff --git a/src/main/gg/frog/mc/permissionstime/command/RemoveAllCmd.java b/src/main/gg/frog/mc/permissionstime/command/packages/RemoveAllCmd.java similarity index 91% rename from src/main/gg/frog/mc/permissionstime/command/RemoveAllCmd.java rename to src/main/gg/frog/mc/permissionstime/command/packages/RemoveAllCmd.java index 9cfe9a4..8606127 100644 --- a/src/main/gg/frog/mc/permissionstime/command/RemoveAllCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/packages/RemoveAllCmd.java @@ -1,4 +1,4 @@ -package gg.frog.mc.permissionstime.command; +package gg.frog.mc.permissionstime.command.packages; import java.util.UUID; @@ -29,6 +29,7 @@ public class RemoveAllCmd implements Runnable { String playerName = args[1]; UUID uuid = pm.getPlayerUUIDByName(playerName); if (uuid != null) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "执行中,请等待...")); if (PluginCfg.IS_DEBUG) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString())); } diff --git a/src/main/gg/frog/mc/permissionstime/command/RemoveCmd.java b/src/main/gg/frog/mc/permissionstime/command/packages/RemoveCmd.java similarity index 92% rename from src/main/gg/frog/mc/permissionstime/command/RemoveCmd.java rename to src/main/gg/frog/mc/permissionstime/command/packages/RemoveCmd.java index 1141f1f..4c92c00 100644 --- a/src/main/gg/frog/mc/permissionstime/command/RemoveCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/packages/RemoveCmd.java @@ -1,4 +1,4 @@ -package gg.frog.mc.permissionstime.command; +package gg.frog.mc.permissionstime.command.packages; import java.util.UUID; @@ -34,6 +34,7 @@ public class RemoveCmd implements Runnable { if (pack != null) { UUID uuid = pm.getPlayerUUIDByName(playerName); if (uuid != null) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "执行中,请等待...")); if (PluginCfg.IS_DEBUG) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString())); } diff --git a/src/main/gg/frog/mc/permissionstime/command/SetCmd.java b/src/main/gg/frog/mc/permissionstime/command/packages/SetCmd.java similarity index 94% rename from src/main/gg/frog/mc/permissionstime/command/SetCmd.java rename to src/main/gg/frog/mc/permissionstime/command/packages/SetCmd.java index ab1fd2d..31718b1 100644 --- a/src/main/gg/frog/mc/permissionstime/command/SetCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/packages/SetCmd.java @@ -1,4 +1,4 @@ -package gg.frog.mc.permissionstime.command; +package gg.frog.mc.permissionstime.command.packages; import java.util.UUID; @@ -46,6 +46,7 @@ public class SetCmd implements Runnable { if (pack != null) { UUID uuid = pm.getPlayerUUIDByName(playerName); if (uuid != null) { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "执行中,请等待...")); if (PluginCfg.IS_DEBUG) { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + "天")); } diff --git a/src/main/gg/frog/mc/permissionstime/database/IPlayerDataService.java b/src/main/gg/frog/mc/permissionstime/database/IPlayerDataService.java index 75592de..659d0b4 100644 --- a/src/main/gg/frog/mc/permissionstime/database/IPlayerDataService.java +++ b/src/main/gg/frog/mc/permissionstime/database/IPlayerDataService.java @@ -45,7 +45,7 @@ public interface IPlayerDataService { * @return */ List queryPlayerData(String uuid) throws Exception; - PlayerDataBean queryPlayerData(String uuid, String packageName) throws Exception; + List queryNotExpirePlayerData(String uuid) throws Exception; } diff --git a/src/main/gg/frog/mc/permissionstime/database/SqlManager.java b/src/main/gg/frog/mc/permissionstime/database/SqlManager.java index dc1cd7c..115a564 100644 --- a/src/main/gg/frog/mc/permissionstime/database/SqlManager.java +++ b/src/main/gg/frog/mc/permissionstime/database/SqlManager.java @@ -1,8 +1,12 @@ package gg.frog.mc.permissionstime.database; +import java.util.Collections; +import java.util.List; + import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.config.PluginCfg; import gg.frog.mc.permissionstime.database.impl.SqlitePlayerDataService; +import gg.frog.mc.permissionstime.model.db.PlayerDataBean; import gg.frog.mc.permissionstime.utils.StrUtil; import lib.PatPeter.SQLibrary.Database; import lib.PatPeter.SQLibrary.MySQL; @@ -45,6 +49,17 @@ public class SqlManager { return false; } + public List getTime(String uuid) { + for (int i = 0; i < 3; i++) { + try { + return pds.queryNotExpirePlayerData(uuid); + } catch (Exception e) { + e.printStackTrace(); + } + } + return Collections.emptyList(); + } + public boolean giveTime(String uuid, String packageName, int days) { for (int i = 0; i < 3; i++) { try { diff --git a/src/main/gg/frog/mc/permissionstime/database/impl/SqlitePlayerDataService.java b/src/main/gg/frog/mc/permissionstime/database/impl/SqlitePlayerDataService.java index 2b538ce..4c156a5 100644 --- a/src/main/gg/frog/mc/permissionstime/database/impl/SqlitePlayerDataService.java +++ b/src/main/gg/frog/mc/permissionstime/database/impl/SqlitePlayerDataService.java @@ -150,6 +150,28 @@ public class SqlitePlayerDataService extends DatabaseUtil implements IPlayerData } } + @Override + public List queryNotExpirePlayerData(String uuid) throws Exception { + long now = new Date().getTime(); + String sql = "SELECT * FROM \"playerData\" where (\"uuid\"='" + uuid + "' AND \"expire\" > " + now + ");"; + try { + List pdbList = new ArrayList<>(); + ResultSet rs = getDB().query(sql); + while (rs.next()) { + long tid = rs.getLong("id"); + String tuuid = rs.getString("uuid"); + String tpackageName = rs.getString("packageName"); + long texpire = rs.getLong("expire"); + PlayerDataBean tpd = new PlayerDataBean(tid, tuuid, tpackageName, texpire); + pdbList.add(tpd); + } + return pdbList; + } catch (Exception e) { + pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "无法查询UUID: {0} 的数据", uuid)); + throw e; + } + } + @Override public boolean delPlayData(String uuid) throws Exception { String sql = "DELETE FROM \"main\".\"playerData\" WHERE (\"uuid\"='" + uuid + "');"; diff --git a/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java b/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java index 13eedb5..c541400 100644 --- a/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java +++ b/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java @@ -18,6 +18,8 @@ public class PermissionPackageBean implements IConfigBean { private String displayName = null; private Integer days = null; + private Boolean global = null; + private List worlds = new ArrayList<>(); private List permissions = new ArrayList<>(); private List groups = new ArrayList<>(); private List prefixs = new ArrayList<>(); @@ -39,6 +41,22 @@ public class PermissionPackageBean implements IConfigBean { this.days = days; } + public Boolean getGlobal() { + return global; + } + + public void setGlobal(Boolean global) { + this.global = global; + } + + public List getWorlds() { + return worlds; + } + + public void setWorlds(List worlds) { + this.worlds = worlds; + } + public List getPermissions() { return permissions; } @@ -76,6 +94,8 @@ public class PermissionPackageBean implements IConfigBean { YamlConfiguration config = new YamlConfiguration(); config.set("displayName", displayName); config.set("days", days); + config.set("global", global); + config.set("worlds", worlds); config.set("permissions", permissions); config.set("groups", groups); config.set("prefixs", prefixs); @@ -90,6 +110,8 @@ public class PermissionPackageBean implements IConfigBean { displayName = "No Name"; } days = config.getInt("days"); + global = config.getBoolean("global"); + worlds = config.getStringList("worlds"); permissions = config.getStringList("permissions"); groups = config.getStringList("groups"); prefixs = config.getStringList("prefixs"); @@ -98,6 +120,7 @@ public class PermissionPackageBean implements IConfigBean { @Override public String toString() { - return "PermissionPackageBean [displayName=" + displayName + ", days=" + days + ", permissions=" + permissions + ", groups=" + groups + ", prefixs=" + prefixs + ", suffixs=" + suffixs + "]"; + return "PermissionPackageBean [displayName=" + displayName + ", days=" + days + ", global=" + global + ", worlds=" + worlds + ", permissions=" + permissions + ", groups=" + groups + ", prefixs=" + prefixs + ", suffixs=" + suffixs + "]"; } + } diff --git a/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java b/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java index 08e3ec9..9352702 100644 --- a/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java +++ b/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java @@ -1,10 +1,17 @@ package gg.frog.mc.permissionstime.utils; import java.text.MessageFormat; +import java.text.SimpleDateFormat; +import java.util.Date; public class StrUtil { - public static String messageFormat(String src, Object... args){ + public static String messageFormat(String src, Object... args) { return MessageFormat.format(src, args).replace("&", "§"); } + + public static String timestampToString(long time) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + return sdf.format(new Date(time)); + } } diff --git a/src/resources/packages.yml b/src/resources/packages.yml index 9f44424..68fcd8c 100644 --- a/src/resources/packages.yml +++ b/src/resources/packages.yml @@ -7,6 +7,10 @@ packages: displayName: '权限包模板1' #权限包时间(单位: 天) days: 10 + #是否跨服权限 + global: false + #单世界权限需要修改 + worlds: [] #权限包含有的权限 permissions: - permission1