1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-25 09:58:50 +00:00

权限包功能

give功能
配置BUG修复
This commit is contained in:
GeekFrog 2017-07-12 05:21:26 +08:00
parent d0e3e86377
commit f00284314f
15 changed files with 334 additions and 97 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>gg.frog.mc</groupId>
<artifactId>permissionstime</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.1-TEST</version>
<packaging>jar</packaging>
<name>PermissionsTime</name>
<description>支持跨服的权限限时插件</description>

View File

@ -2,12 +2,9 @@ package gg.frog.mc.permissionstime.command;
import java.util.UUID;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.config.LangCfg;
import gg.frog.mc.permissionstime.config.PackagesCfg;
import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.database.SqlManager;
@ -17,30 +14,44 @@ import gg.frog.mc.permissionstime.utils.StrUtil;
public class GiveCmd {
private static PluginMain pm = PluginMain.getInstance();
private static SqlManager sm = PluginMain.sm;
public static boolean onCommand(CommandSender sender, Command command, boolean isPlayer, String[] args) {
public static boolean onCommand(CommandSender sender, boolean isPlayer, String[] args) {
if (args.length == 4) {
String playerName = args[1];
String packageName = args[2];
String time = args[3];
int days;
try {
days = Integer.parseInt(time);
if (days <= 0) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数"));
return false;
}
} catch (Exception e) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "时间参数不正确,请输入正整数"));
return false;
}
PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName);
if (pack != null) {
UUID uuid = PluginUtil.getPlayerUUIDByName(playerName);
if (uuid != null) {
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)) {
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()));
}
return true;
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'" + playerName + "'的玩家"));
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'{0}'的玩家", playerName));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'" + packageName + "'的权限包"));
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'{0}'的权限包", packageName));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确" + "<playerName> <packageName> <time>"));
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "参数不正确"));
}
return false;
}

View File

@ -24,14 +24,7 @@ public class MainCommand implements CommandExecutor {
isPlayer = true;
}
if (args.length == 0) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&a===== " + PluginMain.PLUGIN_NAME + " Version:" + PluginMain.PLUGIN_VERSION + " ====="));
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".reload")) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " reload -Reloads the config file."));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".give")) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " give <playerName> <packageName> <time> - Give player package <time>minutes."));
}
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
getHelp(sender, isPlayer);
return true;
} else {
if (args[0].equalsIgnoreCase("reload")) {
@ -49,20 +42,61 @@ public class MainCommand implements CommandExecutor {
}
} else {
pm.getConfigManager().reloadConfig();
sm.updateDatabase();
if (!sm.updateDatabase()) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "数据库异常"));
}
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.CONFIG_RELOADED));
}
return true;
} else if (args[0].equalsIgnoreCase("me")) {
if (hasPermission(sender, isPlayer, "permissionstime.me")) {
return GiveCmd.onCommand(sender, isPlayer, args);
}
} else if (args[0].equalsIgnoreCase("give")) {
if (hasPermission(sender, isPlayer, "permissionstime.give")) {
return GiveCmd.onCommand(sender, command, isPlayer, args);
return GiveCmd.onCommand(sender, isPlayer, args);
}
} else if (args[0].equalsIgnoreCase("set")) {
if (hasPermission(sender, isPlayer, "permissionstime.set")) {
return GiveCmd.onCommand(sender, isPlayer, args);
}
} else if (args[0].equalsIgnoreCase("remove")) {
if (hasPermission(sender, isPlayer, "permissionstime.remove")) {
return GiveCmd.onCommand(sender, isPlayer, args);
}
} else if (args[0].equalsIgnoreCase("packages")) {
if (hasPermission(sender, isPlayer, "permissionstime.packages")) {
return PackagesCmd.onCommand(sender, isPlayer, args);
}
} else {
getHelp(sender, isPlayer);
return true;
}
}
}
return false;
}
private void getHelp(CommandSender sender, boolean isPlayer) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&a===== " + PluginMain.PLUGIN_NAME + " Version:" + PluginMain.PLUGIN_VERSION + " ====="));
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".reload")) {
sender.sendMessage(StrUtil.messageFormat("/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " reload \n\t-Reloads the config file."));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".give")) {
sender.sendMessage(StrUtil.messageFormat("/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " give <playerName> <packageName> <time> \n\t- Give player package <time>day."));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".set")) {
sender.sendMessage(StrUtil.messageFormat("/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " set <playerName> <packageName> <time> \n\t- Set player package <time>day."));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".remove")) {
sender.sendMessage(StrUtil.messageFormat("/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " remove <playerName> <packageName> \n\t- Remove player package."));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(PluginMain.PLUGIN_NAME_LOWER_CASE + ".packages")) {
sender.sendMessage(StrUtil.messageFormat("/" + PluginMain.PLUGIN_NAME_LOWER_CASE + " packages [packageName] \n\t- View packages."));
}
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
}
private boolean hasPermission(CommandSender sender, boolean isPlayer, String permissionPath) {
if (isPlayer) {
Player player = (Player) sender;

View File

@ -0,0 +1,32 @@
package gg.frog.mc.permissionstime.command;
import java.util.Map.Entry;
import org.bukkit.command.CommandSender;
import gg.frog.mc.permissionstime.config.PackagesCfg;
import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
import gg.frog.mc.permissionstime.utils.StrUtil;
public class PackagesCmd {
public static boolean onCommand(CommandSender sender, boolean isPlayer, String[] args) {
if (args.length == 1) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "共有{0}种权限包", PackagesCfg.PACKAGES.size()));
for (Entry<String, PermissionPackageBean> e : PackagesCfg.PACKAGES.entrySet()) {
PermissionPackageBean p = e.getValue();
sender.sendMessage(StrUtil.messageFormat("PackgeName: {0}, DisplayName: {1}", e.getKey(), p.getDisplayName()));
}
} else if (args.length == 2) {
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()));
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "找不到名为'{0}'的权限包",packageName));
}
}
return true;
}
}

View File

@ -71,11 +71,7 @@ public class ConfigManager {
}
os.close();
is.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
} catch (Exception e) {
e.printStackTrace();
}
}

