I am trying to pass the return value from task scheduling to an anonymous class, but I'm having problems. If I set the return value to a final variable, it says that it is not initialized:
final BukkitTask task = Bukkit.getScheduler().runTaskTimer(plugin, new Runnable() {
public void run() {
task.cancel();
}
}, 0L, 20L);
I also tried passing the variable by calling the method inside the anonymous class, however it changes the return type to void, and therefore I cannot pass the correct value:
BukkitTask temp = null;
temp = Bukkit.getScheduler().runTaskTimer(plugin, new Runnable() {
private BukkitTask task;
public void initTask(BukkitTask task) {
this.task = task;
}
public void run() {
task.cancel();
}
}.initTask(temp), 0L, 20L);
How to pass return value to an anonymous class inside code?
Rogue source
share