Add some settings management and also parse the time format.

This allows for: 30seconds, 10minutes, 3hours, or 2days
This commit is contained in:
graywolf336
2013-12-24 12:28:40 -06:00
parent 4a45229bc5
commit 0d79569c74
3 changed files with 63 additions and 4 deletions

View File

@ -1,7 +1,11 @@
package com.graywolf336.jail;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -9,6 +13,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector;
public class Util {
private final static Pattern DURATION_PATTERN = Pattern.compile("^(\\d+)\\s*(sec(?:ond?)?s?|(min(?:ute)?s?|h(?:ours?)?|d(?:ays?)?$", Pattern.CASE_INSENSITIVE);
/** Checks if the first {@link Vector} is inside the other two. */
public static boolean isInsideAB(Vector point, Vector first, Vector second) {
@ -59,4 +64,31 @@ public class Util {
return wand;
}
public static Long getTime(String time) throws Exception {
Long t = 10L;
Matcher match = DURATION_PATTERN.matcher(time);
if (match.matches()) {
String units = match.group(2);
if ("seconds".equals(units) || "second".equals(units) || "s".equals(units))
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.SECONDS);
if ("minutes".equals(units) || "minute".equals(units) || "mins".equals(units) || "min".equals(units))
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.MINUTES);
else if ("hours".equals(units) || "hour".equals(units) || "h".equals(units))
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.HOURS);
else if ("days".equals(units) || "day".equals(units) || "d".equals(units))
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.DAYS);
Bukkit.getLogger().info(units);
}else {
throw new Exception("Invalid format.");
}
return t;
}
/*
*/
}