1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-22 07:28:47 +00:00

新功能 + BUG fix

检测是否有新版本
提示权限包到期
玩家登录时删除过期的或无效数据
This commit is contained in:
GeekFrog 2017-07-24 00:30:46 +08:00
parent 58349ee8c7
commit 8bc004eb12
22 changed files with 573 additions and 28 deletions

View File

@ -46,7 +46,10 @@
- **支持自定义哪个玩家的头颅** - **支持自定义哪个玩家的头颅**
- **支持物品发光(附魔效果)** - **支持物品发光(附魔效果)**
- **玩家进入游戏时赋予权限更早** - **玩家进入游戏时赋予权限更早**
- 手动删除过期的或无效数据 - **管理员查看玩家到期时间**
- **检测是否有新版本**
- **提示权限包到期**
- **玩家登录时删除过期的或无效数据**
- 取消前置插件 - 取消前置插件

View File

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

View File

@ -18,6 +18,7 @@ import gg.frog.mc.permissionstime.database.SqlManager;
import gg.frog.mc.permissionstime.listener.MainListener; import gg.frog.mc.permissionstime.listener.MainListener;
import gg.frog.mc.permissionstime.utils.FileUtil; import gg.frog.mc.permissionstime.utils.FileUtil;
import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.StrUtil;
import gg.frog.mc.permissionstime.utils.UpdateCheck;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
public class PluginMain extends JavaPlugin { public class PluginMain extends JavaPlugin {
@ -59,6 +60,7 @@ public class PluginMain extends JavaPlugin {
e.printStackTrace(); e.printStackTrace();
} }
} }
getServer().getScheduler().runTask(pm, new UpdateCheck(pm));
getServer().getScheduler().runTask(pm, new Runnable() { getServer().getScheduler().runTask(pm, new Runnable() {
public void run() { public void run() {
if (!checkPluginDepends()) { if (!checkPluginDepends()) {

View File

@ -0,0 +1,56 @@
package gg.frog.mc.permissionstime.command;
import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
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;
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 GetCmd implements Runnable {
private PluginMain pm;
private SqlManager sm;
private String[] args;
private CommandSender sender;
public GetCmd(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) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
OfflinePlayer p = pm.getOfflinePlayer(args[1]);
List<PlayerDataBean> ps = sm.getTime(p.getUniqueId().toString());
if (ps.size() > 0) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NUM_OF_PACKAGES, args[1], ps.size()));
for (PlayerDataBean pdb : ps) {
String expireString = StrUtil.timestampToString(pdb.getExpire());
PermissionPackageBean pc = PackagesCfg.PACKAGES.get(pdb.getPackageName());
if (pc != null) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_EXPIRATION_DATE, pdb.getGlobal() ? "*" : "", pc.getDisplayName(), pdb.getPackageName(), expireString));
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_EXPIRATION_DATE, pdb.getGlobal() ? "*" : "", LangCfg.MSG_UNKNOWN_PACKAGE, pdb.getPackageName(), expireString));
}
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_DATA));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " get <playerName> \n&8 - View player packages."));
}
}
}

View File

@ -39,10 +39,6 @@ public class GiveCmd implements Runnable {
int days = 0; int days = 0;
try { try {
days = Integer.parseInt(time); days = Integer.parseInt(time);
if (days <= 0) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DAYS_PARAMETER_INCORRECT));
return;
}
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DAYS_PARAMETER_INCORRECT)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DAYS_PARAMETER_INCORRECT));
return; return;
@ -86,6 +82,7 @@ public class GiveCmd implements Runnable {
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " give <playerName> <packageName> <time> \n&8 - Give player package <time>day."));
} }
} }
} }

View File

