Skip to content

Commit

Permalink
timeban int fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TTTheKing committed Apr 3, 2014
1 parent a4ba4ce commit 5bb3ac8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/com/dre/managerxl/commands/player/CMDTimeBan.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
70 changes: 70 additions & 0 deletions src/com/dre/managerxl/util/MUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 5bb3ac8

Please sign in to comment.