so im trying to make a minecraft plugin that sends a string of text in chat on random intervals. now im trying to make it start from line 1 every 5 minutes. i just dont know how to do this Ps: im new to java.
Random rand = new Random();
int n = rand.nextInt(3);
if (n == 1) {
Bukkit.broadcastMessage("yeet");
}
>Solution :
A quick search should lead you to this:
https://bukkit.org/threads/creating-a-loop.119088/
https://www.codegrepper.com/code-examples/java/bukkit+repeating+task+every+minute+spigot
The code, without testing it:
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
Bukkit.broadcastMessage("This message is shown immediately and then repeated every second");
}
}, 0L, 20L); //0 Tick initial delay, 20 Tick (1 Second) between repeats
It seems like in Minecraft, 20 Ticks equals to one second. So you should calculate 20 x 60 x 5 to get the amount of ticks needed for 5 minutes.
Try 6000.
I also recommend to you to read the Javadoc of the Bukkit project.
This should lead you to the current function that is used.