Skip to content

Instantly share code, notes, and snippets.

@OskarZyg
Created January 23, 2021 00:43
Show Gist options
  • Save OskarZyg/1d3373bd86ff9d34f11e505b8cd0c3aa to your computer and use it in GitHub Desktop.
Save OskarZyg/1d3373bd86ff9d34f11e505b8cd0c3aa to your computer and use it in GitHub Desktop.

BukkitRepeatingTask

RepeatingTask Class that is useful for managing bukkit repeatingTasks

I didn't make this, I just cant find OC.

Usage:

RepeatingTask repeatingTask = new RepeatingTask(this, 0, 20) {
  
  @Override
  public void run() {
    cancelLoop();
  }
  
}

This will run a loop and cancel it.

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public abstract class RepeatingTask implements Runnable {
private int taskId;
public RepeatingTask(JavaPlugin plugin, int arg1, int arg2) {
this.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this, (long)arg1, (long)arg2);
}
public void cancelLoop() {
Bukkit.getScheduler().cancelTask(this.taskId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment