-
Notifications
You must be signed in to change notification settings - Fork 0
Timers
BearCommands offers a new improved and cross-platform way to work with delayed tasks: timers. In this section we will look on how to work with them and how to use parameters.
The basic type of timer is the object type Timer. You can work with them using many constructors. The simpler one is:
public Timer(Runnable action);
which requires a runnable (the action that should be delayed). Keep in mind that creating the Timer object does not run it, but only prepares it. To start it you are required to use the start method:
public void start(IBearPlugin<?> plugin, double duration, boolean async);
which requires the plugin (that needs to be an implementation of IBearPlugin),
the duration (in seconds) and a boolean to enable async (only for Bukkit).
You can also use one constructor to create and start the Timer:
public Timer(IBearPlugin<?> plugin, double duration, boolean async, Runnable action);
A TimerIntermediateAction is an object that represents an action (runnable) that should be run at a certain moment in time:
public TimerIntermediateAction(double time, Consumer<Double> action);
You can use this object to create tasks that should be run before the final task of your Timer (for example a counter-timer).
To add it on the timer you can either use the addIntermediateActions method or pass them in the constructors:
public void addIntermediateActions(TimerIntermediateAction... intermediateActions);
public Timer(IBearPlugin<?> plugin, double duration, boolean async, Runnable action, TimerIntermediateAction... intermediateActions);
InfiniteTimer is a special implementation of Timer that allows to repeat the task specified indefinitely (replicating the functioning of runTaskTimer in Bukkit). By default the task is run every seconds, but you can change the delay using the Timer method:
public void setInterval(double interval);
Obviously, specifying the duration for this type of Timer is useless, since you can stop it only by using the methods pause()
(that actually pauses the task, to later be resumed using resume()
) or stop()
.
- Home
- How to start a plugin
- Work with Configuration Files
- Work with Enums
- Work with Commands
- Work with Custom Players
- Work with Messaging Channels
- Creating custom SavableObjects
- Timers
- General Utils
- Placeholders
- Bukkit Utils
- Velocity Utils