I want to make an Repeating Task whisch isn't in the main Class. ("Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {},20,20);")
But it says that it can't resolve the method.
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityI want to make an Repeating Task whisch isn't in the main Class. ("Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {},20,20);")
But it says that it can't resolve the method.
Instead of the this
you need to pass an instance of the main class to the method. You can achieve this by using the constructor. When you create the Listener class (wich shouldn't be named listener BTW) you need to pass the instance of the main class to it.
//Listener class
<Main class> instance;
public Listener(<Main class> instance) {
this.instance = instance;
}
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, new Runnable() {...});
//Somewhere in the main class
Listener listener = new Listener(this);
Make sure to use this
when you pass the instance of the main class to the listener, because if you use new <Main class name>()
it will throw an exception.