Class Time


  • public class Time
    extends java.lang.Object
    A utility class for all Time related things such as sleeping.
    • Constructor Summary

      Constructors 
      Constructor Description
      Time()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String format​(java.time.Duration duration)  
      static boolean sleep​(int min, int max)
      Sleeps for a random amount of time between a given range.
      static boolean sleep​(long ms)
      Sleep will not execute on the client thread, as this may hang the client.
      static boolean sleepTick()
      Sleeps for one game tick.
      static boolean sleepTicks​(int ticks)
      Sleeps for given amount of ticks.
      static boolean sleepTicksUntil​(java.util.function.BooleanSupplier supplier, int ticks)
      Sleeps for given amount of ticks, or until given condition is true.
      static boolean sleepUntil​(java.util.function.BooleanSupplier supplier, int timeOut)
      Sleeps until the given condition is true.
      static boolean sleepUntil​(java.util.function.BooleanSupplier supplier, int pollingRate, int timeOut)
      Sleeps until the given condition is true.
      static boolean sleepUntil​(java.util.function.BooleanSupplier supplier, java.util.function.BooleanSupplier resetSupplier, int timeOut)
      Sleeps until the given condition is true.
      static boolean sleepUntil​(java.util.function.BooleanSupplier supplier, java.util.function.BooleanSupplier resetSupplier, int pollingRate, int timeOut)
      Sleeps until the given condition is true.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Time

        public Time()
    • Method Detail

      • sleep

        public static boolean sleep​(long ms)
        Sleep will not execute on the client thread, as this may hang the client.
        Parameters:
        ms - The amount of milliseconds to sleep.
        Returns:
        Whether the sleep call was successful.
      • sleep

        public static boolean sleep​(int min,
                                    int max)
        Sleeps for a random amount of time between a given range. Sleep will not execute on the client thread, as this may hang the client.
        Parameters:
        min - The minimum amount of milliseconds to sleep.
        max - The maximum amount of milliseconds to sleep.
        Returns:
        Whether the sleep call was successful.
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.BooleanSupplier supplier,
                                         java.util.function.BooleanSupplier resetSupplier,
                                         int pollingRate,
                                         int timeOut)
        Sleeps until the given condition is true. Sleep will not execute on the client thread, as this may hang the client.
        Parameters:
        supplier - The completion condition.
        resetSupplier - The condition to reset the sleep timer.
        pollingRate - The amount of time to check whether the given conditions are true.
        timeOut - The amount of time until a timeout.
        Returns:
        Whether the sleep call was successful.
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.BooleanSupplier supplier,
                                         java.util.function.BooleanSupplier resetSupplier,
                                         int timeOut)
        Sleeps until the given condition is true. Sleep will not execute on the client thread, as this may hang the client.
        Parameters:
        supplier - The completion condition.
        resetSupplier - The condition to reset the sleep timer.
        timeOut - The amount of time until a timeout.
        Returns:
        Whether the sleep call was successful.
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.BooleanSupplier supplier,
                                         int pollingRate,
                                         int timeOut)
        Sleeps until the given condition is true. Sleep will not execute on the client thread, as this may hang the client.
        Parameters:
        supplier - The completion condition.
        pollingRate - The amount of time to check whether the given conditions are true.
        timeOut - The amount of time until a timeout.
        Returns:
        Whether the sleep call was successful.
      • sleepUntil

        public static boolean sleepUntil​(java.util.function.BooleanSupplier supplier,
                                         int timeOut)
        Sleeps until the given condition is true. Sleep will not execute on the client thread, as this may hang the client.
        Parameters:
        supplier - The completion condition.
        timeOut - The amount of time until a timeout.
        Returns:
        Whether the sleep call was successful.
      • sleepTicks

        public static boolean sleepTicks​(int ticks)
        Sleeps for given amount of ticks. Sleep will not execute on the client thread, as this may hang the client.
        Parameters:
        ticks - Amount of time to sleep in ticks.
        Returns:
        Whether the sleep call was successful.
      • sleepTick

        public static boolean sleepTick()
        Sleeps for one game tick. Sleep will not execute on the client thread, as this may hang the client.
        Returns:
        Whether the sleep call was successful.
      • sleepTicksUntil

        public static boolean sleepTicksUntil​(java.util.function.BooleanSupplier supplier,
                                              int ticks)
        Sleeps for given amount of ticks, or until given condition is true.
        Parameters:
        supplier - The break condition.
        ticks - Max. amount of ticks to sleep.
        Returns:
        Whether the sleep call was successful.
      • format

        public static java.lang.String format​(java.time.Duration duration)
        Parameters:
        duration - The duration value to format.
        Returns:
        A HH:MM:SS formatted string.