bukkitScheduler Programming


Syntax

  • Bukkit.getScheduler().scheduleSyncRepeatingTask(Plugin plugin, Runnable task, int initialDelay, int repeatingDelay)
  • Bukkit.getScheduler().scheduleSyncDelayedTask(Plugin plugin, Runnable task, int initialDelay)
  • Bukkit.getScheduler().runTaskAsynchronously(Plugin plugin, Runnable task)
  • Bukkit.getScheduler().runTask(Plugin plugin, Runnable task)
  • new BukkitRunnable() { @Override public void run() { /* CODE */ } }.runTaskLater(Plugin plugin, long delay);
  • new BukkitRunnable() { @Override public void run() { /* CODE */ } }.runTaskTimer(Plugin plugin, long initialDelay, long repeatingDelay);

Remarks

Few Bukkit API methods are thread-safe and can be called asynchronously. For this reason, Bukkit API methods should only, with a few exceptions, be run on the main thread.

Code run inside of scheduleSync methods, as well as the runTask method will be run on the main thread.

Code run inside of runTaskAsynchronously will be run asynchronously from the main thread. Asynchronous methods are very useful for doing large math or database operations without lagging the server, yet will cause undefined behavior if used to call Bukkit API methods. For this reason, Bukkit API methods that should be run after the asynchronous code should always be put in a runTask method.