1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2025-09-06 11:06:58 +00:00

设置、移除、测试权限组添加

This commit is contained in:
GeekFrog
2017-07-13 07:17:41 +08:00
parent 193f0a7dc4
commit e0e3ce448c
13 changed files with 347 additions and 79 deletions

View File

@ -3,18 +3,23 @@
#### 构建地址:[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/)
##### 插件目标 ##### 插件进度
加粗项已完成 加粗项已完成
- **在配置文件中编辑权限包(可含有多个权限组和多个权限)** - **在配置文件中编辑权限包(可含有多个权限组和多个权限)**
- **时间可以累加** - **时间可以累加**
- **支持重载** - **支持重载**
- 命令支持给玩家**添加**、设置、移除、权限包时间 - **支持UUID**
- 支持UUID - 命令支持给玩家**添加**、**设置**、**移除**、查询自身权限包时间
- 添加、设置、移除-命令执行失败记录
- 手动删除过期的数据
- 调用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

@ -6,7 +6,6 @@ import java.util.logging.Logger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.mcstats.Metrics; import org.mcstats.Metrics;
@ -94,6 +93,10 @@ public class PluginMain extends JavaPlugin {
return sm; return sm;
} }
public Permission getPermission() {
return permission;
}
private boolean checkPluginDepends() { private boolean checkPluginDepends() {
boolean needDepend = false; boolean needDepend = false;
for (String name : DEPEND_PLUGIN.split(",")) { for (String name : DEPEND_PLUGIN.split(",")) {
@ -141,14 +144,18 @@ public class PluginMain extends JavaPlugin {
} }
public UUID getPlayerUUIDByName(String name) { public UUID getPlayerUUIDByName(String name) {
for (Player p : getServer().getOnlinePlayers()) { OfflinePlayer p = getOfflinePlayer(name);
if (p.getName().equals(name)) { if (p == null) {
return p.getUniqueId(); return null;
} } else {
return p.getUniqueId();
} }
}
public OfflinePlayer getOfflinePlayer(String name) {
for (OfflinePlayer p : getServer().getOfflinePlayers()) { for (OfflinePlayer p : getServer().getOfflinePlayers()) {
if (p.getName().equals(name)) { if (p.getName().equalsIgnoreCase(name)) {
return p.getUniqueId(); return p;
} }
} }
return null; return null;

View File

@ -2,6 +2,7 @@ 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 gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
@ -11,44 +12,58 @@ import gg.frog.mc.permissionstime.database.SqlManager;
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean; import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.StrUtil;
public class GiveCmd { public class GiveCmd implements Runnable {
private PluginMain pm; private PluginMain pm;
private SqlManager sm; private SqlManager sm;
private String[] args;
private CommandSender sender;
public GiveCmd(PluginMain pm) { public GiveCmd(PluginMain pm, CommandSender sender, String[] args) {
this.pm = pm; this.pm = pm;
this.sm = pm.getSqlManager(); this.sm = pm.getSqlManager();
this.sender = sender;
this.args = args;
} }
public boolean onCommand(CommandSender sender, boolean isPlayer, String[] args) { @Override
public void run() {
if (args.length == 4) { if (args.length == 4) {
String playerName = args[1]; String playerName = args[1];
String packageName = args[2]; String packageName = args[2];
String time = args[3]; String time = args[3];
int days; int days = 0;
try { try {
days = Integer.parseInt(time); days = Integer.parseInt(time);
if (days <= 0) { if (days <= 0) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数"));
return false; return;
} }
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数"));
return false; return;
} }
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) {
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.giveTime(uuid.toString(), packageName, days)) { 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));
}
}
}
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} {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));
} }
@ -58,6 +73,5 @@ public class GiveCmd {
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确"));
} }
return false;
} }
} }

View File

