Class SourceSimpleTimer

java.lang.Object
ml.karmaconfigs.api.common.timer.scheduler.SimpleScheduler
ml.karmaconfigs.api.common.timer.SourceSimpleTimer

public final class SourceSimpleTimer extends SimpleScheduler
Karma simple scheduler
  • Constructor Details

    • SourceSimpleTimer

      public SourceSimpleTimer(KarmaSource owner, Number time, boolean autoRestart)
      Initialize the scheduler
      Parameters:
      owner - the scheduler owner
      time - the scheduler start time
      autoRestart - if the scheduler should auto-restart when it ends
    • SourceSimpleTimer

      public SourceSimpleTimer(KarmaSource owner, int builtId) throws TimerNotFound, IllegalTimerAccess
      Initialize the scheduler
      Parameters:
      owner - the scheduler owner
      builtId - the scheduler ID
      Throws:
      TimerNotFound - if the scheduler does not exist
      IllegalTimerAccess - if the scheduler owner does not match with provided
  • Method Details

    • cancelUnloaded

      public SimpleScheduler cancelUnloaded(boolean status)
      Notice when the timer has been stopped because its source has been also unloaded
      Parameters:
      status - the notice unloaded status
      Returns:
      this instance
    • cancel

      public void cancel()
      Cancel the scheduler
      Specified by:
      cancel in class SimpleScheduler
    • pause

      public void pause()
      Pause the scheduler
      Specified by:
      pause in class SimpleScheduler
    • start

      public void start() throws TimerAlreadyStarted
      Start the scheduler
      Specified by:
      start in class SimpleScheduler
      Throws:
      TimerAlreadyStarted - if the scheduler is already started
    • restart

      public void restart()
      Restart the scheduler
      Specified by:
      restart in class SimpleScheduler
    • updateAutoRestart

      public SimpleScheduler updateAutoRestart(boolean status)
      Set if the timer should auto restart when it ends
      Specified by:
      updateAutoRestart in class SimpleScheduler
      Parameters:
      status - if the timer should auto restart
      Returns:
      this instance
    • withPeriod

      public SimpleScheduler withPeriod(Number time)
      Set the timer update period
      Specified by:
      withPeriod in class SimpleScheduler
      Parameters:
      time - the period
      Returns:
      this instance
    • multiThreading

      public SimpleScheduler multiThreading(boolean status)
      Set if the timer runs on another thread
      Specified by:
      multiThreading in class SimpleScheduler
      Parameters:
      status - if the timer has multi-threading
      Returns:
      this instance
    • exactSecondPeriodAction

      public SimpleScheduler exactSecondPeriodAction(int time, Runnable task)
      Add an action to perform when the timer reaches the specified second
      Specified by:
      exactSecondPeriodAction in class SimpleScheduler
      Parameters:
      time - the second
      task - the action to perform
      Returns:
      this instance
    • exactPeriodAction

      public SimpleScheduler exactPeriodAction(long time, Runnable task)
      Add an action to perform when the timer reaches the specified millisecond
      Specified by:
      exactPeriodAction in class SimpleScheduler
      Parameters:
      time - the millisecond
      task - the action to perform
      Returns:
      this instance
    • secondChangeAction

      public SimpleScheduler secondChangeAction(Consumer<Integer> action)
      Add an action when the timer passes a second
      Specified by:
      secondChangeAction in class SimpleScheduler
      Parameters:
      action - the action to perform
      Returns:
      this instance
    • periodChangeAction

      public SimpleScheduler periodChangeAction(Consumer<Long> action)
      Add an action when the timer passes a millisecond
      Specified by:
      periodChangeAction in class SimpleScheduler
      Parameters:
      action - the action to perform
      Returns:
      this instance
    • cancelAction

      public SimpleScheduler cancelAction(Consumer<Long> action)
      Set the action to perform when the timer is cancelled
      Specified by:
      cancelAction in class SimpleScheduler
      Parameters:
      action - the action to perform
      Returns:
      this instance
    • pauseAction

      public SimpleScheduler pauseAction(Consumer<Long> action)
      Set the action to perform when the timer is paused
      Specified by:
      pauseAction in class SimpleScheduler
      Parameters:
      action - the action to perform
      Returns:
      this instance
    • startAction

      public SimpleScheduler startAction(Runnable task)
      Set the action to perform when the timer is started
      Specified by:
      startAction in class SimpleScheduler
      Parameters:
      task - the action to perform
      Returns:
      this instance
    • endAction

      public SimpleScheduler endAction(Runnable task)
      Set the action to perform when the timer is completely ended
      Specified by:
      endAction in class SimpleScheduler
      Parameters:
      task - the action to perform
      Returns:
      this instance
    • restartAction

      public SimpleScheduler restartAction(Runnable task)
      Set the action to perform when the timer is restarted
      Specified by:
      restartAction in class SimpleScheduler
      Parameters:
      task - the action to perform
      Returns:
      this instance
    • conditionalAction

      public SimpleScheduler conditionalAction(TimeCondition condition, int condition_value, Consumer<Integer> action)
      Add a conditional action
      Specified by:
      conditionalAction in class SimpleScheduler
      Parameters:
      condition - the condition that the timer must complete
      condition_value - the timer second
      action - the action to perform
      Returns:
      this instance
    • conditionalPeriodAction

      public SimpleScheduler conditionalPeriodAction(TimeCondition condition, long condition_value, Consumer<Long> action)
      Add a conditional action
      Specified by:
      conditionalPeriodAction in class SimpleScheduler
      Parameters:
      condition - the condition that the timer must complete
      condition_value - the timer millisecond
      action - the action to perform
      Returns:
      this instance
    • isCancelled

      public boolean isCancelled()
      Get if the timer is cancelled
      Specified by:
      isCancelled in class SimpleScheduler
      Returns:
      if the timer is cancelled
    • isRunning

      public boolean isRunning()
      Get if the timer is running
      Specified by:
      isRunning in class SimpleScheduler
      Returns:
      if the timer is running
    • isPaused

      public boolean isPaused()
      Get if the timer is paused
      Specified by:
      isPaused in class SimpleScheduler
      Returns:
      if the timer is paused
    • autoRestart

      public boolean autoRestart()
      Get if the timer auto restarts
      Specified by:
      autoRestart in class SimpleScheduler
      Returns:
      if the timer starts the timer automatically when it ends
    • isMultiThreading

      public boolean isMultiThreading()
      Get if the timer has multi-threading enabled
      Specified by:
      isMultiThreading in class SimpleScheduler
      Returns:
      if the timer runs on another thread
    • getOriginalTime

      public long getOriginalTime()
      Get the timer start time
      Specified by:
      getOriginalTime in class SimpleScheduler
      Returns:
      the timer start time
    • getPeriod

      public long getPeriod()
      Get the timer configured period
      Specified by:
      getPeriod in class SimpleScheduler
      Returns:
      the timer update period
    • getMillis

      public long getMillis()
      Get the timer milliseconds
      Specified by:
      getMillis in class SimpleScheduler
      Returns:
      the timer exact time