runTaskTimer outside of the main class

Discussion in 'Plugin Development' started by RFUDEO9EH, Mar 9, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    RFUDEO9EH

    Code :

    TimerTask:

    https://pastebin.com/zGxe3wVE

    Other Class (!= main class):

    TimerTask task = new TimerTask();
    task.runTaskTimer(X, 0, 20);

    I'm outside of the main class and I don't find what to put instead of "X" Help me pls !!
     
  2. Offline

    timtower Administrator Administrator Moderator

    @RFUDEO9EH Add a constructor to the class that takes the main class as argument.
     
  3. Offline

    RFUDEO9EH

    I don't know how to do that
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    RFUDEO9EH

    I have found this :

    private Main main;
    public PluginListeners(Main plugin) {
    this.main = plugin;
    }

    I put this before my @EventHandler and I put this.main in my runTaskTimer but this doesn't work. (I try too plugin in my runTaskTimer but Eclipse show an error). Tell me if I put this code at the right place and tell me if the code is right or not, and more... TY
     
  6. Offline

    timtower Administrator Administrator Moderator

    @RFUDEO9EH That is correct.
    What error do you get then?
    Can't help if I don't know what is wrong.
     
  7. Offline

    RFUDEO9EH

    the whole code :

    https://pastebin.com/4dfEr31F

    The eclipse error is "The constructor PluginListeners() is undefined"
    PluginListeners = the class with my event

    The error is in my main class :
     

    Attached Files:

  8. Offline

    timtower Administrator Administrator Moderator

    @RFUDEO9EH You need to change the line where you make a new PluginListeners so it takes the main instance as well.
     
  9. Offline

    RFUDEO9EH

    I try to put something between brackets of PluginListeners in the main class but I don't find what to put.
     
  10. Offline

    Wick

    It's basic java, you should pass the instance of your main class through there, which can be done by the

    Code:
    this
    keyword.
     
Thread Status:
Not open for further replies.

Share This Page