Package de.murmelmeister.murmelapi.utils
Class TimeUtil
java.lang.Object
de.murmelmeister.murmelapi.utils.TimeUtil
Utility class for time-related operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatScoreboardTime(PlayTime playTime, int userId) Formats the given play time into a scoreboard time string.static longformatTime(String args) Formats the given time string into a long value representing the time in milliseconds.static StringformatTimeValue(PlayTime playTime, int userId) Formats the time value based on the given PlayTime and user ID.private static longReturns the time in milliseconds based on the given format and duration.private static StringgetTimeValue(long time, PlayTimeType type) Returns the formatted time value based on the given time and PlayTimeType.
-
Constructor Details
-
TimeUtil
public TimeUtil()
-
-
Method Details
-
formatTime
Formats the given time string into a long value representing the time in milliseconds. The time string should be a number followed by a time unit. The following time units are supported:- "s" for seconds
- "m" for minutes
- "h" for hours
- "d" for days
- "w" for weeks
- "M" for months (approximated to 30 days)
- "y" for years (approximated to 365 days)
If the time string is "-1", it is considered as permanent and the method returns -1. If the time string starts with "-", it is considered as invalid and the method returns -2. If the time string does not end with a valid time unit, the method returns -3.
- Parameters:
args- the time string to format- Returns:
- the formatted time in milliseconds, or -1, -2, -3 for the special cases described above
- Throws:
RuntimeException- if the time string (excluding the last character) cannot be parsed as a long value
-
getTime
Returns the time in milliseconds based on the given format and duration.- Parameters:
format- the time unitduration- the duration- Returns:
- the time in milliseconds
-
formatTimeValue
Formats the time value based on the given PlayTime and user ID.- Parameters:
playTime- The PlayTime object to get the time from.userId- The ID of the user.- Returns:
- The formatted time value as a string.
-
formatScoreboardTime
Formats the given play time into a scoreboard time string.- Parameters:
playTime- The PlayTime object to get the time from.userId- The ID of the user.- Returns:
- The formatted time value as a string representing the time in days, hours, and years.
-
getTimeValue
Returns the formatted time value based on the given time and PlayTimeType.- Parameters:
time- the time value to formattype- the PlayTimeType representing the time unit- Returns:
- the formatted time value as a string
-