Scheduled Execution
From Multiverse
| MARS |
| Mob Server |
| Object Manager |
| Combat Server |
|
Abilities and Combat Plugin • Combat Statistics • Extending the MARS Combat System • Group System • Trainer Plug-in • Professions • Experience System |
| Tutorials |
| Other Examples |
|
Triggering an Action with a Mouseclick • Scheduled Execution • Working with Sound • Creating a Teleporter |
The class multiverse.server.engine.Engine provides a mechanism for scheduling tasks for execution at some future time. To schedule a task:
- Create a class (in Java or Python) that implements the
Runnableinterface. - Call
Engine.getExecutor().scheduleAtFixedRate()with the following arguments:- The class that implements
Runnable. - Initial delay before execution.
- Subsequent interval between executions.
- Time unit (TimeUnit.NANOSECONDS, TimeUnit.MICROSECONDS, TimeUnit.MILLISECONDS, or TimeUnit.SECONDS)
- The class that implements
This method returns a java.util.concurrent.ScheduledThreadPoolExecutor object, that you can use in a variety of ways to schedule execution.
Here is a Python example:
class PeriodicExample (Runnable):
def run(self):
WorldManagerClient.sendSysChatMsg("periodic example")
The line below runs this periodic example, initially 30 seconds after execution of the statement, then subsequently every 60 seconds:
Engine.getExecutor().scheduleAtFixedRate(PeriodicExample(), 30, 60, TimeUnit.SECONDS)
