mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2024-11-22 07:28:47 +00:00
添加查看自身权限包功能
This commit is contained in:
parent
e0e3ce448c
commit
a545520d58
@ -11,7 +11,7 @@
|
||||
- **时间可以累加**
|
||||
- **支持重载**
|
||||
- **支持UUID**
|
||||
- 命令支持给玩家**添加**、**设置**、**移除**、查询自身权限包时间
|
||||
- **命令支持给玩家添加、设置、移除、查询自身权限包时间**
|
||||
- 添加、设置、移除-命令执行失败记录
|
||||
- 手动删除过期的数据
|
||||
- 调用vault API 设置玩家权限(登录时、游戏中、退出时)
|
||||
|
@ -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")) {
|
||||
|
@ -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 + "天"));
|
@ -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<PlayerDataBean> 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 + "此命令只能玩家执行"));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package gg.frog.mc.permissionstime.command;
|
||||
package gg.frog.mc.permissionstime.command.packages;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
@ -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()));
|
||||
}
|
@ -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()));
|
||||
}
|
@ -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 + "天"));
|
||||
}
|
@ -45,7 +45,7 @@ public interface IPlayerDataService {
|
||||
* @return
|
||||
*/
|
||||
List<PlayerDataBean> queryPlayerData(String uuid) throws Exception;
|
||||
|
||||
PlayerDataBean queryPlayerData(String uuid, String packageName) throws Exception;
|
||||
List<PlayerDataBean> queryNotExpirePlayerData(String uuid) throws Exception;
|
||||
|
||||
}
|
||||
|
@ -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<PlayerDataBean> 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 {
|
||||
|
@ -150,6 +150,28 @@ public class SqlitePlayerDataService extends DatabaseUtil implements IPlayerData
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlayerDataBean> queryNotExpirePlayerData(String uuid) throws Exception {
|
||||
long now = new Date().getTime();
|
||||
String sql = "SELECT * FROM \"playerData\" where (\"uuid\"='" + uuid + "' AND \"expire\" > " + now + ");";
|
||||
try {
|
||||
List<PlayerDataBean> 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 + "');";
|
||||
|
@ -18,6 +18,8 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
|
||||
private String displayName = null;
|
||||
private Integer days = null;
|
||||
private Boolean global = null;
|
||||
private List<String> worlds = new ArrayList<>();
|
||||
private List<String> permissions = new ArrayList<>();
|
||||
private List<String> groups = new ArrayList<>();
|
||||
private List<String> 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<String> getWorlds() {
|
||||
return worlds;
|
||||
}
|
||||
|
||||
public void setWorlds(List<String> worlds) {
|
||||
this.worlds = worlds;
|
||||
}
|
||||
|
||||
public List<String> 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 + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,10 @@ packages:
|
||||
displayName: '权限包模板1'
|
||||
#权限包时间(单位: 天)
|
||||
days: 10
|
||||
#是否跨服权限
|
||||
global: false
|
||||
#单世界权限需要修改
|
||||
worlds: []
|
||||
#权限包含有的权限
|
||||
permissions:
|
||||
- permission1
|
||||
|
Loading…
Reference in New Issue
Block a user