@ -15,14 +15,10 @@ public class MainCommand implements CommandExecutor {
private PluginMain pm; private PluginMain pm;
private SqlManager sm; private SqlManager sm;
private GiveCmd giveCmd;
private PackagesCmd packagesCmd;
public MainCommand(PluginMain pm) { public MainCommand(PluginMain pm) {
this.pm = pm; this.pm = pm;
this.sm = pm.getSqlManager(); this.sm = pm.getSqlManager();
giveCmd = new GiveCmd(pm);
packagesCmd = new PackagesCmd(pm);
} }
@Override @Override
@ -59,28 +55,38 @@ public class MainCommand implements CommandExecutor {
return true; return true;
} else if (args[0].equalsIgnoreCase("me")) { } else if (args[0].equalsIgnoreCase("me")) {
if (hasPermission(sender, isPlayer, "permissionstime.me")) { if (hasPermission(sender, isPlayer, "permissionstime.me")) {
return giveCmd.onCommand(sender, isPlayer, args); GiveCmd giveCmd = new GiveCmd(pm, sender, args);
new Thread(giveCmd).start();
} }
} else if (args[0].equalsIgnoreCase("give")) { } else if (args[0].equalsIgnoreCase("give")) {
if (hasPermission(sender, isPlayer, "permissionstime.give")) { if (hasPermission(sender, isPlayer, "permissionstime.give")) {
return giveCmd.onCommand(sender, isPlayer, args); GiveCmd giveCmd = new GiveCmd(pm, sender, args);
new Thread(giveCmd).start();
} }
} else if (args[0].equalsIgnoreCase("set")) { } else if (args[0].equalsIgnoreCase("set")) {
if (hasPermission(sender, isPlayer, "permissionstime.set")) { if (hasPermission(sender, isPlayer, "permissionstime.set")) {
return giveCmd.onCommand(sender, isPlayer, args); SetCmd setCmd = new SetCmd(pm, sender, args);
new Thread(setCmd).start();
} }
} else if (args[0].equalsIgnoreCase("remove")) { } else if (args[0].equalsIgnoreCase("remove")) {
if (hasPermission(sender, isPlayer, "permissionstime.remove")) { if (hasPermission(sender, isPlayer, "permissionstime.remove")) {
return giveCmd.onCommand(sender, isPlayer, args); RemoveCmd removeCmd = new RemoveCmd(pm, sender, args);
new Thread(removeCmd).start();
}
} else if (args[0].equalsIgnoreCase("removeall")) {
if (hasPermission(sender, isPlayer, "permissionstime.removeall")) {
RemoveAllCmd removeAllCmd = new RemoveAllCmd(pm, sender, args);
new Thread(removeAllCmd).start();
} }
} else if (args[0].equalsIgnoreCase("packages")) { } else if (args[0].equalsIgnoreCase("packages")) {
if (hasPermission(sender, isPlayer, "permissionstime.packages")) { if (hasPermission(sender, isPlayer, "permissionstime.packages")) {
return packagesCmd.onCommand(sender, isPlayer, args); PackagesCmd packagesCmd = new PackagesCmd(pm, sender, args);
new Thread(packagesCmd).start();
} }
} else { } else {
getHelp(sender, isPlayer); getHelp(sender, isPlayer);
return true;
} }
return true;
} }
} }
return false; return false;
@ -88,8 +94,11 @@ 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 + ".reload")) { if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".me")) {
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " reload \n -Reloads the config file.")); 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."));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give")) { if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".give")) {
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " give <playerName> <packageName> <time> \n - Give player package <time>day.")); sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " give <playerName> <packageName> <time> \n - Give player package <time>day."));
@ -100,8 +109,11 @@ public class MainCommand implements CommandExecutor {
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove")) { if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove")) {
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " remove <playerName> <packageName> \n - Remove player package.")); sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " remove <playerName> <packageName> \n - Remove player package."));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".packages")) { if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall")) {
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " packages [packageName] \n - View packages.")); sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " removeall <playerName> \n - Remove player all package."));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload")) {
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " reload \n -Reloads the config file."));
} }
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
} }

View File

