The Bukkit scheduler is a very powerful tool, and it is easy to learn how to use it. It allows you to create repetitive tasks such as saving data. It also allows you to delay how long until a block of code is executed. The Bukkit scheduler can also be used to asynchronously compute lengthy tasks. This means that a task such as writing data to a file or downloading a file to the server can be scheduled to run on a separate thread to prevent the main thread, and thus the game, from lagging. In this chapter, you will learn how to do each of these by continuing to work on the Warper
teleportation plugin, as well as creating a new plugin called AlwaysDay
. This new plugin will ensure that it is always daytime on the server by repeatedly setting the time to noon. This chapter will cover the following topics:
Creating a
BukkitRunnable
classUnderstanding synchronous and asynchronous tasks and when they should be used
Running a task from a
BukkitRunnable
classScheduling...