Class TimeUtil

java.lang.Object
de.murmelmeister.murmelapi.utils.TimeUtil

public final class TimeUtil extends Object
Utility class for time-related operations.
  • Constructor Details

    • TimeUtil

      public TimeUtil()
  • Method Details

    • formatTime

      public static long formatTime(String args)
      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

      private static long getTime(String format, long duration)
      Returns the time in milliseconds based on the given format and duration.
      Parameters:
      format - the time unit
      duration - the duration
      Returns:
      the time in milliseconds
    • formatTimeValue

      public static String formatTimeValue(PlayTime playTime, int userId)
      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

      public static String formatScoreboardTime(PlayTime playTime, int userId)
      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

      private static String getTimeValue(long time, PlayTimeType type)
      Returns the formatted time value based on the given time and PlayTimeType.
      Parameters:
      time - the time value to format
      type - the PlayTimeType representing the time unit
      Returns:
      the formatted time value as a string