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.

enter image description here


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.