@ -10,15 +10,20 @@ import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean; import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.StrUtil;
public class PackagesCmd { public class PackagesCmd implements Runnable {
private PluginMain pm; private PluginMain pm;
private CommandSender sender;
private String[] args;
public PackagesCmd(PluginMain pm) { public PackagesCmd(PluginMain pm, CommandSender sender, String[] args) {
this.pm = pm; this.pm = pm;
this.sender = sender;
this.args = args;
} }
public boolean onCommand(CommandSender sender, boolean isPlayer, String[] args) { @Override
public void run() {
if (args.length == 1) { if (args.length == 1) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "共有{0}种权限包", PackagesCfg.PACKAGES.size())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "共有{0}种权限包", PackagesCfg.PACKAGES.size()));
for (Entry<String, PermissionPackageBean> e : PackagesCfg.PACKAGES.entrySet()) { for (Entry<String, PermissionPackageBean> e : PackagesCfg.PACKAGES.entrySet()) {
@ -34,6 +39,5 @@ public class PackagesCmd {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的权限包", packageName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的权限包", packageName));
} }
} }
return true;
} }
} }

View File

@ -0,0 +1,48 @@
package gg.frog.mc.permissionstime.command;
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) {
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

@ -0,0 +1,55 @@
package gg.frog.mc.permissionstime.command;
import java.util.UUID;
import org.bukkit.command.CommandSender;
import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.config.PackagesCfg;
import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.database.SqlManager;
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
import gg.frog.mc.permissionstime.utils.StrUtil;
public class RemoveCmd implements Runnable {
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;
}
@Override
public void run() {
if (args.length == 3) {
String playerName = args[1];
String packageName = args[2];
PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName);
if (pack != null) {
UUID uuid = pm.getPlayerUUIDByName(playerName);
if (uuid != null) {
if (PluginCfg.IS_DEBUG) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString()));
}
if (sm.removeTime(uuid.toString(), packageName)) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "删除玩家 {0} 的 {1}", playerName, pack.getDisplayName()));
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未删除玩家 {0} 的 {1}", playerName, pack.getDisplayName()));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的玩家", playerName));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的权限包", packageName));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确"));
}
}
}

View File

@ -0,0 +1,67 @@
package gg.frog.mc.permissionstime.command;
import java.util.UUID;
import org.bukkit.command.CommandSender;
import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.config.PackagesCfg;
import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.database.SqlManager;
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
import gg.frog.mc.permissionstime.utils.StrUtil;
public class SetCmd implements Runnable {
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;
}
@Override
public void run() {
if (args.length == 4) {
String playerName = args[1];
String packageName = args[2];
String time = args[3];
int days = 0;
try {
days = Integer.parseInt(time);
if (days <= 0) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数"));
return;
}
} catch (Exception e) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数"));
return;
}
PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName);
if (pack != null) {
UUID uuid = pm.getPlayerUUIDByName(playerName);
if (uuid != null) {
if (PluginCfg.IS_DEBUG) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + ""));
}
if (sm.setTime(uuid.toString(), packageName, days)) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "设置玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName()));
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "未设置玩家 {0} {1}天的 {2}", playerName, time, pack.getDisplayName()));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的玩家", playerName));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为''{0}''的权限包", packageName));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确"));
}
}
}

View File

