Package rs.kreme.ksbot.api.commons
Class Timer
- java.lang.Object
-
- rs.kreme.ksbot.api.commons.Timer
-
public class Timer extends java.lang.ObjectA utility class for managing and tracking elapsed time and performing time-based calculations.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetElapsedTime()Calculates the elapsed time since the timer started.intgetPerHour(int gained)Calculates the hourly rate based on a gained value.intgetPerHour(int gained, int startAmount)Calculates the hourly rate based on a gained value and an initial start amount.longgetRemaining()Retrieves the remaining time until the timer ends.java.lang.StringgetRemainingTime()Formats the remaining time as a string in the format "DD:HH:MM:SS".booleanisFinished()Checks if the timer has finished (end time reached).booleanisRunning()Checks if the timer is currently running.voidreset()Resets the timer, initializing it to the current time if it was stopped.voidrestart()Restarts the timer by resetting and resuming it.voidstop()Stops the timer, preserving the remaining duration for resumption.java.lang.StringtoString()Generates a formatted string of the elapsed time in the format "DD:HH:MM:SS".
-
-
-
Constructor Detail
-
Timer
public Timer(long duration)
Creates a Timer with a specified duration.- Parameters:
duration- The duration in milliseconds for which the timer should run.
-
Timer
public Timer(long duration, long start)Creates a Timer with a specified start time and duration.- Parameters:
duration- The duration in milliseconds for which the timer should run.start- The custom start time in milliseconds.
-
Timer
public Timer()
Creates a Timer with no initial duration.
-
-
Method Detail
-
getRemaining
public long getRemaining()
Retrieves the remaining time until the timer ends.- Returns:
- The remaining time in milliseconds. Returns 0 if the timer has already ended.
-
isFinished
public boolean isFinished()
Checks if the timer has finished (end time reached).- Returns:
trueif the timer has finished, otherwisefalse.
-
restart
public void restart()
Restarts the timer by resetting and resuming it.
-
reset
public void reset()
Resets the timer, initializing it to the current time if it was stopped.
-
stop
public void stop()
Stops the timer, preserving the remaining duration for resumption.
-
isRunning
public boolean isRunning()
Checks if the timer is currently running.- Returns:
trueif the timer is running, otherwisefalse.
-
getElapsedTime
public long getElapsedTime()
Calculates the elapsed time since the timer started.- Returns:
- The elapsed time in milliseconds.
-
getPerHour
public int getPerHour(int gained)
Calculates the hourly rate based on a gained value.- Parameters:
gained- The total value gained during the elapsed time.- Returns:
- The calculated rate per hour.
-
getPerHour
public int getPerHour(int gained, int startAmount)Calculates the hourly rate based on a gained value and an initial start amount.- Parameters:
gained- The total value gained during the elapsed time.startAmount- The initial amount at the start of the timer.- Returns:
- The calculated rate per hour.
-
getRemainingTime
public java.lang.String getRemainingTime()
Formats the remaining time as a string in the format "DD:HH:MM:SS".- Returns:
- The formatted remaining time string.
-
toString
public java.lang.String toString()
Generates a formatted string of the elapsed time in the format "DD:HH:MM:SS".- Overrides:
toStringin classjava.lang.Object- Returns:
- The formatted elapsed time string.
-
-