From db77040560c0ab44f359e32e8d010204aa2e7a25 Mon Sep 17 00:00:00 2001 From: h31ix Date: Sat, 12 Oct 2013 23:59:42 -0400 Subject: [PATCH] Allow finer specification of intervals --- .../anticheat/config/files/Enterprise.java | 8 ++--- .../java/net/h31ix/anticheat/manage/User.java | 2 +- .../net/h31ix/anticheat/util/Utilities.java | 23 ++++++++++++++ .../anticheat/util/enterprise/Database.java | 31 ++++++++++--------- src/main/resources/enterprise.yml | 8 ++--- 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/h31ix/anticheat/config/files/Enterprise.java b/src/main/java/net/h31ix/anticheat/config/files/Enterprise.java index 8b08c1d..f7e8914 100644 --- a/src/main/java/net/h31ix/anticheat/config/files/Enterprise.java +++ b/src/main/java/net/h31ix/anticheat/config/files/Enterprise.java @@ -30,8 +30,8 @@ public class Enterprise extends ConfigurationFile { public ConfigValue serverName; public ConfigValue loggingEnabled; - public ConfigValue loggingLife; - public ConfigValue loggingInterval; + public ConfigValue loggingLife; + public ConfigValue loggingInterval; public ConfigValue syncUsers; @@ -49,8 +49,8 @@ public class Enterprise extends ConfigurationFile { serverName = new ConfigValue("server.name"); loggingEnabled = new ConfigValue("log.enable"); - loggingLife = new ConfigValue("log.life"); - loggingInterval = new ConfigValue("log.interval"); + loggingLife = new ConfigValue("log.life"); + loggingInterval = new ConfigValue("log.interval"); syncUsers = new ConfigValue("sync.users"); diff --git a/src/main/java/net/h31ix/anticheat/manage/User.java b/src/main/java/net/h31ix/anticheat/manage/User.java index 73b9a6e..2464fb5 100644 --- a/src/main/java/net/h31ix/anticheat/manage/User.java +++ b/src/main/java/net/h31ix/anticheat/manage/User.java @@ -54,7 +54,7 @@ public class User { */ public User(String name) { this.name = name; - this.id = getPlayer().isOnline() ? getPlayer().getEntityId() : -1; + this.id = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getEntityId() : -1; } /** diff --git a/src/main/java/net/h31ix/anticheat/util/Utilities.java b/src/main/java/net/h31ix/anticheat/util/Utilities.java index ab29a40..687123c 100644 --- a/src/main/java/net/h31ix/anticheat/util/Utilities.java +++ b/src/main/java/net/h31ix/anticheat/util/Utilities.java @@ -33,6 +33,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public final class Utilities { private static final List INSTANT_BREAK = new ArrayList(); @@ -475,6 +477,27 @@ public final class Utilities { return b.toString(); } + /** + * Parse a string in the format of "XdXhXmXs" to seconds + * @param string The string to parse + * @return seconds + */ + public static long lifeToSeconds(String string) { + if (string.equals("0") || string.equals("")) return 0; + String[] lifeMatch = new String[]{ "d", "h", "m", "s" }; + int[] lifeInterval = new int[]{ 86400, 3600, 60, 1 }; + long seconds = 0L; + + for (int i=0;i