@ -1,8 +1,8 @@
package gg.frog.mc.permissionstime.config; package gg.frog.mc.permissionstime.config;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean; import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
@ -12,7 +12,7 @@ public class PackagesCfg extends PluginConfig {
public static String PACKAGES_VERSION = null; public static String PACKAGES_VERSION = null;
public static String DEFAULT_GROUP = null; public static String DEFAULT_GROUP = null;
public static Map<String, PermissionPackageBean> PACKAGES = new HashMap<>(); public static Map<String, PermissionPackageBean> PACKAGES = new ConcurrentHashMap<>();
public PackagesCfg(String fileName, PluginMain pm) { public PackagesCfg(String fileName, PluginMain pm) {
super(fileName, pm); super(fileName, pm);

View File

@ -29,7 +29,7 @@ public interface IPlayerDataService {
* @throws Exception * @throws Exception
*/ */
boolean setPlayerData(PlayerDataBean bean) throws Exception; boolean setPlayerData(PlayerDataBean bean) throws Exception;
boolean setTime(String uuid, String packageName, int days) throws Exception;
boolean addTime(String uuid, String packageName, int days) throws Exception; boolean addTime(String uuid, String packageName, int days) throws Exception;
/** /**

View File

@ -57,4 +57,43 @@ public class SqlManager {
} }
return false; return false;
} }
public boolean setTime(String uuid, String packageName, int days) {
for (int i = 0; i < 3; i++) {
try {
if (pds.setTime(uuid, packageName, days)) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
public boolean removeTime(String uuid, String packageName) {
for (int i = 0; i < 3; i++) {
try {
if (pds.delPlayData(uuid, packageName)) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
public boolean removeAllTime(String uuid) {
for (int i = 0; i < 3; i++) {
try {
if (pds.delPlayData(uuid)) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
} }

View File

@ -69,18 +69,31 @@ public class SqlitePlayerDataService extends DatabaseUtil implements IPlayerData
} }
@Override @Override
public boolean addTime(String uuid, String packageName, int days) throws Exception { public boolean setTime(String uuid, String packageName, int days) throws Exception {
PlayerDataBean pdb = queryPlayerData(uuid, packageName);
long now = new Date().getTime(); long now = new Date().getTime();
long addTime = days * 24 * 60 * 60 * 1000L; long addTime = days * 24 * 60 * 60 * 1000L;
long expire = 0L; long expire = now + addTime;
PlayerDataBean pdb = queryPlayerData(uuid, packageName);
if (pdb == null) {
pdb = new PlayerDataBean(null, uuid, packageName, expire);
return setPlayerData(pdb);
} else {
pdb.setExpire(expire);
return setPlayerData(pdb);
}
}
@Override
public boolean addTime(String uuid, String packageName, int days) throws Exception {
long now = new Date().getTime();
long addTime = days * 24 * 60 * 60 * 1000L;
long expire = now + addTime;
PlayerDataBean pdb = queryPlayerData(uuid, packageName);
if (pdb == null) { if (pdb == null) {
expire = now + addTime;
pdb = new PlayerDataBean(null, uuid, packageName, expire); pdb = new PlayerDataBean(null, uuid, packageName, expire);
return setPlayerData(pdb); return setPlayerData(pdb);
} else { } else {
if (pdb.getExpire() < now) { if (pdb.getExpire() < now) {
expire = now + addTime;
pdb.setExpire(expire); pdb.setExpire(expire);
return setPlayerData(pdb); return setPlayerData(pdb);
} else { } else {

View File

@ -2,39 +2,43 @@ name: PermissionsTime
main: gg.frog.mc.permissionstime.PluginMain main: gg.frog.mc.permissionstime.PluginMain
version: 0.0.1 version: 0.0.1
author: GeekFrog author: GeekFrog
softdepend: [SQLibrary, Vault] softdepend:
- SQLibrary
- Vault
commands: commands:
permissionstime: permissionstime:
description: Show all commands. description: Show all commands.
usage: /permissionstime [param]
permissions: permissions:
permissionstime.*: permissionstime.*:
description: Gives access to all PermissionsTime commands. description: Gives access to all PermissionsTime commands.
children: children:
permissionstime.me: true permissionstime.me: true
permissionstime.reload: true permissionstime.reload: true
permissionstime.give: true permissionstime.give: true
permissionstime.set: true permissionstime.set: true
permissionstime.remove: true permissionstime.remove: true
permissionstime.packages: true permissionstime.removeall: true
permissionstime.reload: true permissionstime.packages: true
permissionstime.me: permissionstime.me:
description: View himself package. description: View himself package.
default: true default: true
permissionstime.reload: permissionstime.reload:
description: Reloads the config file. description: Reloads the config file.
default: op default: op
permissionstime.give: permissionstime.give:
description: Give player package <time>day. description: Give player package <time>day.
default: op default: op
permissionstime.set: permissionstime.set:
description: Set player package <time>day. description: Set player package <time>day.
default: op default: op
permissionstime.remove: permissionstime.remove:
description: Remove player package. description: Remove player package.
default: op default: op
permissionstime.packages: permissionstime.removeall:
description: View packages. description: Remove player all package.
default: op default: op
permissionstime.packages:
description: View packages.
default: op