Schedule to Run Later

Now back to your main plugin: once you have the task defined over in its own class, you can create an object of that class from your main plugin using new, and schedule it to be run in the future using addSynchronousTask().

 
ExampleTask task = ​new​ ExampleTask(plugin);
 
Canary.getServer().addSynchronousTask(task);

plugin should be a variable that’s set to your main plugin. If you’re putting this code in a non-static function in your plugin, you can use the Java keyword this, which means “this plugin object.” If you’re putting this code in a static function, you need a static variable (like plugin) that has previously been set to the plugin. For example, in an object function (a method) like your constructor or enable ...

Get Learn to Program with Minecraft Plugins, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.