View File

@ -18,19 +18,19 @@ public class PackagesCfg extends PluginConfig {
}
@Override
protected void init() {
}
protected void init() {}
@Override
protected void loadToDo() {
PACKAGES_VERSION = setGetDefault("version", "?");
DEFAULT_GROUP = setGetDefault("defaultGroup", "Default");
PACKAGES = getObjMap("packages", PermissionPackageBean.class);
saveObj("packages", PACKAGES);
if (PluginCfg.IS_DEBUG) {
System.out.println("packages vresion:" + PACKAGES_VERSION);
System.out.println("defaultGroup:" + DEFAULT_GROUP);
for (Entry<String, PermissionPackageBean> p : PACKAGES.entrySet()) {
System.out.println(p);
System.out.println(p.getKey() + ":" + p.getValue());
}
}
}

View File

@ -1,39 +1,51 @@
package gg.frog.mc.permissionstime.database;
import java.sql.SQLException;
import java.util.List;
import gg.frog.mc.permissionstime.model.db.PlayerDataBean;
public interface IPlayerDataService {
/**
* 检查表是否
* 检查表是否
*
* @return
* @throws SQLException
* @throws SQLException
*/
boolean tableExist() throws Exception;
/**
* 创建用户数据表
* @return
* @throws SQLException
*
* @return
* @throws SQLException
*/
boolean creatTable() throws Exception;
/**
* 保存更新用户数据
* @throws Exception
*
* @throws Exception
*/
boolean saveOrUpdatePlayerData(PlayerDataBean bean) throws Exception;
boolean setPlayerData(PlayerDataBean bean) throws Exception;
boolean addTime(String uuid, String packageName, int days) throws Exception;
/**
* 删除
*/
boolean delPlayData(String uuid);
boolean delPlayData(String uuid) throws Exception;
boolean delPlayData(String uuid, String packageName) throws Exception;
/**
* 查询
* @return
*
* @return
*/
PlayerDataBean queryPlayerData(String uuid) throws Exception;
List<PlayerDataBean> queryPlayerData(String uuid) throws Exception;
PlayerDataBean queryPlayerData(String uuid, String packageName) throws Exception;
}

