1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-22 15:48:51 +00:00

权限增加、移除功能

This commit is contained in:
GeekFrog 2017-07-14 06:33:19 +08:00
parent a545520d58
commit 35bcfdc5f8
14 changed files with 275 additions and 124 deletions

View File

@ -3,6 +3,12 @@
#### 构建地址:[http://ci.frog.gg/jenkins/job/PermissionsTime/](http://ci.frog.gg/jenkins/job/PermissionsTime/) #### 构建地址:[http://ci.frog.gg/jenkins/job/PermissionsTime/](http://ci.frog.gg/jenkins/job/PermissionsTime/)
#### 已知问题:
如果出现问题一般退出服务器重进就能解决。一次不行再来一次。
- 如果权限组有继承关系, 被继承的权限组会被大组覆盖, 大组到期被删除, 小组的权限就没有了, 只能重新登录游戏。
##### 插件进度: ##### 插件进度:
加粗项已完成 加粗项已完成
@ -12,14 +18,13 @@
- **支持重载** - **支持重载**
- **支持UUID** - **支持UUID**
- **命令支持给玩家添加、设置、移除、查询自身权限包时间** - **命令支持给玩家添加、设置、移除、查询自身权限包时间**
- 添加、设置、移除-命令执行失败记录 - **添加、设置、移除-命令执行失败记录**
- 手动删除过期的数据 - **支持不同世界权限**
- 调用vault API 设置玩家权限(登录时、游戏中、退出时) - 调用vault API 设置玩家权限 -- 登录时(添加 移除)、游戏中(**命令添加/移除** 延迟移除)、退出时移除
- mysql保存数据 - mysql保存数据
- 支持不同世界权限 - 支持跨服
- 支持前后缀管理 - 手动删除过期的或无效数据
- 支持分页? - 支持分页?
- 支持操作离线用户?
##### 使用统计: ##### 使用统计:
![image](http://i.mcstats.org/PermissionsTime/Global+Statistics.borderless.png) ![image](http://i.mcstats.org/PermissionsTime/Global+Statistics.borderless.png)

View File

@ -1,5 +1,6 @@
package gg.frog.mc.permissionstime; package gg.frog.mc.permissionstime;
import java.text.MessageFormat;
import java.util.Locale; import java.util.Locale;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Logger; 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.config.PluginCfg;
import gg.frog.mc.permissionstime.database.SqlManager; import gg.frog.mc.permissionstime.database.SqlManager;
import gg.frog.mc.permissionstime.listener.TheListener; import gg.frog.mc.permissionstime.listener.TheListener;
import gg.frog.mc.permissionstime.utils.FileUtil;
import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.StrUtil;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
@ -160,4 +162,8 @@ public class PluginMain extends JavaPlugin {
} }
return null; return null;
} }
public void writeFailLog(String content, Object... args) {
FileUtil.writeOnFile(getDataFolder() + "/failure.log", "[" + StrUtil.nowTimeString() + "] " + MessageFormat.format(content, args));
}
} }

View File

@ -1,9 +1,10 @@
package gg.frog.mc.permissionstime.command.packages; package gg.frog.mc.permissionstime.command;
import java.util.UUID; import java.util.UUID;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.config.PackagesCfg; import gg.frog.mc.permissionstime.config.PackagesCfg;
@ -54,17 +55,27 @@ public class GiveCmd implements Runnable {
} }
if (sm.giveTime(uuid.toString(), packageName, days)) { if (sm.giveTime(uuid.toString(), packageName, days)) {
if (player.isOnline()) { if (player.isOnline()) {
for (String groupName : pack.getGroups()) { pm.getServer().getScheduler().runTask(pm, new Runnable() {
if (!pm.getPermission().playerAddGroup(null, player, groupName)) { @Override
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "权限组{0}添加失败", groupName)); 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())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "给予玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName()));
} else { } 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())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未给予玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName()));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的玩家", playerName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的玩家", playerName));
} }

View File

