Solved delayed task not working in static method

Discussion in 'Plugin Development' started by dan14941, Oct 8, 2014.

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

    dan14941

    here is my code
    Code:
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                  public void run() {
                      Bukkit.getServer().broadcastMessage("This message is broadcast by the main thread");
                  }
                }, 30L);
    but because its inside a static method it gives me an error on "this" how do i fix it?
    (yes it has to be in a static method! don't ask why)
     
  2. Offline

    AdamQpzm

    dan14941 Show us the full code, otherwise we're going to assume that it does not need to be a static method. Such things rarely do in cases such as this.
     
    nlthijs48 likes this.
  3. Offline

    dan14941

    AdamQpzm i told you i do need a static and thats that! I think i need to make an instance of my class? like something to do with this.plugin?

    AdamQpzm if you want to discuss is on irc we can

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  4. Offline

    AdamQpzm

    dan14941 Static is there for times in which an instance of the class wouldn't really make sense or maybe even would be wasteful. You wouldn't be able to use this.plugin to solve this. I could advice you on a workaround to this problem, however it is against my moral code to intentionally reinforce or recommend a bad design. So please, show me why it needs to be static, otherwise it does not need to be.
    -----
    Edit for the sake of everyone else: dan14941 contacted me on IRC, and the issue was resolved by removing the static from the method & variable.
     
Thread Status:
Not open for further replies.

Share This Page