View File

@ -26,7 +26,7 @@ public class SqlManager {
}
public boolean updateDatabase() {
if(db != null && db.isOpen()){
if (db != null && db.isOpen()) {
db.close();
}
if (PluginCfg.USE_MYSQL) {
@ -37,7 +37,7 @@ public class SqlManager {
}
db.open();
try {
if(!pds.tableExist()){
if (!pds.tableExist()) {
pds.creatTable();
}
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX) + "连接数据库成功");
@ -47,4 +47,17 @@ public class SqlManager {
}
return false;
}
public boolean giveTime(String uuid, String packageName, int days) {
for (int i = 0; i < 3; i++) {
try {
if (pds.addTime(uuid, packageName, days)) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
}

View File

@ -1,6 +1,9 @@
package gg.frog.mc.permissionstime.database.impl;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.config.PluginCfg;
@ -15,7 +18,7 @@ public class SqlitePlayerDataService extends DatabaseUtil implements IPlayerData
@Override
public boolean tableExist() throws Exception {
String sql = "SELECT count(*) AS num FROM \"main\".sqlite_master M where tbl_name='playerData';";
String sql = "SELECT count(*) AS num FROM \"main\".sqlite_master M where (tbl_name='playerData' AND type='table');";
try {
ResultSet rs = getDB().query(sql);
int num = rs.getInt("num");
@ -24,50 +27,132 @@ public class SqlitePlayerDataService extends DatabaseUtil implements IPlayerData
}
return false;
} catch (Exception e) {
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX) + "无法检查有无数据表");
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "无法检查有无数据表"));
throw e;
}
}
@Override
public boolean creatTable() throws Exception {
String sql = "CREATE TABLE \"main\".\"playerData\" ( \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, \"uuid\" TEXT NOT NULL, \"packageName\" TEXT NOT NULL, \"expire\" INTEGER NOT NULL )";
String sql = "CREATE TABLE \"playerData\" ( \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, \"uuid\" TEXT NOT NULL, \"packageName\" TEXT NOT NULL, \"expire\" INTEGER NOT NULL, CONSTRAINT \"UUID_PACKAGE\" UNIQUE (\"uuid\", \"packageName\"));";
try {
getDB().query(sql);
return true;
} catch (Exception e) {
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX) + "无法创建数据表");
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "无法创建数据表"));
throw e;
}
}
@Override
public boolean saveOrUpdatePlayerData(PlayerDataBean bean) throws Exception {
if(bean.getId()!=null){
}else{
public boolean setPlayerData(PlayerDataBean bean) throws Exception {
PlayerDataBean pdb = bean;
String sql;
if (pdb.getId() != null) {
sql = "UPDATE \"main\".\"playerData\" SET \"uuid\"='" + pdb.getUuid() + "', \"packageName\"='" + pdb.getPackageName() + "', \"expire\"=" + pdb.getExpire() + " WHERE (\"id\"=" + pdb.getId() + ");";
} else {
sql = "INSERT INTO \"main\".\"playerData\" (\"uuid\", \"packageName\", \"expire\") VALUES ('" + pdb.getUuid() + "', '" + pdb.getPackageName() + "', " + pdb.getExpire() + ");";
}
String sql = "CREATE TABLE \"main\".\"playerData\" ( \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, \"uuid\" TEXT NOT NULL, \"packageName\" TEXT NOT NULL, \"expire\" INTEGER NOT NULL )";
try {
getDB().query(sql);
return true;
} catch (Exception e) {
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX) + "无法创建数据");
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "无法创建数据: {0}", pdb));
throw e;
}
}
@Override
public boolean delPlayData(String uuid) {
return false;
// TODO Auto-generated method stub
public boolean addTime(String uuid, String packageName, int days) throws Exception {
PlayerDataBean pdb = queryPlayerData(uuid, packageName);
long now = new Date().getTime();
long addTime = days * 24 * 60 * 60 * 1000;
long expire = 0;
if (pdb == null) {
expire = now + addTime;
pdb = new PlayerDataBean(null, uuid, packageName, expire);
return setPlayerData(pdb);
} else {
if (pdb.getExpire() < now) {
expire = now + addTime;
pdb.setExpire(expire);
return setPlayerData(pdb);
} else {
String sql = "UPDATE \"main\".\"playerData\" SET \"expire\"=\"expire\"+" + addTime + " WHERE (\"id\"=" + pdb.getId() + ");";
try {
getDB().query(sql);
return true;
} catch (Exception e) {
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "无法更新数据: {0}", pdb));
throw e;
}
}
}
}
@Override
public PlayerDataBean queryPlayerData(String uuid) {
return null;
public List<PlayerDataBean> queryPlayerData(String uuid) throws Exception {
String sql = "SELECT * FROM \"playerData\" where (\"uuid\"='" + uuid + "');";
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 PlayerDataBean queryPlayerData(String uuid, String packageName) throws Exception {
String sql = "SELECT * FROM \"playerData\" where (\"uuid\"='" + uuid + "' AND \"packageName\"='" + packageName + "');";
try {
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);
return tpd;
}
return null;
} catch (Exception e) {
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "无法查询UUID: {0}, packageName: {1} 的数据", uuid, packageName));
throw e;
}
}
@Override
public boolean delPlayData(String uuid) throws Exception {
String sql = "DELETE FROM \"main\".\"playerData\" WHERE (\"uuid\"='" + uuid + "');";
try {
getDB().query(sql);
return true;
} catch (Exception e) {
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "无法删除UUID为: {0} 的数据", uuid));
throw e;
}
}
@Override
public boolean delPlayData(String uuid, String packageName) throws Exception {
String sql = "DELETE FROM \"main\".\"playerData\" WHERE (\"uuid\"='" + uuid + "' AND \"packageName\"='" + packageName + "');";
try {
getDB().query(sql);
return true;
} catch (Exception e) {
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "无法删除UUID: {0}, packageName: {1} 的数据", uuid, packageName));
throw e;
}
}
}

