From 95ae255b077720a1d22eb32510f0d9fcb717de44 Mon Sep 17 00:00:00 2001 From: Alexander Bielen Date: Tue, 30 Oct 2018 19:32:08 +0100 Subject: [PATCH] Merged unique code into Timer --- .../environment/api/utils/PaintUtil.java | 51 ------------------- .../parabot/environment/api/utils/Timer.java | 13 ++++- 2 files changed, 12 insertions(+), 52 deletions(-) delete mode 100644 src/main/java/org/parabot/environment/api/utils/PaintUtil.java diff --git a/src/main/java/org/parabot/environment/api/utils/PaintUtil.java b/src/main/java/org/parabot/environment/api/utils/PaintUtil.java deleted file mode 100644 index 202f446..0000000 --- a/src/main/java/org/parabot/environment/api/utils/PaintUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.parabot.environment.api.utils; - -import java.text.DecimalFormat; - -/** - * Functions frequently used for displaying data on paints - * - * @author AlexanderBielen - */ -public class PaintUtil { - - /** - * Calculates how much given variable has gained per hour - * - * @param currentAmount total gained amount - * @param start time from which to start counting in milliseconds - * @return rate per hour - */ - public static long calculatePerHour(int currentAmount, long start) { - return calculatePerHour(currentAmount, 0, start); - } - - /** - * Calculates how much given variable has gained per hour, with variable start amount - * - * @param currentAmount total gained amount - * @param startAmount start amount - * @param start time from which to start counting in milliseconds - * @return rate per hour - */ - public static long calculatePerHour(int currentAmount, int startAmount, long start) { - return (int)(((double)(currentAmount - startAmount) * 3600000D) / (double)(System.currentTimeMillis() - start)); - } - - /** - * Formats a time difference from given timestamp till present into readable hh:mm:ss format - * - * @param start start time in milliseconds - * @return readable timestamp - */ - public static String formatRunTime(long start) { - DecimalFormat df = new DecimalFormat("00"); - long currentTime = System.currentTimeMillis() - start; - long hours = currentTime / (3600000); - currentTime -= hours * (3600000); - long minutes = currentTime / (60000); - currentTime -= minutes * (60000); - long seconds = currentTime / (1000); - return df.format(hours) + ":" + df.format(minutes) + ":" + df.format(seconds); - } -} \ No newline at end of file diff --git a/src/main/java/org/parabot/environment/api/utils/Timer.java b/src/main/java/org/parabot/environment/api/utils/Timer.java index fa3c07e..5b44fdc 100644 --- a/src/main/java/org/parabot/environment/api/utils/Timer.java +++ b/src/main/java/org/parabot/environment/api/utils/Timer.java @@ -105,7 +105,18 @@ public class Timer { * @return hourly gains */ public int getPerHour(final int gained) { - return (int) ((gained) * 3600000D / (System.currentTimeMillis() - start)); + return getPerHour(gained, 0); + } + + /** + * Calculates hourly gains based on given variable, with variable start amount + * + * @param gained total gained amount + * @param startAmount start amount + * @return hourly gains + */ + public int getPerHour(final int gained, int startAmount) { + return (int) (((gained - startAmount) * 3600000D) / (System.currentTimeMillis() - start)); } /**