Package net.risingworld.api
Class Timer
java.lang.Object
net.risingworld.api.Timer
A timer which executes at specified intervals.
 
 
Example: Create and start a timer which executes every minute and broadcasts a message 
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic TimerfindTimer(int id) Looks if there is an active timer with the provided id.intgetID()Gets the ID of this timer.floatGets the remaining initial delay (seconds) of this timer.floatGets the interval (seconds) of this timer.floatGets the passed seconds (i.e how long this timer is already active).intGets how often the timer is supposed to trigger / repeat.getTask()Gets the task which will be executed once the timer triggers, or null if no task was set for this timer.floatgetTick()Used internally! Returns the current "tick" of this timer.booleanisActive()Gets whether or not this timer is currently active.booleanisKilled()booleanisPaused()Gets whether or not this timer is currently paused.voidkill()Kills the timer and releases all resources which belong to this timer.static booleankillTimer(int id) Kills the timer which has the provided id.voidpause()Pauses this timer.voidreinit(float interval, float delay, int repetitions) voidsetInitialDelay(float delay) Sets the initial delay for this timer.voidsetInterval(float interval) Sets the interval for this timer.voidsetRepetitions(int repetitions) Sets the amount of repetitions, i.e how often the timer is supposed to trigger / repeat.voidSets a new task which will be executed once the timer triggers.voidsetTick(float tick) Used internally! Do not call this method manually.
 Increments the internal "tick" of this timer.voidstart()Starts the timer.static booleantimerExists(int id) Determines if an active timer with the provided id exists.
- 
Constructor Details- 
TimerCreates a new timer.- Parameters:
- interval- the interval in seconds. Only applies to subsequent repetitions (i.e does not apply to first execution, in this case, set the initial delay instead).
- delay- the initial delay in seconds.
- repetitions- determines how often the timer should repeat. Use 0 if the timer should only trigger once, or -1 if the timer should repeat infinitely.
- task- a runnable which is executed when the timer triggers. It's allowed to provide- nulland set the task at a later stage (see- setTask(java.lang.Runnable)).
 
 
- 
- 
Method Details- 
startpublic void start()Starts the timer. Has no effect if the timer is already active.
- 
pausepublic void pause()
- 
reinitpublic void reinit(float interval, float delay, int repetitions) 
- 
killpublic void kill()Kills the timer and releases all resources which belong to this timer.
 It is not possible to resume or restart the timer, so only call this method if you want to discard the timer.
- 
isActivepublic boolean isActive()Gets whether or not this timer is currently active. Note that the timer is still considered as "active" if it's paused (to check if it's paused, seeisPaused()).- Returns:
- true if the timer is active, false if not.
 
- 
isPausedpublic boolean isPaused()Gets whether or not this timer is currently paused. Note that this does not takeisActive()into account.- Returns:
- true if the timer is paused, false if not.
- See Also:
 
- 
isKilledpublic boolean isKilled()
- 
setIntervalpublic void setInterval(float interval) Sets the interval for this timer.- Parameters:
- interval- the new interval in seconds.
 
- 
getIntervalpublic float getInterval()Gets the interval (seconds) of this timer.- Returns:
- the interval in seconds.
 
- 
setInitialDelaypublic void setInitialDelay(float delay) Sets the initial delay for this timer. Has no effect if the timer has already started.- Parameters:
- delay- the initial delay in seconds.
 
- 
getInitialDelaypublic float getInitialDelay()Gets the remaining initial delay (seconds) of this timer. Returns 0 if the timer has already started.- Returns:
- the remaining initial delay in seconds.
 
- 
setRepetitionspublic void setRepetitions(int repetitions) Sets the amount of repetitions, i.e how often the timer is supposed to trigger / repeat. Set to 0 if the timer should only trigger once.- Parameters:
- repetitions- the amount of repetitions.
 
- 
getRepetitionspublic int getRepetitions()Gets how often the timer is supposed to trigger / repeat. This value decrements every time the timer triggers (unless it is set to -1).- Returns:
- the remaining amount of repetitions.
 
- 
getTaskGets the task which will be executed once the timer triggers, or null if no task was set for this timer.- Returns:
- the Runnable task.
 
- 
setTaskSets a new task which will be executed once the timer triggers. If you set null, no task will be executed when the timer triggers. If another task it already set, it will be overridden.- Parameters:
- task- the new Runnable task.
- Example: Create timer and kill it when a certain condition is true
 
- 
getIDpublic int getID()Gets the ID of this timer.- Returns:
- the timer ID
 
- 
setTickpublic void setTick(float tick) Used internally! Do not call this method manually.
 Increments the internal "tick" of this timer.- Parameters:
- tick- time per frame.
 
- 
getTickpublic float getTick()Used internally! Returns the current "tick" of this timer.- Returns:
- the "tick", i.e the internal timer counter.
 
- 
getPassedSecondspublic float getPassedSeconds()Gets the passed seconds (i.e how long this timer is already active).- Returns:
- the amount of passed second since start of the timer.
 
- 
findTimerLooks if there is an active timer with the provided id.- Parameters:
- id- the id of the timer.
- Returns:
- the timer with the provided id, or null if no timer with this id was found.
 
- 
killTimerpublic static boolean killTimer(int id) Kills the timer which has the provided id. If no timer was found, nothing happens.- Parameters:
- id- the timer id.
- Returns:
- true if the timer with the provided id existed and if it wasn't killed yet, false if there was either no such timer or if the timer was already killed.
 
- 
timerExistspublic static boolean timerExists(int id) Determines if an active timer with the provided id exists.- Parameters:
- id- the id of the timer.
- Returns:
- true if a timer with the provided id exists, false if not.
 
 
-