Class TimeValues

java.lang.Object
me.croabeast.common.time.TimeValues

public class TimeValues extends Object
Represents a collection of string formats for different time units.

TimeValues holds configurable formatting strings for seconds, minutes, hours, days, weeks, months, and years. It is designed to support multiple languages and custom formatting. The class includes pre-defined instances such as DEFAULT_KEYS and SPANISH_KEYS. Once an instance is "locked" (i.e. modification is disabled), its values cannot be changed.

The formatting strings are used in conjunction with TimeFormatter to produce human-readable representations of time durations.

Example usage:


 // Using default keys:
 TimeValues defaults = TimeValues.DEFAULT_KEYS;

 // Customizing for Spanish:
 TimeValues spanish = TimeValues.SPANISH_KEYS;

 // Load from configuration:
 ConfigurationSection section = ...;
 TimeValues configValues = TimeValues.fromSection(section);
 

  • Field Details

    • DEFAULT_KEYS

      public static final TimeValues DEFAULT_KEYS
      Default time unit keys in English.
    • SPANISH_KEYS

      public static final TimeValues SPANISH_KEYS
      Predefined time unit keys for Spanish language.
  • Method Details

    • setSplitter

      public TimeValues setSplitter(String splitter)
      Sets the splitter string used between time unit segments.
      Parameters:
      splitter - the new splitter string (must not be blank)
      Returns:
      this TimeValues instance for chaining
    • setSecondsFormat

      public TimeValues setSecondsFormat(String secondsFormat)
      Sets the format string for seconds.
      Parameters:
      secondsFormat - the format string for seconds (must not be blank)
      Returns:
      this TimeValues instance for chaining
    • setMinutesFormat

      public TimeValues setMinutesFormat(String minutesFormat)
      Sets the format string for minutes.
      Parameters:
      minutesFormat - the format string for minutes (must not be blank)
      Returns:
      this TimeValues instance for chaining
    • setHoursFormat

      public TimeValues setHoursFormat(String hoursFormat)
      Sets the format string for hours.
      Parameters:
      hoursFormat - the format string for hours (must not be blank)
      Returns:
      this TimeValues instance for chaining
    • setDaysFormat

      public TimeValues setDaysFormat(String daysFormat)
      Sets the format string for days.
      Parameters:
      daysFormat - the format string for days (must not be blank)
      Returns:
      this TimeValues instance for chaining
    • setWeeksFormat

      public TimeValues setWeeksFormat(String weeksFormat)
      Sets the format string for weeks.
      Parameters:
      weeksFormat - the format string for weeks (must not be blank)
      Returns:
      this TimeValues instance for chaining
    • setMonthsFormat

      public TimeValues setMonthsFormat(String monthsFormat)
      Sets the format string for months.
      Parameters:
      monthsFormat - the format string for months (must not be blank)
      Returns:
      this TimeValues instance for chaining
    • setYearsFormat

      public TimeValues setYearsFormat(String yearsFormat)
      Sets the format string for years.
      Parameters:
      yearsFormat - the format string for years (must not be blank)
      Returns:
      this TimeValues instance for chaining
    • create

      public static TimeValues create()
      Creates a new modifiable instance of TimeValues.
      Returns:
      a new TimeValues instance with default formats
    • fromSection

      public static TimeValues fromSection(org.bukkit.configuration.ConfigurationSection section)
      Creates a TimeValues instance from a configuration section.

      The configuration should contain keys such as "splitter", "seconds", "minutes", "hours", "days", "weeks", "months", and "years". If a key is missing or invalid, the corresponding default value is retained.

      Parameters:
      section - the configuration section containing time format settings
      Returns:
      a new TimeValues instance loaded from the configuration
      Throws:
      NullPointerException - if the configuration section is null