diff --git a/README.md b/README.md index 9b660ad..78dd713 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ - **检测是否有新版本** - **提示权限包到期** - **玩家登录时删除过期的或无效数据** +- **提示剩余时间** - 取消前置插件 diff --git a/pom.xml b/pom.xml index 63afa98..c28d910 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 gg.frog.mc permissionstime - 0.2.1-SNAPSHOT + 0.2.2-SNAPSHOT jar PermissionsTime 支持跨服的权限限时插件 diff --git a/src/main/gg/frog/mc/permissionstime/command/GetCmd.java b/src/main/gg/frog/mc/permissionstime/command/GetCmd.java index d7e77e9..c486bc2 100644 --- a/src/main/gg/frog/mc/permissionstime/command/GetCmd.java +++ b/src/main/gg/frog/mc/permissionstime/command/GetCmd.java @@ -41,9 +41,9 @@ public class GetCmd implements Runnable { 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)); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_EXPIRATION_DATE, pdb.getGlobal() ? "*" : "", pc.getDisplayName(), pdb.getPackageName(), expireString, StrUtil.getLeftTime(pdb.getExpire()))); } else { - sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_EXPIRATION_DATE, pdb.getGlobal() ? "*" : "", LangCfg.MSG_UNKNOWN_PACKAGE, pdb.getPackageName(), expireString)); + sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_EXPIRATION_DATE, pdb.getGlobal() ? "*" : "", LangCfg.MSG_UNKNOWN_PACKAGE, pdb.getPackageName(), expireString, StrUtil.getLeftTime(pdb.getExpire()))); } } } else { diff --git a/src/main/gg/frog/mc/permissionstime/config/LangCfg.java b/src/main/gg/frog/mc/permissionstime/config/LangCfg.java index aa61efa..fbe1489 100644 --- a/src/main/gg/frog/mc/permissionstime/config/LangCfg.java +++ b/src/main/gg/frog/mc/permissionstime/config/LangCfg.java @@ -12,7 +12,8 @@ import gg.frog.mc.permissionstime.utils.config.PluginConfig; public class LangCfg extends PluginConfig { public static String INVENTORY_NAME = null; - public static String EXPIRATION_DATE = null; + public static String EXPIRATION_TIME = null; + public static String LEFT_TIME = null; public static String TIME_UNIT_D = null; public static String TIME_UNIT_H = null; public static String TIME_UNIT_M = null; @@ -67,7 +68,8 @@ public class LangCfg extends PluginConfig { @Override protected void loadToDo() { INVENTORY_NAME = getConfig().getString("inventoryName", "&4===Permissions Packages==="); - EXPIRATION_DATE = getConfig().getString("expirationDate", "&4Expiration date: {0}"); + EXPIRATION_TIME = getConfig().getString("expirationTime", "&4Expiration time: {0}"); + LEFT_TIME = getConfig().getString("leftTime", "&4Left time: About {0}{1} {2}{3} {4}{5}"); TIME_UNIT_D = getConfig().getString("timeUnitD", "day(s)"); TIME_UNIT_H = getConfig().getString("timeUnitH", "hour(s)"); TIME_UNIT_M = getConfig().getString("timeUnitM", "minute(s)"); @@ -98,7 +100,7 @@ public class LangCfg extends PluginConfig { 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_EXPIRATION_DATE = getConfig().getString("msg.expirationDate", "{0}packages: {1}({2}), Expiration date: {3}, {4}"); MSG_UNKNOWN_PACKAGE = getConfig().getString("msg.unknownPackage", "Unknown Packages"); MSG_IS_EXPIRATION_DATE = getConfig().getString("msg.isExpirationDate", "Your package: {0}({1})&r has expired."); diff --git a/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java b/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java index 1510d8f..d0e82ff 100644 --- a/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java +++ b/src/main/gg/frog/mc/permissionstime/gui/PlayerPermissionShow.java @@ -23,7 +23,8 @@ public class PlayerPermissionShow { ItemStack tItem = item.clone(); ItemMeta meta = tItem.getItemMeta(); List lores = meta.getLore(); - lores.add(StrUtil.messageFormat(LangCfg.EXPIRATION_DATE, StrUtil.timestampToString(pdb.getExpire()))); + lores.add(StrUtil.messageFormat(LangCfg.EXPIRATION_TIME, StrUtil.timestampToString(pdb.getExpire()))); + lores.add(StrUtil.getLeftTime(pdb.getExpire())); meta.setLore(lores); tItem.setItemMeta(meta); inventory.addItem(tItem); diff --git a/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java b/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java index 0a649d5..2526cb5 100644 --- a/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java +++ b/src/main/gg/frog/mc/permissionstime/model/cfg/PermissionPackageBean.java @@ -298,7 +298,7 @@ public class PermissionPackageBean implements IConfigBean { 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())); + p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_IS_EXPIRATION_DATE, packageBean != null ? packageBean.getDisplayName() : LangCfg.MSG_UNKNOWN_PACKAGE, playerData.getPackageName())); } } }); diff --git a/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java b/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java index 29f1343..18c6a6c 100644 --- a/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java +++ b/src/main/gg/frog/mc/permissionstime/utils/StrUtil.java @@ -5,9 +5,15 @@ import java.util.Date; import org.apache.commons.lang.time.DateFormatUtils; +import gg.frog.mc.permissionstime.config.LangCfg; +import gg.frog.mc.permissionstime.database.IPlayerDataDao; + public class StrUtil { private static String dfs = "yyyy/MM/dd HH:mm:ss"; + private static long dt = 24 * 60 * IPlayerDataDao.TIME_UNIT; + private static long ht = 60 * IPlayerDataDao.TIME_UNIT; + private static long mt = IPlayerDataDao.TIME_UNIT; public static String messageFormat(String src, Object... args) { return MessageFormat.format(src, args).replace("&", "§").replace("\\n", "\n"); @@ -24,4 +30,13 @@ public class StrUtil { public static String nowTimeString() { return DateFormatUtils.format(new Date(), dfs); } + + public static String getLeftTime(long time) { + long leftTime = time - new Date().getTime(); + long d = leftTime / dt; + long h = (leftTime % dt) / ht; + long m = (leftTime % ht) / mt; + return messageFormat(LangCfg.LEFT_TIME, d, LangCfg.TIME_UNIT_D, h, LangCfg.TIME_UNIT_H, m, LangCfg.TIME_UNIT_M); + } + } diff --git a/src/resources/lang/en.yml b/src/resources/lang/en.yml index c8634ee..de2e569 100644 --- a/src/resources/lang/en.yml +++ b/src/resources/lang/en.yml @@ -1,5 +1,6 @@ inventoryName: '&4===Permissions Packages===' -expirationDate: '&4Expiration date: {0}' +expirationTime: '&4Expiration date: {0}' +leftTime: '&4Left time: About {0}{1} {2}{3} {4}{5}' timeUnitD: 'day(s)' timeUnitH: 'hour(s)' timeUnitM: 'minute(s)' @@ -30,7 +31,7 @@ msg: delAll: '&2Remove 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}' + expirationDate: '{0}packages: {1}({2}), Expiration date: {3}, {4}' unknownPackage: 'Unknown Packages' isExpirationDate: 'Your package: {0}({1})&r has expired.' cmd: diff --git a/src/resources/lang/zh-cn.yml b/src/resources/lang/zh-cn.yml index df26559..14fe5f5 100644 --- a/src/resources/lang/zh-cn.yml +++ b/src/resources/lang/zh-cn.yml @@ -1,5 +1,6 @@ inventoryName: '&4===权限仓库===' -expirationDate: '&4到期时间: {0}.' +expirationTime: '&4到期时间: {0}.' +leftTime: '&4剩余时间: 大约 {0}{1} {2}{3} {4}{5}' timeUnitD: '天' timeUnitH: '小时' timeUnitM: '分钟' @@ -30,7 +31,7 @@ msg: delAll: '&2删除玩家 {0} 的所有权限包.' delAllFail: '&4未删除玩家 {0} 的 所有权限包.' numOfPackages: '====={0}有{1}个权限包=====' - expirationDate: '{0}权限包: {1}({2}), 到期时间: {3}' + expirationDate: '{0}权限包: {1}({2}), 到期时间: {3}, {4}' unknownPackage: '未知权限包' isExpirationDate: '你的权限包: {0}({1})&r, 已到期.' cmd: diff --git a/src/resources/plugin.yml b/src/resources/plugin.yml index 0a3375f..1238f96 100644 --- a/src/resources/plugin.yml +++ b/src/resources/plugin.yml @@ -1,5 +1,5 @@ name: PermissionsTime -version: 0.2.1-SNAPSHOT +version: 0.2.2-SNAPSHOT main: gg.frog.mc.permissionstime.PluginMain author: GeekFrog softdepend: