mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 16:49:10 +00:00
[FEATURE] Added days into Timer
Credits to @parnassian
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
package org.parabot.environment.api.utils;
|
package org.parabot.environment.api.utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* A simple timer class
|
* A simple timer class
|
||||||
*
|
*
|
||||||
* @author Everel, Parameter
|
* @author Everel, Parameter
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class Timer {
|
public class Timer {
|
||||||
private long start;
|
private long start;
|
||||||
@@ -17,7 +15,6 @@ public class Timer {
|
|||||||
* @param end
|
* @param end
|
||||||
*/
|
*/
|
||||||
public Timer(long end) {
|
public Timer(long end) {
|
||||||
|
|
||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
this.end = System.currentTimeMillis() + end;
|
this.end = System.currentTimeMillis() + end;
|
||||||
}
|
}
|
||||||
@@ -92,8 +89,8 @@ public class Timer {
|
|||||||
/**
|
/**
|
||||||
* Calculates hourly gains based on given variable
|
* Calculates hourly gains based on given variable
|
||||||
*
|
*
|
||||||
* @param gained
|
* @param gained variable
|
||||||
* variable
|
*
|
||||||
* @return hourly gains
|
* @return hourly gains
|
||||||
*/
|
*/
|
||||||
public int getPerHour(final int gained) {
|
public int getPerHour(final int gained) {
|
||||||
@@ -101,7 +98,7 @@ public class Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates string based on HH:MM:SS
|
* Generates string based on DD:HH:MM:SS
|
||||||
*
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
@@ -109,9 +106,16 @@ public class Timer {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
long elapsed = getElapsedTime();
|
long elapsed = getElapsedTime();
|
||||||
int second = (int) (elapsed / 1000 % 60);
|
int day = (int) (elapsed / 86400000);
|
||||||
int minute = (int) (elapsed / 60000 % 60);
|
elapsed -= day * 86400000;
|
||||||
int hour = (int) (elapsed / 3600000 % 60);
|
int hour = (int) (elapsed / 3600000);
|
||||||
|
elapsed -= hour * 3600000;
|
||||||
|
int minute = (int) (elapsed / 60000);
|
||||||
|
elapsed -= minute * 60000;
|
||||||
|
int second = (int) (elapsed / 1000);
|
||||||
|
if (day > 0) {
|
||||||
|
b.append(day < 10 ? "0" : "").append(day).append("d:");
|
||||||
|
}
|
||||||
b.append(hour < 10 ? "0" : "").append(hour).append(":");
|
b.append(hour < 10 ? "0" : "").append(hour).append(":");
|
||||||
b.append(minute < 10 ? "0" : "").append(minute).append(":");
|
b.append(minute < 10 ? "0" : "").append(minute).append(":");
|
||||||
b.append(second < 10 ? "0" : "").append(second);
|
b.append(second < 10 ? "0" : "").append(second);
|
||||||
|
|||||||
Reference in New Issue
Block a user