Creating a BukkitRunnable class
We will start by creating the AlwaysDay
plugin. All the code that we write for this plugin will be put inside the
onEnable
method. The first step to create a scheduled task is to create a BukkitRunnable
class This can be done with the following line of code:
BukkitRunnable runnable = new BukkitRunnable();
You will be given a warning telling you to implement abstract methods. NetBeans can automatically add the needed methods for you. The new method that is added for you is run
. This method will be called when the scheduler runs your task. For our new plugin, AlwaysDay
, we want the task to set the time of each world to noon.
BukkitRunnable runnable = new BukkitRunnable() { @Override public void run() { for (World world : Bukkit.getWorlds()) { //Set the time to noon world.setTime(6000); } } };
Note
Remember that time on a Minecraft server is measured in ticks. 20 ticks are equivalent to 1 second. The measurement of ticks is given as follows...