@ -6,12 +6,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import gg.frog.mc.permissionstime.PluginMain; 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.LangCfg;
import gg.frog.mc.permissionstime.config.PluginCfg; import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.database.SqlManager; import gg.frog.mc.permissionstime.database.SqlManager;
@ -102,7 +96,7 @@ public class MainCommand implements CommandExecutor {
private void getHelp(CommandSender sender, boolean isPlayer) { private void getHelp(CommandSender sender, boolean isPlayer) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&a===== " + pm.PLUGIN_NAME + " Version:" + pm.PLUGIN_VERSION + " =====")); 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")) { 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")) { if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages")) {
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " packages [packageName] \n - View packages.")); sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " packages [packageName] \n - View packages."));

View File

@ -1,4 +1,4 @@
package gg.frog.mc.permissionstime.command.packages; package gg.frog.mc.permissionstime.command;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package gg.frog.mc.permissionstime.command.packages; package gg.frog.mc.permissionstime.command;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -34,7 +34,7 @@ public class PackagesCmd implements Runnable {
String packageName = args[1]; String packageName = args[1];
if (PackagesCfg.PACKAGES.containsKey(packageName)) { if (PackagesCfg.PACKAGES.containsKey(packageName)) {
PermissionPackageBean p = PackagesCfg.PACKAGES.get(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 { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的权限包", packageName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的权限包", packageName));
} }

View File

@ -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<PlayerDataBean> 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 + "参数不正确"));
}
}
}

View File

@ -1,8 +1,10 @@
package gg.frog.mc.permissionstime.command.packages; package gg.frog.mc.permissionstime.command;
import java.util.UUID; import java.util.UUID;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.config.PackagesCfg; import gg.frog.mc.permissionstime.config.PackagesCfg;
@ -32,15 +34,34 @@ public class RemoveCmd implements Runnable {
String packageName = args[2]; String packageName = args[2];
PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName);
if (pack != null) { if (pack != null) {
UUID uuid = pm.getPlayerUUIDByName(playerName); OfflinePlayer player = pm.getOfflinePlayer(playerName);
if (uuid != null) { if (player != null) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "执行中,请等待...")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "执行中,请等待..."));
UUID uuid = player.getUniqueId();
if (PluginCfg.IS_DEBUG) { if (PluginCfg.IS_DEBUG) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString()));
} }
if (sm.removeTime(uuid.toString(), packageName)) { 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())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "删除玩家 {0} 的 {1}", playerName, pack.getDisplayName()));
} else { } 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())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未删除玩家 {0} 的 {1}", playerName, pack.getDisplayName()));
} }
} else { } else {

View File

@ -1,8 +1,10 @@
package gg.frog.mc.permissionstime.command.packages; package gg.frog.mc.permissionstime.command;
import java.util.UUID; import java.util.UUID;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.config.PackagesCfg; import gg.frog.mc.permissionstime.config.PackagesCfg;
@ -44,15 +46,34 @@ public class SetCmd implements Runnable {
} }
PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName);
if (pack != null) { if (pack != null) {
UUID uuid = pm.getPlayerUUIDByName(playerName); OfflinePlayer player = pm.getOfflinePlayer(playerName);
if (uuid != null) { if (player != null) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "执行中,请等待...")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "执行中,请等待..."));
UUID uuid = player.getUniqueId();
if (PluginCfg.IS_DEBUG) { if (PluginCfg.IS_DEBUG) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + "")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + ""));
} }
if (sm.setTime(uuid.toString(), packageName, days)) { 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())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "设置玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName()));
} else { } 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())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未设置玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName()));
} }
} else { } else {

View File

@ -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 + "参数不正确"));
}
}
}

View File

