diff --git a/README.md b/README.md index 64e5f75..36d6472 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ #### 构建地址:[http://ci.frog.gg/jenkins/job/PermissionsTime/](http://ci.frog.gg/jenkins/job/PermissionsTime/) +#### 已知问题: + +如果出现问题一般退出服务器重进就能解决。一次不行再来一次。 + +- 如果权限组有继承关系, 被继承的权限组会被大组覆盖, 大组到期被删除, 小组的权限就没有了, 只能重新登录游戏。 + ##### 插件进度: 加粗项已完成 @@ -12,14 +18,13 @@ - **支持重载** - **支持UUID** - **命令支持给玩家添加、设置、移除、查询自身权限包时间** -- 添加、设置、移除-命令执行失败记录 -- 手动删除过期的数据 -- 调用vault API 设置玩家权限(登录时、游戏中、退出时) +- **添加、设置、移除-命令执行失败记录** +- **支持不同世界权限** +- 调用vault API 设置玩家权限 -- 登录时(添加 移除)、游戏中(**命令添加/移除** 延迟移除)、退出时移除 - mysql保存数据 -- 支持不同世界权限 -- 支持前后缀管理 +- 支持跨服 +- 手动删除过期的或无效数据 - 支持分页? -- 支持操作离线用户? ##### 使用统计: ![image](http://i.mcstats.org/PermissionsTime/Global+Statistics.borderless.png) \ No newline at end of file diff --git a/src/main/gg/frog/mc/permissionstime/PluginMain.java b/src/main/gg/frog/mc/permissionstime/PluginMain.java index 4b3a0d7..24577c4 100644 --- a/src/main/gg/frog/mc/permissionstime/PluginMain.java +++ b/src/main/gg/frog/mc/permissionstime/PluginMain.java @@ -1,5 +1,6 @@ package gg.frog.mc.permissionstime; +import java.text.MessageFormat; import java.util.Locale; import java.util.UUID; import java.util.logging.Logger; @@ -15,6 +16,7 @@ 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.TheListener; +import gg.frog.mc.permissionstime.utils.FileUtil; import gg.frog.mc.permissionstime.utils.StrUtil; import net.milkbowl.vault.permission.Permission; @@ -160,4 +162,8 @@ public class PluginMain extends JavaPlugin { } 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/packages/GiveCmd.java b/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java similarity index 74% rename from src/main/gg/frog/mc/permissionstime/command/packages/GiveCmd.java rename to src/main/gg/frog/mc/permissionstime/command/GiveCmd.java index 3c27830..5c8c570 100644 --- a/src/main/gg/frog/mc/permissionstime/command/packages/GiveCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java @@ -1,9 +1,10 @@ -package gg.frog.mc.permissionstime.command.packages; +package gg.frog.mc.permissionstime.command; import java.util.UUID; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.config.PackagesCfg; @@ -54,17 +55,27 @@ public class GiveCmd implements Runnable { } if (sm.giveTime(uuid.toString(), packageName, days)) { if (player.isOnline()) { - for (String groupName : pack.getGroups()) { - if (!pm.getPermission().playerAddGroup(null, player, groupName)) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "权限组{0}添加失败", groupName)); + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + pack.givePlayer(player, sender, pm.getPermission()); } + }); + Player p = pm.getServer().getPlayer(uuid); + if (p != null) { + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "{0}给予你 {1}天的 {2}", sender.getName(), time, pack.getDisplayName())); } } sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "给予玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName())); } else { + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + pm.writeFailLog("命令执行失败 给予玩家 {0}({1}) {2}天的 {3} 执行人: {4}", playerName, player.getUniqueId().toString(), time, pack.getDisplayName(), sender.getName()); + } + }); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未给予玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName())); } - } else { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的玩家", playerName)); } diff --git a/src/main/gg/frog/mc/permissionstime/command/MainCommand.java b/src/main/gg/frog/mc/permissionstime/command/MainCommand.java index ee88906..fe7d5d5 100644 --- a/src/main/gg/frog/mc/permissionstime/command/MainCommand.java +++ b/src/main/gg/frog/mc/permissionstime/command/MainCommand.java @@ -6,12 +6,6 @@ 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; @@ -102,7 +96,7 @@ public class MainCommand implements CommandExecutor { private void getHelp(CommandSender sender, boolean isPlayer) { 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 + ".me")) { - sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " .me \n - View self package.")); + sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " me \n - View self package.")); } 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.")); diff --git a/src/main/gg/frog/mc/permissionstime/command/packages/MeCmd.java b/src/main/gg/frog/mc/permissionstime/command/MeCmd.java similarity index 97% rename from src/main/gg/frog/mc/permissionstime/command/packages/MeCmd.java rename to src/main/gg/frog/mc/permissionstime/command/MeCmd.java index 0ff962e..6d7aa12 100644 --- a/src/main/gg/frog/mc/permissionstime/command/packages/MeCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/MeCmd.java @@ -1,4 +1,4 @@ -package gg.frog.mc.permissionstime.command.packages; +package gg.frog.mc.permissionstime.command; import java.util.List; diff --git a/src/main/gg/frog/mc/permissionstime/command/packages/PackagesCmd.java b/src/main/gg/frog/mc/permissionstime/command/PackagesCmd.java similarity index 94% rename from src/main/gg/frog/mc/permissionstime/command/packages/PackagesCmd.java rename to src/main/gg/frog/mc/permissionstime/command/PackagesCmd.java index 46c770c..608a495 100644 --- a/src/main/gg/frog/mc/permissionstime/command/packages/PackagesCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/PackagesCmd.java @@ -1,4 +1,4 @@ -package gg.frog.mc.permissionstime.command.packages; +package gg.frog.mc.permissionstime.command; import java.util.Map.Entry; @@ -34,7 +34,7 @@ public class PackagesCmd implements Runnable { String packageName = args[1]; if (PackagesCfg.PACKAGES.containsKey(packageName)) { 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())); + 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())); } else { sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的权限包", packageName)); } diff --git a/src/main/gg/frog/mc/permissionstime/command/RemoveAllCmd.java b/src/main/gg/frog/mc/permissionstime/command/RemoveAllCmd.java new file mode 100644 index 0000000..59af054 --- /dev/null +++ b/src/main/gg/frog/mc/permissionstime/command/RemoveAllCmd.java @@ -0,0 +1,78 @@ +package gg.frog.mc.permissionstime.command; + +import java.util.List; +import java.util.UUID; + +import org.bukkit.OfflinePlayer; +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 RemoveAllCmd implements Runnable { + + 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; + } + + @Override + public void run() { + if (args.length == 2) { + String playerName = args[1]; + 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())); + } + List pdbList = sm.getTime(uuid.toString()); + if (sm.removeAllTime(uuid.toString())) { + if (player.isOnline() && pdbList.size() > 0) { + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + for (PlayerDataBean pdb : pdbList) { + String packageName = pdb.getPackageName(); + PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); + pack.clearPlayer(player, sender, pm.getPermission()); + } + } + }); + Player p = pm.getServer().getPlayer(uuid); + if (p != null) { + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "{0}删除了你的所有权限包", sender.getName())); + } + } + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "删除玩家 {0} 的所有权限包", playerName)); + } else { + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + pm.writeFailLog("命令执行失败 删除玩家 {0}({1}) 的所有权限包 执行人: {2}", playerName, player.getUniqueId().toString(), sender.getName()); + } + }); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未删除玩家 {0} 的 {1}", playerName)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的玩家", playerName)); + } + } else { + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确")); + } + } +} diff --git a/src/main/gg/frog/mc/permissionstime/command/packages/RemoveCmd.java b/src/main/gg/frog/mc/permissionstime/command/RemoveCmd.java similarity index 61% rename from src/main/gg/frog/mc/permissionstime/command/packages/RemoveCmd.java rename to src/main/gg/frog/mc/permissionstime/command/RemoveCmd.java index 4c92c00..6144d69 100644 --- a/src/main/gg/frog/mc/permissionstime/command/packages/RemoveCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/RemoveCmd.java @@ -1,8 +1,10 @@ -package gg.frog.mc.permissionstime.command.packages; +package gg.frog.mc.permissionstime.command; import java.util.UUID; +import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.config.PackagesCfg; @@ -32,15 +34,34 @@ public class RemoveCmd implements Runnable { String packageName = args[2]; PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); if (pack != null) { - UUID uuid = pm.getPlayerUUIDByName(playerName); - if (uuid != 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())); } if (sm.removeTime(uuid.toString(), packageName)) { + if (player.isOnline()) { + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + pack.clearPlayer(player, sender, pm.getPermission()); + } + }); + Player p = pm.getServer().getPlayer(uuid); + if (p != null) { + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "{0}删除了你的 {1}权限包", sender.getName(), pack.getDisplayName())); + } + } sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "删除玩家 {0} 的 {1}", playerName, pack.getDisplayName())); } else { + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + pm.writeFailLog("命令执行失败 删除玩家 {0}({1}) 的 {2} 执行人: {3}", playerName, player.getUniqueId().toString(), pack.getDisplayName(), sender.getName()); + } + }); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未删除玩家 {0} 的 {1}", playerName, pack.getDisplayName())); } } else { diff --git a/src/main/gg/frog/mc/permissionstime/command/packages/SetCmd.java b/src/main/gg/frog/mc/permissionstime/command/SetCmd.java similarity index 66% rename from src/main/gg/frog/mc/permissionstime/command/packages/SetCmd.java rename to src/main/gg/frog/mc/permissionstime/command/SetCmd.java index 31718b1..c20b461 100644 --- a/src/main/gg/frog/mc/permissionstime/command/packages/SetCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/SetCmd.java @@ -1,8 +1,10 @@ -package gg.frog.mc.permissionstime.command.packages; +package gg.frog.mc.permissionstime.command; import java.util.UUID; +import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.config.PackagesCfg; @@ -44,15 +46,34 @@ public class SetCmd implements Runnable { } PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); if (pack != null) { - UUID uuid = pm.getPlayerUUIDByName(playerName); - if (uuid != 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 + "天")); } if (sm.setTime(uuid.toString(), packageName, days)) { + if (player.isOnline()) { + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + pack.givePlayer(player, sender, pm.getPermission()); + } + }); + Player p = pm.getServer().getPlayer(uuid); + if (p != null) { + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "{0}设置你 {1}天的 {2}", sender.getName(), time, pack.getDisplayName())); + } + } sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "设置玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName())); } else { + pm.getServer().getScheduler().runTask(pm, new Runnable() { + @Override + public void run() { + pm.writeFailLog("命令执行失败 设置玩家 {0}({1}) {2}天的 {3} 执行人: {4}", playerName, player.getUniqueId().toString(), time, pack.getDisplayName(), sender.getName()); + } + }); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未设置玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName())); } } else { diff --git a/src/main/gg/frog/mc/permissionstime/command/packages/RemoveAllCmd.java b/src/main/gg/frog/mc/permissionstime/command/packages/RemoveAllCmd.java deleted file mode 100644 index 8606127..0000000 --- a/src/main/gg/frog/mc/permissionstime/command/packages/RemoveAllCmd.java +++ /dev/null @@ -1,49 +0,0 @@ -package gg.frog.mc.permissionstime.command.packages; - -import java.util.UUID; - -import org.bukkit.command.CommandSender; - -import gg.frog.mc.permissionstime.PluginMain; -import gg.frog.mc.permissionstime.config.PluginCfg; -import gg.frog.mc.permissionstime.database.SqlManager; -import gg.frog.mc.permissionstime.utils.StrUtil; - -public class RemoveAllCmd implements Runnable { - - 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; - } - - @Override - public void run() { - if (args.length == 2) { - 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())); - } - if (sm.removeAllTime(uuid.toString())) { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "删除玩家 {0} 的所有权限包", playerName)); - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未删除玩家 {0} 的所有权限包", playerName)); - } - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的玩家", playerName)); - } - - } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确")); - } - } -} 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 c541400..d249ae6 100644 --- a/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java +++ b/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java @@ -3,10 +3,14 @@ package gg.frog.mc.permissionstime.model.cfg; import java.util.ArrayList; import java.util.List; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.YamlConfiguration; import gg.frog.mc.permissionstime.utils.config.IConfigBean; +import net.milkbowl.vault.permission.Permission; /** * 权限包实体类 @@ -19,11 +23,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<>(); - private List suffixs = new ArrayList<>(); public String getDisplayName() { return displayName; @@ -49,14 +50,6 @@ public class PermissionPackageBean implements IConfigBean { this.global = global; } - public List getWorlds() { - return worlds; - } - - public void setWorlds(List worlds) { - this.worlds = worlds; - } - public List getPermissions() { return permissions; } @@ -73,33 +66,14 @@ public class PermissionPackageBean implements IConfigBean { this.groups = groups; } - public List getPrefixs() { - return prefixs; - } - - public void setPrefixs(List prefixs) { - this.prefixs = prefixs; - } - - public List getSuffixs() { - return suffixs; - } - - public void setSuffixs(List suffixs) { - this.suffixs = suffixs; - } - @Override public YamlConfiguration toConfig() { 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); - config.set("suffixs", suffixs); return config; } @@ -111,16 +85,81 @@ public class PermissionPackageBean implements IConfigBean { } days = config.getInt("days"); global = config.getBoolean("global"); - worlds = config.getStringList("worlds"); permissions = config.getStringList("permissions"); groups = config.getStringList("groups"); - prefixs = config.getStringList("prefixs"); - suffixs = config.getStringList("suffixs"); } @Override public String toString() { - return "PermissionPackageBean [displayName=" + displayName + ", days=" + days + ", global=" + global + ", worlds=" + worlds + ", permissions=" + permissions + ", groups=" + groups + ", prefixs=" + prefixs + ", suffixs=" + suffixs + "]"; + return "PermissionPackageBean [displayName=" + displayName + ", days=" + days + ", global=" + global + ", permissions=" + permissions + ", groups=" + groups + "]"; + } + + public void givePlayer(OfflinePlayer player, CommandSender sender, Permission permission) { + List worlds = sender.getServer().getWorlds(); + for (String pem : permissions) { + String[] args = pem.split(":"); + pem = args[0]; + if (args.length > 1) { + for (int i = 1; i < args.length; i++) { + String worldName = args[i]; + permission.playerAdd(worldName, player, pem); + } + } else { + for (World world : worlds) { + String worldName = world.getName(); + permission.playerAdd(worldName, player, pem); + } + } + } + for (String groupName : groups) { + String[] args = groupName.split(":"); + groupName = args[0]; + if (args.length > 1) { + for (int i = 1; i < args.length; i++) { + String worldName = args[i]; + permission.playerAddGroup(worldName, player, groupName); + } + } else { + for (World world : worlds) { + String worldName = world.getName(); + permission.playerAddGroup(worldName, player, groupName); + } + } + } + } + + public void clearPlayer(OfflinePlayer player, CommandSender sender, Permission permission) { + List worlds = sender.getServer().getWorlds(); + for (String pem : permissions) { + String[] args = pem.split(":"); + pem = args[0]; + if (args.length > 1) { + for (int i = 1; i < args.length; i++) { + String worldName = args[i]; + permission.playerAdd(worldName, player, pem); + } + } else { + for (World world : worlds) { + String worldName = world.getName(); + permission.playerAdd(worldName, player, pem); + } + } + } + for (String groupName : groups) { + String[] args = groupName.split(":"); + groupName = args[0]; + if (args.length > 1) { + for (int i = 1; i < args.length; i++) { + String worldName = args[i]; + permission.playerRemoveGroup(worldName, player, groupName); + } + } else { + for (World world : worlds) { + String worldName = world.getName(); + permission.playerRemoveGroup(worldName, player, groupName); + } + } + } } } diff --git a/src/main/gg/frog/mc/permissionstime/utils/FileUtil.java b/src/main/gg/frog/mc/permissionstime/utils/FileUtil.java index 30a582b..077e757 100644 --- a/src/main/gg/frog/mc/permissionstime/utils/FileUtil.java +++ b/src/main/gg/frog/mc/permissionstime/utils/FileUtil.java @@ -1,5 +1,7 @@ package gg.frog.mc.permissionstime.utils; +import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; @@ -7,13 +9,14 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; public class FileUtil { - + public interface FindFilesDo { boolean isProcess(String fileName); + void process(String fileName, InputStream is); } - - public static void findFilesFromJar(FindFilesDo ffd, Class jarClazz){ + + public static void findFilesFromJar(FindFilesDo ffd, Class jarClazz) { JarFile jarFile = null; try { String jarFilePath = jarClazz.getProtectionDomain().getCodeSource().getLocation().getFile(); @@ -21,7 +24,7 @@ public class FileUtil { Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry e = entries.nextElement(); - if(ffd.isProcess(e.getName())){ + if (ffd.isProcess(e.getName())) { InputStream is = jarFile.getInputStream(e); ffd.process(e.getName(), is); try { @@ -43,4 +46,16 @@ public class FileUtil { } } } + + public static void writeOnFile(String fileName, String content) { + FileWriter fw; + try { + File f = new File(fileName); + fw = new FileWriter(f, true); + fw.write(content + "\r\n"); + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java b/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java index 9352702..bda4eec 100644 --- a/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java +++ b/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java @@ -1,17 +1,27 @@ package gg.frog.mc.permissionstime.utils; import java.text.MessageFormat; -import java.text.SimpleDateFormat; import java.util.Date; +import org.apache.commons.lang.time.DateFormatUtils; + public class StrUtil { + private static String dfs = "yyyy/MM/dd HH:mm:ss"; + 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)); + return DateFormatUtils.format(new Date(time), dfs); + } + + public static String dateToString(Date d) { + return DateFormatUtils.format(d, dfs); + } + + public static String nowTimeString() { + return DateFormatUtils.format(new Date(), dfs); } } diff --git a/src/resources/packages.yml b/src/resources/packages.yml index 68fcd8c..658c5e2 100644 --- a/src/resources/packages.yml +++ b/src/resources/packages.yml @@ -1,4 +1,5 @@ version: 0.0.1 +#默认权限组 defaultGroup: Default packages: #权限包名称 @@ -9,21 +10,20 @@ packages: days: 10 #是否跨服权限 global: false - #单世界权限需要修改 - worlds: [] - #权限包含有的权限 + #权限包含有的权限 world1、world2、world3是赋值给玩家permission2权限的世界 + #如果所有世界都赋值权限则不用注明世界名称如:permission1 permissions: - permission1 - - permission2 + - permission2:world1:world2:world3 #权限包含有的权限组 groups: - group1 - - group2 + - group2:world1 #权限包含有的前缀 prefixs: - '&2[Player]&3' - - '&2[VIP]&3' + - '&2[VIP]&3:world2' #权限包含有的后缀 suffixs: - '→❤' - - '→★' + - '→★:world2:world3'