Class GameDate

java.lang.Object
net.risingworld.api.utils.GameDate
All Implemented Interfaces:
Comparable<GameDate>

public final class GameDate extends Object implements Comparable<GameDate>
Represents an ingame date and time of day. This object is immutable, i.e it's a snapshot of the current ingame time and does not change when the ingame time passes. Use Server.getGameDate() to get the current ingame date.
The game has no months: A year consists of 4 seasons (spring, summer, autumn and winter) with Seasons.DAYS_PER_SEASON days per season. A day has 24 hours.
A "time of day" is always represented by the minutes since midnight (0-1439), e.g. 450 for 7:30 am.

Example: Check if it's night and print the current date
1GameDate date = Server.getGameDate();
2if (date.isNight()) {
3 System.out.println("Night of day " + date.getDayOfSeason() + " in " + date.getSeason());
4}
  • Field Details

    • DAYS_PER_YEAR

      public static final int DAYS_PER_YEAR
      Number of days per year
      See Also:
    • MINUTES_PER_DAY

      public static final int MINUTES_PER_DAY
      Number of minutes per day
      See Also:
    • SUNRISE_START

      public static final int SUNRISE_START
      Time of day when the sunrise starts (7:00 am, minutes since midnight). The night ends at this time
      See Also:
    • SUNRISE_END

      public static final int SUNRISE_END
      Time of day when the sunrise ends (8:00 am, minutes since midnight)
      See Also:
    • SUNSET_START

      public static final int SUNSET_START
      Time of day when the sunset starts (9:00 pm, minutes since midnight). The night begins after this time
      See Also:
    • SUNSET_END

      public static final int SUNSET_END
      Time of day when the sunset ends (10:00 pm, minutes since midnight)
      See Also:
  • Method Details

    • of

      public static GameDate of(int year, int day, int hour, int minute)
      Creates a new game date.
      Parameters:
      year - the year (new worlds start in year 1).
      day - the day of the year (1-124).
      hour - the hour of the day (0-23).
      minute - the minute (0-59).
      Returns:
      the new date object.
      Throws:
      IllegalArgumentException - if a value is out of range.
    • ofTotalMinutes

      public static GameDate ofTotalMinutes(int totalMinutes)
      Creates a game date from the total amount of minutes, i.e the value returned by getTotalMinutes(). Useful to restore a date you've stored previously (e.g. in a database).
      Parameters:
      totalMinutes - the total amount of minutes.
      Returns:
      the new date object.
      Throws:
      IllegalArgumentException - if the value is negative.
    • getYear

      public int getYear()
      Gets the year. New worlds start with year 1.
      Returns:
      the year.
    • getDay

      public int getDay()
      Gets the day of year (1-124).
      Returns:
      the day of year.
    • getDayOfSeason

      public int getDayOfSeason()
      Gets the day within the season (1-31).
      Returns:
      the day within the season.
    • getSeason

      public Seasons.Season getSeason()
      Gets the season according to the calendar, i.e. based on the day of year. Note that the actual season of the server may differ, e.g. if seasons are disabled (see Server.getCurrentSeason()).
      Returns:
      the calendar season.
    • getTimeOfDay

      public int getTimeOfDay()
      Gets the time of day, i.e. the minutes since midnight (0-1439).
      Returns:
      the time of day.
    • getHour

      public int getHour()
      Gets the hour (0-23).
      Returns:
      the hour.
    • getMinute

      public int getMinute()
      Gets the minute (0-59).
      Returns:
      the minute.
    • getTotalMinutes

      public int getTotalMinutes()
      Gets the total amount of minutes since the beginning of year 0. Useful to store a date (see ofTotalMinutes(int)) or to calculate the minutes between two dates.
      Returns:
      the total amount of minutes.
    • plusMinutes

      public GameDate plusMinutes(int minutes)
      Returns a new date with the provided amount of minutes added (or subtracted, if negative). This object stays unchanged.
      Parameters:
      minutes - the amount of minutes to add.
      Returns:
      the new date.
      Throws:
      IllegalArgumentException - if the new date would be before year 0.
      ArithmeticException - if the new date would be out of range.
    • isNight

      public boolean isNight()
      Gets whether or not it's night, i.e. after SUNSET_START (9:00 pm) and before SUNRISE_START (7:00 am). This is the same time window in which the game skips the night if all players are sleeping.
      Returns:
      true if it's night, false if not.
    • isNight

      public static boolean isNight(int timeOfDay)
      Gets whether or not the provided time of day is at night, i.e. after SUNSET_START (9:00 pm) and before SUNRISE_START (7:00 am).
      Parameters:
      timeOfDay - the time of day, i.e. the minutes since midnight (0-1439).
      Returns:
      true if the time is at night, false if not.
    • compareTo

      public int compareTo(GameDate other)
      Specified by:
      compareTo in interface Comparable<GameDate>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object