@ -3,10 +3,14 @@ package gg.frog.mc.permissionstime.model.cfg;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import gg.frog.mc.permissionstime.utils.config.IConfigBean; 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 String displayName = null;
private Integer days = null; private Integer days = null;
private Boolean global = null; private Boolean global = null;
private List<String> worlds = new ArrayList<>();
private List<String> permissions = new ArrayList<>(); private List<String> permissions = new ArrayList<>();
private List<String> groups = new ArrayList<>(); private List<String> groups = new ArrayList<>();
private List<String> prefixs = new ArrayList<>();
private List<String> suffixs = new ArrayList<>();
public String getDisplayName() { public String getDisplayName() {
return displayName; return displayName;
@ -49,14 +50,6 @@ public class PermissionPackageBean implements IConfigBean {
this.global = global; this.global = global;
} }
public List<String> getWorlds() {
return worlds;
}
public void setWorlds(List<String> worlds) {
this.worlds = worlds;
}
public List<String> getPermissions() { public List<String> getPermissions() {
return permissions; return permissions;
} }
@ -73,33 +66,14 @@ public class PermissionPackageBean implements IConfigBean {
this.groups = groups; this.groups = groups;
} }
public List<String> getPrefixs() {
return prefixs;
}
public void setPrefixs(List<String> prefixs) {
this.prefixs = prefixs;
}
public List<String> getSuffixs() {
return suffixs;
}
public void setSuffixs(List<String> suffixs) {
this.suffixs = suffixs;
}
@Override @Override
public YamlConfiguration toConfig() { public YamlConfiguration toConfig() {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
config.set("displayName", displayName); config.set("displayName", displayName);
config.set("days", days); config.set("days", days);
config.set("global", global); config.set("global", global);
config.set("worlds", worlds);
config.set("permissions", permissions); config.set("permissions", permissions);
config.set("groups", groups); config.set("groups", groups);
config.set("prefixs", prefixs);
config.set("suffixs", suffixs);
return config; return config;
} }
@ -111,16 +85,81 @@ public class PermissionPackageBean implements IConfigBean {
} }
days = config.getInt("days"); days = config.getInt("days");
global = config.getBoolean("global"); global = config.getBoolean("global");
worlds = config.getStringList("worlds");
permissions = config.getStringList("permissions"); permissions = config.getStringList("permissions");
groups = config.getStringList("groups"); groups = config.getStringList("groups");
prefixs = config.getStringList("prefixs");
suffixs = config.getStringList("suffixs");
} }
@Override @Override
public String toString() { 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<World> 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<World> 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);
}
}
}
} }
} }

View File

@ -1,5 +1,7 @@
package gg.frog.mc.permissionstime.utils; package gg.frog.mc.permissionstime.utils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Enumeration; import java.util.Enumeration;
@ -10,6 +12,7 @@ public class FileUtil {
public interface FindFilesDo { public interface FindFilesDo {
boolean isProcess(String fileName); boolean isProcess(String fileName);
void process(String fileName, InputStream is); void process(String fileName, InputStream is);
} }
@ -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();
}
}
} }

View File

@ -1,17 +1,27 @@
package gg.frog.mc.permissionstime.utils; package gg.frog.mc.permissionstime.utils;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import org.apache.commons.lang.time.DateFormatUtils;
public class StrUtil { public class StrUtil {
private static String dfs = "yyyy/MM/dd HH:mm:ss";
public static String messageFormat(String src, Object... args) { public static String messageFormat(String src, Object... args) {
return MessageFormat.format(src, args).replace("&", "§"); return MessageFormat.format(src, args).replace("&", "§");
} }
public static String timestampToString(long time) { public static String timestampToString(long time) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); return DateFormatUtils.format(new Date(time), dfs);
return sdf.format(new Date(time)); }
public static String dateToString(Date d) {
return DateFormatUtils.format(d, dfs);
}
public static String nowTimeString() {
return DateFormatUtils.format(new Date(), dfs);
} }
} }

View File

@ -1,4 +1,5 @@
version: 0.0.1 version: 0.0.1
#默认权限组
defaultGroup: Default defaultGroup: Default
packages: packages:
#权限包名称 #权限包名称
@ -9,21 +10,20 @@ packages:
days: 10 days: 10
#是否跨服权限 #是否跨服权限
global: false global: false
#单世界权限需要修改 #权限包含有的权限 world1、world2、world3是赋值给玩家permission2权限的世界
worlds: [] #如果所有世界都赋值权限则不用注明世界名称如permission1
#权限包含有的权限
permissions: permissions:
- permission1 - permission1
- permission2 - permission2:world1:world2:world3
#权限包含有的权限组 #权限包含有的权限组
groups: groups:
- group1 - group1
- group2 - group2:world1
#权限包含有的前缀 #权限包含有的前缀
prefixs: prefixs:
- '&2[Player]&3' - '&2[Player]&3'
- '&2[VIP]&3' - '&2[VIP]&3:world2'
#权限包含有的后缀 #权限包含有的后缀
suffixs: suffixs:
- '→❤' - '→❤'
- '→★' - '→★:world2:world3'