Writing a repeating task for a plugin
We already have a BukkitRunnable
class, so in order to run a task timer we just need to determine the delay and the period. We want the delay to be 0. That way if it is night when the plugin is enabled, the time will be set to noon right away. As for the period, we could repeat the task every second if we wanted to keep the sun always directly above. The task only contains one simple line of code so repeating it that often will not cause much lag to the server. However, repeating the task every minute will still prevent the world from ever growing dark. Therefore we will delay the task by 0 ticks and repeat it every 1200 ticks. The entire
AlwaysDay
plugin is given in the following code:
package com.codisimus.alwaysday; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; public class AlwaysDay extends JavaPlugin { @Override public void onEnable() { BukkitRunnable...