View File

@ -16,11 +16,29 @@ import gg.frog.mc.permissionstime.utils.config.IConfigBean;
*/
public class PermissionPackageBean implements IConfigBean {
private String displayName = null;
private Integer days = null;
private List<String> permissions = new ArrayList<>();
private List<String> groups = new ArrayList<>();
private List<String> prefixs = new ArrayList<>();
private List<String> suffixs = new ArrayList<>();
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public Integer getDays() {
return days;
}
public void setDays(Integer days) {
this.days = days;
}
public List<String> getPermissions() {
return permissions;
}
@ -56,6 +74,8 @@ public class PermissionPackageBean implements IConfigBean {
@Override
public YamlConfiguration toConfig() {
YamlConfiguration config = new YamlConfiguration();
config.set("displayName", displayName);
config.set("days", days);
config.set("permissions", permissions);
config.set("groups", groups);
config.set("prefixs", prefixs);
@ -65,6 +85,11 @@ public class PermissionPackageBean implements IConfigBean {
@Override
public void toConfigBean(MemorySection config) {
displayName = config.getString("displayName");
if (displayName == null) {
displayName = "No Name";
}
days = config.getInt("days");
permissions = config.getStringList("permissions");
groups = config.getStringList("groups");
prefixs = config.getStringList("prefixs");
@ -73,6 +98,6 @@ public class PermissionPackageBean implements IConfigBean {
@Override
public String toString() {
return "PermissionPackageBean [permissions=" + permissions + ", groups=" + groups + ", prefixs=" + prefixs + ", suffixs=" + suffixs + "]";
return "PermissionPackageBean [displayName=" + displayName + ", days=" + days + ", permissions=" + permissions + ", groups=" + groups + ", prefixs=" + prefixs + ", suffixs=" + suffixs + "]";
}
}

View File

@ -2,35 +2,57 @@ package gg.frog.mc.permissionstime.model.db;
public class PlayerDataBean {
private Integer id;
private Long id;
private String uuid;
private String packageName;
private Integer expire;
public Integer getId() {
private Long expire;
public PlayerDataBean() {
super();
}
public PlayerDataBean(Long id, String uuid, String packageName, Long expire) {
super();
this.id = id;
this.uuid = uuid;
this.packageName = packageName;
this.expire = expire;
}
public Long getId() {
return id;
}
public void setId(Integer id) {
public void setId(Long id) {
this.id = id;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public Integer getExpire() {
public Long getExpire() {
return expire;
}
public void setExpire(Integer expire) {
public void setExpire(Long expire) {
this.expire = expire;
}
@Override
public String toString() {
return "PlayerDataBean [id=" + id + ", uuid=" + uuid + ", packageName=" + packageName + ", expire=" + expire + "]";
}
}

View File

@ -5,6 +5,6 @@ import java.text.MessageFormat;
public class StrUtil {
public static String messageFormat(String src, Object... args){
return MessageFormat.format(src.replace("&", "§"), args);
return MessageFormat.format(src, args).replace("&", "§");
}
}

View File

@ -80,7 +80,7 @@ public abstract class PluginConfig {
*/
private FileConfiguration getConfig(File folder, String fileName) {
if (config == null) {
reloadConfig(folder, fileName);
reloadConfig(folder, fileName, true);
}
return config;
}
@ -104,7 +104,7 @@ public abstract class PluginConfig {
PluginMain.LOG.log(Level.SEVERE, "Could not save config to " + configFile, ex);
}
}
public void saveAndReloadConfig() {
try {
getConfig().save(configFile);
@ -118,20 +118,22 @@ public abstract class PluginConfig {
* 配置重载
*/
public void reloadConfig() {
reloadConfig(folder, fileName);
reloadConfig(folder, fileName, false);
}
/**
* 配置重载
*/
private void reloadConfig(File folder, String fileName) {
private void reloadConfig(File folder, String fileName, boolean useRes) {
config = YamlConfiguration.loadConfiguration(configFile);
final InputStream defConfigStream = PluginMain.getInstance().getResource(fileName);
if (defConfigStream == null) {
return;
if (useRes) {
final InputStream defConfigStream = PluginMain.getInstance().getResource(fileName);
if (defConfigStream == null) {
return;
}
config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
}
config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
loadToDo();
saveConfig();
}
@ -167,31 +169,31 @@ public abstract class PluginConfig {
T bean = clazz.newInstance();
bean.toConfigBean((MemorySection) beanConfig);
return bean;
} catch (InstantiationException | IllegalAccessException e) {
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
protected String setGetDefault(String path, String def){
if(!getConfig().contains(path)){
protected String setGetDefault(String path, String def) {
if (!getConfig().contains(path)) {
getConfig().set(path, def);
return def;
}
return getConfig().getString(path);
}
protected int setGetDefault(String path, int def){
if(!getConfig().contains(path)){
protected int setGetDefault(String path, int def) {
if (!getConfig().contains(path)) {
getConfig().set(path, def);
return def;
}
return getConfig().getInt(path);
}
protected boolean setGetDefault(String path, boolean def){
if(!getConfig().contains(path)){
protected boolean setGetDefault(String path, boolean def) {
if (!getConfig().contains(path)) {
getConfig().set(path, def);
return def;
}

View File

@ -3,7 +3,11 @@ defaultGroup: Default
packages:
#权限包名称
example1:
#权限包含有的权限
#权限包显示名称
displayName: '权限包模板1'
#权限包时间(单位: 天)
days: 10
#权限包含有的权限
permissions:
- permission1
- permission2

View File

@ -12,28 +12,29 @@ permissions:
permissionstime.*:
description: Gives access to all PermissionsTime commands.
children:
permissionstime.me: true
permissionstime.reload: true
permissionstime.give: true
permissionstime.set: true
permissionstime.remove: true
permissionstime.package: true
permissionstime.packages: true
permissionstime.reload: true
permissionstime.me:
description: View himself package.
default: default
default: true
permissionstime.reload:
description: Reloads the config file.
default: op
permissionstime.give:
description: Give player package <time>minutes.
description: Give player package <time>day.
default: op
permissionstime.set:
description: Set player package <time>minutes.
description: Set player package <time>day.
default: op
permissionstime.remove:
description: Remove player package.
default: op
permissionstime.package:
permissionstime.packages:
description: View packages.
default: op