@ -90,6 +90,11 @@ public class MainCommand implements CommandExecutor, TabCompleter {
SetCmd setCmd = new SetCmd(pm, sender, args); SetCmd setCmd = new SetCmd(pm, sender, args);
new Thread(setCmd).start(); new Thread(setCmd).start();
} }
} else if (args[0].equalsIgnoreCase("get")) {
if (hasPermission(sender, isPlayer, "permissionstime.get")) {
GetCmd getCmd = new GetCmd(pm, sender, args);
new Thread(getCmd).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")) {
RemoveCmd removeCmd = new RemoveCmd(pm, sender, args); RemoveCmd removeCmd = new RemoveCmd(pm, sender, args);
@ -115,27 +120,30 @@ public class MainCommand implements CommandExecutor, TabCompleter {
} }
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 + (pm.getDescription().getCommands().containsKey("pt") ? " Aliases:/pt" : "") + " =====")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "\n&a===== " + pm.PLUGIN_NAME + " Version:" + pm.PLUGIN_VERSION + (pm.getDescription().getCommands().containsKey("pt") ? " Aliases:/pt" : "") + " ====="));
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("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " me \n&8 - 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("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " packages [packageName] \n&8 - 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("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " give <playerName> <packageName> <time> \n&8 - Give player package <time>day."));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".set")) { if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".set")) {
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " set <playerName> <packageName> <time> \n - Set player package <time>day.")); sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " set <playerName> <packageName> <time> \n&8 - Set player package <time>day."));
}
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".get")) {
sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " get <playerName> \n&8 - View player packages."));
} }
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> [t/f delGlobal] \n - Remove player package.")); sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " remove <playerName> <packageName> [t/f delGlobal] \n&8 - Remove player package."));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall")) { if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".removeall")) {
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " removeall <playerName> [t/f delGlobal] \n - Remove player all package.")); sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " removeall <playerName> [t/f delGlobal] \n&8 - Remove player all package."));
} }
if (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".reload")) { 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("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " reload \n&8 -Reloads the config file."));
} }
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
} }
@ -173,6 +181,9 @@ public class MainCommand implements CommandExecutor, TabCompleter {
if ("set".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + "set"))) { if ("set".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + "set"))) {
tipList.add("set"); tipList.add("set");
} }
if ("get".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + "get"))) {
tipList.add("get");
}
if ("remove".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove"))) { if ("remove".startsWith(args[0]) && (!isPlayer || sender.isOp() || sender.hasPermission(pm.PLUGIN_NAME_LOWER_CASE + ".remove"))) {
tipList.add("remove"); tipList.add("remove");
} }
@ -191,7 +202,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
tipList.add(name); tipList.add(name);
} }
} }
} else if ("give".equals(args[0]) || "set".equals(args[0]) || "remove".equals(args[0]) || "removeall".equals(args[0])) { } else if ("give".equals(args[0]) || "set".equals(args[0]) || "get".equals(args[0]) || "remove".equals(args[0]) || "removeall".equals(args[0])) {
return null; return null;
} }
} else if (args.length == 3) { } else if (args.length == 3) {

View File

@ -43,6 +43,7 @@ public class MeCmd implements Runnable {
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " me \n&8 - View self package."));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Only player can use this command.")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Only player can use this command."));

View File

@ -39,6 +39,9 @@ public class PackagesCmd implements Runnable {
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName));
} }
}else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " packages [packageName] \n&8 - View packages."));
} }
} }
} }

View File

@ -71,6 +71,7 @@ public class RemoveAllCmd implements Runnable {
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " removeall <playerName> [t/f delGlobal] \n&8 - Remove player all package."));
} }
} }
} }

View File

@ -78,6 +78,7 @@ public class RemoveCmd implements Runnable {
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " remove <playerName> <packageName> [t/f delGlobal] \n&8 - Remove player package."));
} }
} }
} }

View File

@ -39,10 +39,6 @@ public class SetCmd implements Runnable {
int days = 0; int days = 0;
try { try {
days = Integer.parseInt(time); days = Integer.parseInt(time);
if (days <= 0) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DAYS_PARAMETER_INCORRECT));
return;
}
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DAYS_PARAMETER_INCORRECT)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DAYS_PARAMETER_INCORRECT));
return; return;
@ -86,6 +82,7 @@ public class SetCmd implements Runnable {
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " set <playerName> <packageName> <time> \n&8 - Set player package <time>day."));
} }
} }
} }

View File

