Class DurationUtils

java.lang.Object
dev.chicoferreira.lifestealer.DurationUtils

public class DurationUtils extends Object
  • Constructor Details

    • DurationUtils

      public DurationUtils()
  • Method Details

    • setFormats

      public static void setFormats(Map<String,DurationUtils.DurationFormatSettings> formats)
    • formatDurationTag

      public static net.kyori.adventure.text.minimessage.tag.resolver.TagResolver formatDurationTag(@TagPattern @NotNull @NotNull String key, @NotNull @NotNull Duration duration)
      Creates a @{link MiniMessage} tag resolver that formats a duration using the given format using DurationFormatUtils.formatDuration(long, String).
      Parameters:
      key - The key of the tag
      duration - The duration to format
      Returns:
      A tag resolver that formats the duration using the given format
    • parse

      public static Duration parse(String string) throws IllegalArgumentException
      Parses a string into a Duration. The string should be formatted as a sequence of numbers followed by a unit. Supported units: s or S (seconds), m (minutes), h or H (hours), d or D (days), w or W (weeks), M (months), y or Y (years)

      Example: "1d 2h 3m 4s" returns a duration with 1 day, 2 hours, 3 minutes and 4 seconds

      Parameters:
      string - The string to parse
      Returns:
      The parsed duration
      Throws:
      IllegalArgumentException - If the string is not in a valid format