diff --git a/pom.xml b/pom.xml
index 82c69c3..73a8cb8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
gg.frog.mc
permissionstime
- 0.1.3-SNAPSHOT
+ 0.2.0-SNAPSHOT
jar
PermissionsTime
支持跨服的权限限时插件
diff --git a/src/main/gg/frog/mc/permissionstime/PluginMain.java b/src/main/gg/frog/mc/permissionstime/PluginMain.java
index 69e3123..3c6f3b1 100644
--- a/src/main/gg/frog/mc/permissionstime/PluginMain.java
+++ b/src/main/gg/frog/mc/permissionstime/PluginMain.java
@@ -9,7 +9,6 @@ import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
-import org.mcstats.Metrics;
import gg.frog.mc.permissionstime.command.MainCommand;
import gg.frog.mc.permissionstime.config.ConfigManager;
@@ -52,14 +51,6 @@ public class PluginMain extends JavaPlugin {
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " https://github.com/geekfrog/PermissionsTime/ "));
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
- if (PluginCfg.IS_METRICS) {
- try {
- Metrics metrics = new Metrics(pm);
- metrics.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
getServer().getScheduler().runTask(pm, new UpdateCheck(pm));
getServer().getScheduler().runTask(pm, new Runnable() {
public void run() {
@@ -71,6 +62,14 @@ public class PluginMain extends JavaPlugin {
registerCommands();
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&2Startup successful!"));
}
+ if (PluginCfg.IS_METRICS) {
+ try {
+ org.mcstats.Metrics mcstats = new org.mcstats.Metrics(pm);
+ mcstats.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
});
}
diff --git a/src/main/gg/frog/mc/permissionstime/command/GetCmd.java b/src/main/gg/frog/mc/permissionstime/command/GetCmd.java
index 6846692..d7e77e9 100644
--- a/src/main/gg/frog/mc/permissionstime/command/GetCmd.java
+++ b/src/main/gg/frog/mc/permissionstime/command/GetCmd.java
@@ -33,24 +33,28 @@ public class GetCmd implements Runnable {
if (args.length == 2) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
OfflinePlayer p = pm.getOfflinePlayer(args[1]);
- List 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));
+ if (p != null) {
+ List 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_NO_DATA));
+ sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, args[1]));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
- sender.sendMessage(StrUtil.messageFormat("&6/" + pm.PLUGIN_NAME_LOWER_CASE + " get \n&8 - View player packages."));
+ sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GET, pm.PLUGIN_NAME_LOWER_CASE));
}
}
}
diff --git a/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java b/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java
index 64ba229..c61a5d1 100644
--- a/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java
+++ b/src/main/gg/frog/mc/permissionstime/command/GiveCmd.java
@@ -32,15 +32,34 @@ public class GiveCmd implements Runnable {
@Override
public void run() {
- if (args.length == 4) {
+ if (args.length == 5) {
String playerName = args[1];
String packageName = args[2];
String time = args[3];
- int days = 0;
+ String unit = args[4];
+ final String unitName;
+ int minutes = 0;
try {
- days = Integer.parseInt(time);
+ minutes = Integer.parseInt(time);
+ if (minutes == 0) {
+ throw new RuntimeException("not a nonzero integer.");
+ }
} catch (Exception e) {
- sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DAYS_PARAMETER_INCORRECT));
+ sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_PARAMETER_INCORRECT));
+ sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE));
+ return;
+ }
+ if ("d".equalsIgnoreCase(unit)) {
+ minutes *= 24 * 60;
+ unitName = LangCfg.TIME_UNIT_D;
+ } else if ("h".equalsIgnoreCase(unit)) {
+ minutes *= 60;
+ unitName = LangCfg.TIME_UNIT_H;
+ } else if ("m".equalsIgnoreCase(unit)) {
+ unitName = LangCfg.TIME_UNIT_M;
+ } else {
+ sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_UNIT_PARAMETER_INCORRECT));
+ sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE));
return;
}
PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName);
@@ -50,9 +69,9 @@ public class GiveCmd implements Runnable {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
UUID uuid = player.getUniqueId();
if (PluginCfg.IS_DEBUG) {
- sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + " days."));
+ sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + unitName + "."));
}
- if (sm.giveTime(((PluginCfg.USE_MYSQL && pack.getGlobal()) ? "g:" : "") + uuid.toString(), packageName, days)) {
+ if (sm.giveTime(((PluginCfg.USE_MYSQL && pack.getGlobal()) ? "g:" : "") + uuid.toString(), packageName, minutes)) {
if (player.isOnline()) {
Player p = player.getPlayer();
try {
@@ -62,17 +81,17 @@ public class GiveCmd implements Runnable {
e.printStackTrace();
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
}
- p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_GIVE_PACKAGE, sender.getName(), time, pack.getDisplayName()));
+ p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_GIVE_PACKAGE, sender.getName(), time + unitName, pack.getDisplayName()));
}
- sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE, playerName, time, pack.getDisplayName()));
+ sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE, playerName, time + unitName, pack.getDisplayName()));
} else {
pm.getServer().getScheduler().runTask(pm, new Runnable() {
@Override
public void run() {
- pm.writeFailLog("Command execution failed. Give {0}({1}) {2}days {3} Executor: {4}", playerName, player.getUniqueId().toString(), time, pack.getDisplayName(), sender.getName());
+ pm.writeFailLog("Command execution failed. Give {0}({1}) {2} {3} Executor: {4}", playerName, player.getUniqueId().toString(), time + unitName, pack.getDisplayName(), sender.getName());
}
});
- sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE_FAIL, playerName, time, pack.getDisplayName()));
+ sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE_FAIL, playerName, time + unitName, pack.getDisplayName()));
}
} else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName));
@@ -82,7 +101,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