From 5bb3ac8ee18076c7370d0960ef88e73f77055914 Mon Sep 17 00:00:00 2001 From: TTTheKing Date: Thu, 3 Apr 2014 14:46:33 +0200 Subject: [PATCH] timeban int fix --- .../managerxl/commands/player/CMDTimeBan.java | 2 +- src/com/dre/managerxl/util/MUtility.java | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/com/dre/managerxl/commands/player/CMDTimeBan.java b/src/com/dre/managerxl/commands/player/CMDTimeBan.java index a4e3612..e47f765 100644 --- a/src/com/dre/managerxl/commands/player/CMDTimeBan.java +++ b/src/com/dre/managerxl/commands/player/CMDTimeBan.java @@ -33,7 +33,7 @@ public void onExecute(String[] args, CommandSender sender) { message = P.p.getLanguageReader().get("Cmd_Ban_DefaultReason"); } - int time = MUtility.getStringTimeToInt(args[1]); + long time = MUtility.getStringTimeToLong(args[1]); player.setBannedTime(System.currentTimeMillis() + time); player.setBannedReason(message); diff --git a/src/com/dre/managerxl/util/MUtility.java b/src/com/dre/managerxl/util/MUtility.java index 5916706..32db25d 100644 --- a/src/com/dre/managerxl/util/MUtility.java +++ b/src/com/dre/managerxl/util/MUtility.java @@ -66,6 +66,41 @@ public static int getStringTimeToInt(String time) { return result * 1000; // Seconds to millisecs } + public static long getStringTimeToLong(String time) { + long result = 0; + int index = 0; + int lastIndex = 0; + + // Days + index = time.indexOf("d"); + if (index > lastIndex) { + result += parseInt(time.substring(lastIndex, index)) * 24 * 60 * 60; + } + + // Hours + lastIndex = index; + index = time.indexOf("h"); + if (index > lastIndex) { + result += parseInt(time.substring(lastIndex + 1, index)) * 60 * 60; + } + + // Minutes + lastIndex = index; + index = time.indexOf("m"); + if (index > lastIndex) { + result += parseInt(time.substring(lastIndex + 1, index)) * 60; + } + + // Seconds + lastIndex = index; + index = time.indexOf("s"); + if (index > lastIndex) { + result += parseInt(time.substring(lastIndex + 1, index)); + } + + return result * 1000; // Seconds to millisecs + } + public static String getIntTimeToString(long l) { String result = ""; @@ -100,6 +135,41 @@ public static String getIntTimeToString(long l) { return result.trim(); } + + public static String getLongTimeToString(long l) { + String result = ""; + + l = l / 1000; // Millisecs to seconds + + // Days + int dayTime = 24 * 60 * 60; + if (l >= dayTime) { + result += ((int) (l / dayTime)) + " " + P.p.getLanguageReader().get("Format_Days") + " "; + l = l % dayTime; + } + + // Hours + int hourTime = 60 * 60; + if (l >= hourTime) { + result += ((int) (l / hourTime)) + " " + P.p.getLanguageReader().get("Format_Hours") + " "; + l = l % hourTime; + } + + // Minute + int minuteTime = 60; + if (l >= minuteTime) { + result += ((int) (l / minuteTime)) + " " + P.p.getLanguageReader().get("Format_Minutes") + " "; + l = l % minuteTime; + } + + // Seconds + if (l >= 1) { + result += l + " " + P.p.getLanguageReader().get("Format_Seconds") + " "; + l = l % minuteTime; + } + + return result.trim(); + } public static Location getNearestFreePosition(Location currentPosition) { Block block = currentPosition.getBlock();