@ -37,6 +37,10 @@ public class LangCfg extends PluginConfig {
public static String MSG_TELL_DEL_ALL = null; public static String MSG_TELL_DEL_ALL = null;
public static String MSG_DEL_ALL = null; public static String MSG_DEL_ALL = null;
public static String MSG_DEL_ALL_FAIL = null; public static String MSG_DEL_ALL_FAIL = null;
public static String MSG_NUM_OF_PACKAGES = null;
public static String MSG_EXPIRATION_DATE = null;
public static String MSG_UNKNOWN_PACKAGE = null;
public static String MSG_IS_EXPIRATION_DATE = null;
public LangCfg(String fileName, PluginMain pm) { public LangCfg(String fileName, PluginMain pm) {
super(fileName, pm); super(fileName, pm);
@ -73,5 +77,9 @@ public class LangCfg extends PluginConfig {
MSG_TELL_DEL_ALL = getConfig().getString("msg.tellDelAll", "&4{0} remove all your packages"); MSG_TELL_DEL_ALL = getConfig().getString("msg.tellDelAll", "&4{0} remove all your packages");
MSG_DEL_ALL = getConfig().getString("msg.delAll", "&2Remove all packages for player {0}"); MSG_DEL_ALL = getConfig().getString("msg.delAll", "&2Remove all packages for player {0}");
MSG_DEL_ALL_FAIL = getConfig().getString("msg.delAllFail", "&4Failed to remove all packages for player {0}"); MSG_DEL_ALL_FAIL = getConfig().getString("msg.delAllFail", "&4Failed to remove all packages for player {0}");
MSG_NUM_OF_PACKAGES = getConfig().getString("msg.numOfPackages", "====={0} has {1} packages=====");
MSG_EXPIRATION_DATE = getConfig().getString("msg.expirationDate", "{0}packages: {1}({2}), Expiration date: {3}");
MSG_UNKNOWN_PACKAGE = getConfig().getString("msg.unknownPackage", "Unknown Packages");
MSG_IS_EXPIRATION_DATE = getConfig().getString("msg.isExpirationDate", "Your package: {0}({1})&r has expired.");
} }
} }

View File

