mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2025-09-06 11:06:58 +00:00
新功能 + BUG fix
检测是否有新版本 提示权限包到期 玩家登录时删除过期的或无效数据
This commit is contained in:
@ -18,6 +18,7 @@ import gg.frog.mc.permissionstime.database.SqlManager;
|
||||
import gg.frog.mc.permissionstime.listener.MainListener;
|
||||
import gg.frog.mc.permissionstime.utils.FileUtil;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
import gg.frog.mc.permissionstime.utils.UpdateCheck;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
public class PluginMain extends JavaPlugin {
|
||||
@ -59,6 +60,7 @@ public class PluginMain extends JavaPlugin {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
getServer().getScheduler().runTask(pm, new UpdateCheck(pm));
|
||||
getServer().getScheduler().runTask(pm, new Runnable() {
|
||||
public void run() {
|
||||
if (!checkPluginDepends()) {
|
||||
|
56
src/main/gg/frog/mc/permissionstime/command/GetCmd.java
Normal file
56
src/main/gg/frog/mc/permissionstime/command/GetCmd.java
Normal 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."));
|
||||
}
|
||||
}
|
||||
}
|
@ -39,10 +39,6 @@ public class GiveCmd implements Runnable {
|
||||
int days = 0;
|
||||
try {
|
||||
days = Integer.parseInt(time);
|
||||
if (days <= 0) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DAYS_PARAMETER_INCORRECT));
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DAYS_PARAMETER_INCORRECT));
|
||||
return;
|
||||
@ -86,6 +82,7 @@ public class GiveCmd implements Runnable {
|
||||
}
|
||||
} else {
|
||||
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."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +90,11 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
SetCmd setCmd = new SetCmd(pm, sender, args);
|
||||
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")) {
|
||||
if (hasPermission(sender, isPlayer, "permissionstime.remove")) {
|
||||
RemoveCmd removeCmd = new RemoveCmd(pm, sender, args);
|
||||
@ -115,27 +120,30 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
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"))) {
|
||||
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")) {
|
||||
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")) {
|
||||
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")) {
|
||||
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")) {
|
||||
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")) {
|
||||
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")) {
|
||||
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));
|
||||
}
|
||||
@ -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"))) {
|
||||
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"))) {
|
||||
tipList.add("remove");
|
||||
}
|
||||
@ -191,7 +202,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
||||
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;
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
|
@ -43,6 +43,7 @@ public class MeCmd implements Runnable {
|
||||
}
|
||||
} else {
|
||||
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 {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Only player can use this command."));
|
||||
|
@ -39,6 +39,9 @@ public class PackagesCmd implements Runnable {
|
||||
} else {
|
||||
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."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ public class RemoveAllCmd implements Runnable {
|
||||
}
|
||||
} else {
|
||||
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."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ public class RemoveCmd implements Runnable {
|
||||
}
|
||||
} else {
|
||||
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."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,10 +39,6 @@ public class SetCmd implements Runnable {
|
||||
int days = 0;
|
||||
try {
|
||||
days = Integer.parseInt(time);
|
||||
if (days <= 0) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DAYS_PARAMETER_INCORRECT));
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DAYS_PARAMETER_INCORRECT));
|
||||
return;
|
||||
@ -86,6 +82,7 @@ public class SetCmd implements Runnable {
|
||||
}
|
||||
} else {
|
||||
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."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,10 @@ public class LangCfg extends PluginConfig {
|
||||
public static String MSG_TELL_DEL_ALL = null;
|
||||
public static String MSG_DEL_ALL = 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) {
|
||||
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_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_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.");
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ public interface IPlayerDataDao {
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
boolean delPlayData(Long id) throws Exception;
|
||||
boolean delPlayData(String uuid) throws Exception;
|
||||
|
||||
boolean delPlayData(String uuid, String packageName) throws Exception;
|
||||
|
||||
/**
|
||||
|
@ -50,6 +50,17 @@ public class SqlManager {
|
||||
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) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
@ -112,4 +123,17 @@ public class SqlManager {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
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 + "';";
|
||||
|
@ -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
|
||||
public boolean delPlayData(String uuid) throws Exception {
|
||||
String sql = "DELETE FROM \"main\".\"playerData\" WHERE (\"uuid\"='" + uuid + "');";
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
@ -254,10 +255,8 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
subPpb.clearPlayer(player, plugin.getServer(), plugin.getPermission());
|
||||
addPpb.givePlayer(player, plugin.getServer(), plugin.getPermission());
|
||||
}
|
||||
checkExpire(player, plugin);
|
||||
BukkitTask task = taskMap.get(player.getUniqueId().toString());
|
||||
if (task != null) {
|
||||
plugin.getServer().getScheduler().cancelTask(task.getTaskId());
|
||||
}
|
||||
if (pdbList.size() > 0) {
|
||||
delay = (delay / 1000 + 1) * 20;// 1秒=20ticks
|
||||
task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
@ -286,4 +285,24 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
src/main/gg/frog/mc/permissionstime/utils/UpdateCheck.java
Normal file
38
src/main/gg/frog/mc/permissionstime/utils/UpdateCheck.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user