@ -37,8 +37,8 @@ public interface IPlayerDataDao {
/** /**
* 删除 * 删除
*/ */
boolean delPlayData(Long id) throws Exception;
boolean delPlayData(String uuid) throws Exception; boolean delPlayData(String uuid) throws Exception;
boolean delPlayData(String uuid, String packageName) throws Exception; boolean delPlayData(String uuid, String packageName) throws Exception;
/** /**

View File

@ -50,6 +50,17 @@ public class SqlManager {
return false; return false;
} }
public List<PlayerDataBean> getAllTime(String uuid) {
for (int i = 0; i < 3; i++) {
try {
return pds.queryPlayerData(uuid);
} catch (Exception e) {
e.printStackTrace();
}
}
return Collections.emptyList();
}
public List<PlayerDataBean> getTime(String uuid) { public List<PlayerDataBean> getTime(String uuid) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
try { try {
@ -112,4 +123,17 @@ public class SqlManager {
} }
return false; return false;
} }
public boolean delById(Long id) {
for (int i = 0; i < 3; i++) {
try {
if (pds.delPlayData(id)) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
} }

View File

@ -216,6 +216,18 @@ public class MySQLPlayerDataDao extends DatabaseUtil implements IPlayerDataDao {
} }
} }
@Override
public boolean delPlayData(Long id) throws Exception {
String sql = "DELETE FROM `" + PluginCfg.SQL_TABLE_PREFIX + "playerData` WHERE `id`='" + id + "' AND (`serverId`='" + PluginCfg.SQL_SERVER_ID + "' OR `serverId` IS NULL);";
try {
getDB().query(sql);
return true;
} catch (Exception e) {
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Can't delete data by ID: {0}", id));
throw e;
}
}
@Override @Override
public boolean delPlayData(String uuid) throws Exception { public boolean delPlayData(String uuid) throws Exception {
String sql = "DELETE FROM `" + PluginCfg.SQL_TABLE_PREFIX + "playerData` WHERE `uuid`='" + uuid + "' AND `serverId`='" + PluginCfg.SQL_SERVER_ID + "';"; String sql = "DELETE FROM `" + PluginCfg.SQL_TABLE_PREFIX + "playerData` WHERE `uuid`='" + uuid + "' AND `serverId`='" + PluginCfg.SQL_SERVER_ID + "';";

View File

@ -175,6 +175,18 @@ public class SqlitePlayerDataDao extends DatabaseUtil implements IPlayerDataDao
} }
} }
@Override
public boolean delPlayData(Long id) throws Exception {
String sql = "DELETE FROM \"main\".\"playerData\" WHERE (\"id\"='" + id + "');";
try {
getDB().query(sql);
return true;
} catch (Exception e) {
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Can't delete data by ID: {0}", id));
throw e;
}
}
@Override @Override
public boolean delPlayData(String uuid) throws Exception { public boolean delPlayData(String uuid) throws Exception {
String sql = "DELETE FROM \"main\".\"playerData\" WHERE (\"uuid\"='" + uuid + "');"; String sql = "DELETE FROM \"main\".\"playerData\" WHERE (\"uuid\"='" + uuid + "');";

View File

@ -11,6 +11,7 @@ import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
@ -254,10 +255,8 @@ public class PermissionPackageBean implements IConfigBean {
subPpb.clearPlayer(player, plugin.getServer(), plugin.getPermission()); subPpb.clearPlayer(player, plugin.getServer(), plugin.getPermission());
addPpb.givePlayer(player, plugin.getServer(), plugin.getPermission()); addPpb.givePlayer(player, plugin.getServer(), plugin.getPermission());
} }
checkExpire(player, plugin);
BukkitTask task = taskMap.get(player.getUniqueId().toString()); BukkitTask task = taskMap.get(player.getUniqueId().toString());
if (task != null) {
plugin.getServer().getScheduler().cancelTask(task.getTaskId());
}
if (pdbList.size() > 0) { if (pdbList.size() > 0) {
delay = (delay / 1000 + 1) * 20;// 1秒=20ticks delay = (delay / 1000 + 1) * 20;// 1秒=20ticks
task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@ -286,4 +285,24 @@ public class PermissionPackageBean implements IConfigBean {
plugin.getServer().getScheduler().cancelTask(task.getTaskId()); plugin.getServer().getScheduler().cancelTask(task.getTaskId());
} }
} }
public static void checkExpire(OfflinePlayer player, PluginMain plugin) {
List<PlayerDataBean> playerDataList = plugin.getSqlManager().getAllTime(player.getUniqueId().toString());
long now = new Date().getTime();
for (PlayerDataBean playerData : playerDataList) {
if (playerData.getExpire() < now) {
PermissionPackageBean packageBean = PackagesCfg.PACKAGES.get(playerData.getPackageName());
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Player p = player.getPlayer();
if (p != null) {
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4你的权限包: &r{0}({1}), 已到期.", packageBean != null ? packageBean.getDisplayName() : LangCfg.MSG_UNKNOWN_PACKAGE, playerData.getPackageName()));
}
}
});
plugin.getSqlManager().delById(playerData.getId());
}
}
}
} }

View File

@ -0,0 +1,38 @@
package gg.frog.mc.permissionstime.utils;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.bukkit.configuration.file.YamlConfiguration;
import com.google.common.base.Charsets;
import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.config.PluginCfg;
public class UpdateCheck implements Runnable {
private static final String pluginInfoUrl = "https://raw.githubusercontent.com/geekfrog/PermissionsTime/master/src/resources/plugin.yml";
private PluginMain pm;
public UpdateCheck(PluginMain pm) {
this.pm = pm;
}
@Override
public void run() {
try {
URL url = new URL(pluginInfoUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
connection.setRequestMethod("GET");
YamlConfiguration tempConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8));
String version = tempConfig.getString("version", pm.PLUGIN_VERSION);
if (!pm.PLUGIN_VERSION.equals(version)) {
pm.getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "There is a new version ''{0}'' of the plugin.", version));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -2,14 +2,12 @@ inventoryName: '&4===Permissions Packages==='
expirationDate: '&4Expiration date: {0}' expirationDate: '&4Expiration date: {0}'
msg: msg:
parameterMismatch: '&4Parameter mismatch.' parameterMismatch: '&4Parameter mismatch.'
daysParameterIncorrect: '&4The number of days is incorrect. Please enter a positive daysParameterIncorrect: '&4The number of days is incorrect. Please enter a positive integer.'
integer.'
processing: '&2Please wait for processing...' processing: '&2Please wait for processing...'
noData: '&4No data for packages.' noData: '&4No data for packages.'
packageNum: '&4There are {0} kinds of permissions packages.' packageNum: '&4There are {0} kinds of permissions packages.'
packageList: '{0}packageName: {1}, displayName: {2}' packageList: '{0}packageName: {1}, displayName: {2}'
packageDetail: 'packageName: {0}, displayName: {1}&r\nPermissions: {2}\nGroups: packageDetail: 'packageName: {0}, displayName: {1}&r\nPermissions: {2}\nGroups: {3}'
{3}'
nopermission: '&4You do not have permission to do this.' nopermission: '&4You do not have permission to do this.'
configReloaded: '&2Configuration overload is complete.' configReloaded: '&2Configuration overload is complete.'
failSetPermission: '&4Failed to modify permissions. Please re-enter the server!' failSetPermission: '&4Failed to modify permissions. Please re-enter the server!'
@ -27,3 +25,7 @@ msg:
tellDelAll: '&4{0} remove all your packages' tellDelAll: '&4{0} remove all your packages'
delAll: '&2Remove all packages for player {0}' delAll: '&2Remove all packages for player {0}'
delAllFail: '&4Failed to remove all packages for player {0}' delAllFail: '&4Failed to remove all packages for player {0}'
numOfPackages: '====={0} has {1} packages====='
expirationDate: '{0}packages: {1}({2}), Expiration date: {3}'
unknownPackage: 'Unknown Packages'
isExpirationDate: 'Your package: {0}({1})&r has expired.'

View File

@ -25,3 +25,7 @@ msg:
tellDelAll: '&4{0}删除了你的所有权限包.' tellDelAll: '&4{0}删除了你的所有权限包.'
delAll: '&2删除玩家 {0} 的所有权限包.' delAll: '&2删除玩家 {0} 的所有权限包.'
delAllFail: '&4未删除玩家 {0} 的 所有权限包.' delAllFail: '&4未删除玩家 {0} 的 所有权限包.'
numOfPackages: '====={0}有{1}个权限包====='
expirationDate: '{0}权限包: {1}({2}), 到期时间: {3}'
unknownPackage: '未知权限包'
isExpirationDate: '你的权限包: {0}({1})&r, 已到期.'

View File

@ -1,6 +1,6 @@
name: PermissionsTime name: PermissionsTime
version: 0.1.3-SNAPSHOT
main: gg.frog.mc.permissionstime.PluginMain main: gg.frog.mc.permissionstime.PluginMain
version: 0.1.2-SNAPSHOT
author: GeekFrog author: GeekFrog
softdepend: softdepend:
- SQLibrary - SQLibrary
@ -15,11 +15,13 @@ commands:
permissions: permissions:
permissionstime.*: permissionstime.*:
description: Gives access to all PermissionsTime commands. description: Gives access to all PermissionsTime commands.
default: op
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.get: true
permissionstime.remove: true permissionstime.remove: true
permissionstime.removeall: true permissionstime.removeall: true
permissionstime.packages: true permissionstime.packages: true
@ -35,6 +37,9 @@ permissions:
permissionstime.set: permissionstime.set:
description: Set player package <time>day. description: Set player package <time>day.
default: op default: op
permissionstime.get:
description: View player packages.
default: op
permissionstime.remove: permissionstime.remove:
description: Remove player package. description: Remove player package.
default: op default: op

349
帖子代码.txt Normal file
View File

@ -0,0 +1,349 @@
[align=center][font=微软雅黑][table=95%][tr=black][td]
[align=center]
[img=400,50]https://i.loli.net/2017/07/18/596cdf5e63a20.png[/img]
[b][size=4][color=#ffffff]—PermissionsTime [/color][/size][/b]
[size=4][color=#ffffff][b]权限限时[/b][/color][/size]
[/align]
[align=center] [/align]
[align=center]
[table=98%,#4169e1]
[tr][td]
[align=center][size=6][color=#ffffff][b]唠叨[/b][/color][/size][/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,gray]
[tr][td]
[align=center][size=4][color=#ffa500][b]这是本人第一个发布的插件, 希望能让大家满意![/b][/color][/size][/align]
[align=center][size=4][color=#dda0dd][b]本插件需要JAVA8[/b][/color][/size][/align]
[align=center][size=4][color=#98fb98][b]下载地址在最下面![/b][/color][/size][/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,#4169e1]
[tr][td]
[align=center][size=6][color=#ffffff][b]前言[/b][/color][/size][/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,gray]
[tr][td]
[size=4][color=#ffffff]
[spoiler]之前开服需要个能对权限限时的插件, 但找了几个不适合我的服务器, 大多不支持UUID, 所以我花了大概2周之间做了这个插件[/spoiler]
[/color][/size]
[align=center]
[b][size=4][color=#9932cc][font=微软雅黑]配合点券商店, 实现点券购买VIP(权限及物品), 氪金服的好选择![/color][/size][/b][br/]
[b][size=4][color=#ffffff][font=微软雅黑]本插件支持 1.7.10-1.12 大部分服务器, 1.9以下服务端的需要把中文配置进行转码, 也可以下载帖子后面的语言文件。[/color][/size][/b]
[/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,#4169e1]
[tr][td]
[align=center][size=6][color=#ffffff][b]功能/特性[/b][/color][/size][/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,gray]
[tr][td]
[size=4][color=#ffffff][b][list]
[*]可在配置文件中编辑权限包(可含有多个权限组和多个权限)
[*]时间可以累加
[*]支持UUID
[*]添加、设置、移除-命令执行失败时自动记录, 方便事后有据可依
[*]支持多世界权限(需要权限插件支持)
[*]支持mysql保存数据
[*]支持跨服
[*]gui显示自己的权限包
[/list][/b][/color][/size]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,#4169e1]
[tr][td]
[align=center][size=6][color=#ffffff][b]插件展示[/b][/color][/size][/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,gray]
[tr][td]
[spoiler]
[attachimg]1101066[/attachimg][br/]
[attachimg]1101067[/attachimg][br/]
[attachimg]1101065[/attachimg]
[/spoiler]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,#4169e1]
[tr][td]
[align=center][size=6][color=#ffffff][b]权限[/b][/color][/size][/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,gray]
[tr][td]
[spoiler][b]
[table=98%]
[tr=#dda0dd][td]权限[/td][td]用途[/td][td]默认权限归属[/td][/tr]
[tr=#f5deb3][td]permissionstime.*[/td][td]插件的全部权限.[/td][td]op默认拥有.[/td][/tr]
[tr=#fffacd][td]permissionstime.me[/td][td]查看你自己拥有的权限包.[/td][td]玩家默认拥有.[/td][/tr]
[tr=#f5deb3][td]permissionstime.packages[/td][td]查看服务器拥有权限包的权限.[/td][td]op默认拥有.[/td][/tr]
[tr=#fffacd][td]permissionstime.give[/td][td]给予玩家权限包使用时间的权限.[/td][td]op默认拥有.[/td][/tr]
[tr=#f5deb3][td]permissionstime.set[/td][td]重置玩家权限包使用时间的权限.[/td][td]op默认拥有.[/td][/tr]
[tr=#fffacd][td]permissionstime.remove[/td][td]删除玩家的某个权限包的权限.[/td][td]op默认拥有.[/td][/tr]
[tr=#f5deb3][td]permissionstime.removeall[/td][td]删除玩家的所有权限包的权限.[/td][td]op默认拥有.[/td][/tr]
[tr=#fffacd][td]permissionstime.reload[/td][td]重载配置的权限.[/td][td]op默认拥有.[/td][/tr]
[/table][/b][/spoiler]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,#4169e1]
[tr][td]
[align=center][size=6][color=#ffffff][b]命令[/b][/color][/size][/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,gray]
[tr][td]
[size=4][color=#98fb98][b]好多人都说命令太长, 其实是[color=#9932cc]有别名[/color]的, 请使用 [size=5][color=#ff0000]/pt[/color][/size][/b][/color][/size][br/]
[spoiler][b]
[table=98%]
[tr=#dda0dd][td]命令[/td][td]用途[/td][/tr]
[tr=#f5deb3][td][i]/permissionstime[/i][/td][td]查看全部命令[/td][/tr]
[tr=#fffacd][td][i]/permissionstime me[/i][/td][td]查看你自己拥有的权限包.[/td][/tr]
[tr=#f5deb3][td][i]/permissionstime packages [权限包名][/i][/td][td]查看服务器拥有的权限包(输入第二个参数可以查看该权限包的详细信息).[/td][/tr]
[tr=#fffacd][td][i]/permissionstime give <玩家名> <权限包名> <天数>[/i][/td][td]给玩家某个权限包N天的使用时间.[/td][/tr]
[tr=#f5deb3][td][i]/permissionstime set <玩家名> <权限包名> <天数>[/i][/td][td]重置玩家某个权限包使用时间为N天.[/td][/tr]
[tr=#fffacd][td][i]/permissionstime remove <玩家名> <权限包名> [是否删除跨服权限 是:t 否:f][/i][/td][td]删除玩家的某个权限包.[/td][/tr]
[tr=#f5deb3][td][i]/permissionstime removeall <玩家名> [是否删除跨服权限 是:t 否:f][/i][/td][td]删除玩家的所有权限包.[/td][/tr]
[tr=#fffacd][td][i]/permissionstime reload[/i][/td][td]重载配置.[/td][/tr]
[/table][/b][/spoiler]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,#4169e1]
[tr][td]
[align=center][size=6][color=#ffffff][b]插件配置[/b][/color][/size][/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,gray]
[tr][td]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,#4169e1]
[tr][td]
[align=center][size=6][color=#ffffff][b]已知问题(作者提醒)[/b][/color][/size][/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,gray]
[tr][td]
[size=4][color=#ffffff][b][list]
[*]如果出现问题一般退出服务器重进就能解决。一次不行再来一次。
[*]插件重载不会重置在线玩家的权限, 如有必要请重启服务器。
[*]玩家每次登陆会重置权限包涉及的权限。请不要单独给予玩家涉及的权限。
[*]服务器关闭时, 插件被禁用的顺序不一, 会导致玩家有权限留存。 如果配置的权限包删掉原来设置的权限(或修改世界), 会导致插件无法清理原有的权限及权限组。(你可以配置一个不使用的权限包, 权限包内含有你想清理的权限及权限组即可。)
[/list][/b][/color][/size]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,#4169e1]
[tr][td]
[align=center][size=6][color=#ffffff][b]更新日志[/b][/color][/size][/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,gray]
[tr][td]
[spoiler][size=4][b]
[url=http://ci.frog.gg/jenkins/job/PermissionsTime/changes]详细的更新记录[/url][br/]
[color=#ffffff]2017年7月19日 V0.1.2[/color]
[quote][color=#000000]1.支持自定义哪个玩家的头颅 1.8+支持[br/]
2.支持物品发光(附魔效果)[br/]
3.玩家进入游戏时赋予权限更早[/color][/quote]
[color=#ffffff]2017年7月17日 V0.1.1[/color]
[quote][color=#000000]1.添加自动补全命令功能[br/]
2.修复多线程导致的蹦服BUG[/color][/quote]
[color=#ffffff]2017年7月16日 V0.1.0[/color]
[quote][color=#000000]插件首次发布!!![/color][/quote]
[/b][/size][/spoiler]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,#4169e1]
[tr][td]
[align=center][size=6][color=#ffffff][b]下载地址[/b][/color][/size][/align]
[/td][/tr]
[/table]
[/align]
[align=center]
[table=98%,gray]
[tr][td]
[color=#ffffff][size=4][b]
[align=center] [url=http://ci.frog.gg/jenkins/job/PermissionsTime/51/]V0.1.2版下载地址[/url][/align]
[align=center]前置插件:[url=https://dev.bukkit.org/projects/vault/files]vault[/url] , [url=https://dev.bukkit.org/projects/sqlibrary/files]sqlibrary[/url][/align]
[align=center]前置插件最好去原站下载适合的版本, 如果无法下载可以在帖内下载。[/align]
[br/]
[align=center][b]帖内下载:[/b][/align]
[align=center][attach]1101088[/attach][/align][align=center][b][color=#ff0000]前置插件必须安装[/color][/b][/align][align=center][attach]1101089[/attach][/align]
[align=center][attach]1101090[/attach][/align]
[align=center][attach]1101110[/attach][/align]
[br/]
[align=center][color=#ff0000][b]如果大家觉得好用就给点金粒吧,如果不好请告诉我,帮助我改进。[/b][/color][/align]
[align=center][b]BUG可以在帖内回复我。[/b][/align]
[/b][/size][/color]
[/td][/tr]
[/table]
[/align]
[/td][/tr][/table][/font][/align]
[spoiler][color=#ffffff]
config.yml
[code]
# 插件提示前缀.
pluginPrefix: '&4[&b限时权限&4]'
# 是否开启DEBUG模式.
debug: false
# 是否同意插件统计信息.
metrics: true
# 语言文件名称 在'lang'文件夹内.
lang: zh-cn
# 数据库相关.
mysql:
# 是否使用MySQL数据库.
enable: false
# 服务器唯一标识, 用来区分权限是哪个服务器的.
serverId: default
hostname: localhost
port: 3306
database: minecraft
username: user
password: '123456'
# 数据库表前缀
tablePrefix: pt_[/code]
packages.yml
[code]
# 配置文件版本.
# Config version.
version: 1.00
# 默认权限组.
# Default permission group.
defaultGroup: Default
packages:
# 权限包名称.
# Permission package name.
example1:
# 权限包显示名称.
# Permission package display name.
displayName: '&4Test Package'
# 显示的物品类型.
# 可以使用id, 但不可与type同时使用.
# 可以定义物品的种类, 特殊的如头颅可以指定哪个玩家的头颅.
# Show the type of item.
# You can use 'id', but you can't use 'type' at the same time.
# You can define the type of item, such as skull can set which player's head.
#id: 397
#type: SKULL_ITEM:5
#type: SKULL_ITEM:MHF_Present1
type: NETHER_STAR
# 是否有附魔发光的特效
glowing: false
# 标签.
# Lores.
lores:
- '&2This is a test lore.'
# 是否跨服权限?
# Is multiple server permission?
global: false
# 权限包含有的权限 world1、world2、world3是赋值给玩家permission2权限的世界.
# 如果所有世界都赋值权限则不用注明世界名称如permission1.
# Package contain permissions.
# Add ':world1' at the end can restrict permissions used in 'world1'.
permissions:
- permission1
- permission2:world1:world2:world3
# 权限包含有的权限组.
# Package contain groups.
groups:
- group1
- group2:world1
[/code]
[font=-apple-system, BlinkMacSystemFont,][color=#000000]简体中文 zh-cn.yml[/color][/font][code]
inventoryName: '&4===权限仓库==='
expirationDate: '&4到期时间: {0}.'
msg:
parameterMismatch: '&4参数不匹配.'
daysParameterIncorrect: '&4时间参数不正确,请输入正整数.'
processing: '&2执行中请等待...'
noData: '&4暂时无权限包.'
packageNum: '&4共有{0}种权限包.'
packageList: '{0}权限包名: {1}, 显示名称: {2}'
packageDetail: '权限包名: {0}, 显示名称: {1}&r\n权限: {2}\n权限组: {3}'
nopermission: '&4你没有权限这么做.'
configReloaded: '&2配置重载完成.'
failSetPermission: '&4修改权限失败, 请重新进入服务器!'
noFindPlayer: '&4找不到名为&2{0}&4的玩家.'
noFindPackage: '&4找不到名为&2{0}&4的权限包.'
tellGivePackage: '&2{0}给予你 {1}天的 {2}.'
givePackage: '&2给予玩家 {0} {1}天的 {2}.'
givePackageFail: '&4未给予玩家 {0} {1}天的 {2}.'
tellSetPackage: '&2{0}设置你 {1}天的 {2}.'
setPackage: '&2设置玩家 {0} {1}天的 {2}.'
setPackageFail: '&4未设置玩家 {0} {1}天的 {2}.'
tellDelPackage: '&4{0}删除了你的 {1}权限包.'
delPackage: '&2删除玩家 {0} 的 {1}.'
delPackageFail: '&4未删除玩家 {0} 的 {1}.'
tellDelAll: '&4{0}删除了你的所有权限包.'
delAll: '&2删除玩家 {0} 的所有权限包.'
delAllFail: '&4未删除玩家 {0} 的 所有权限包.'[/code]
[/color][/spoiler]