Solved Task in a task?

Discussion in 'Plugin Development' started by ProMCKingz, Mar 11, 2015.

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

    ProMCKingz

    Hey, I have the following code. However, I was wondering how I could create another runnable after that one has ended.

    Code:
      Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
            public void run() {
                   inWar.remove(fac);
                        pa.sendMessage(prefix + ChatColor.RED + "Your preperation time has ended!");
                 }
                }, 100L);
             }
     
  2. Offline

    aaomidi

    Why don't you try it?
     
  3. Offline

    ProMCKingz

    @aaomidi
    My question was, how would i add another task in that scheduler. So that when that ends it starts another one
     
    Last edited: Mar 12, 2015
  4. Offline

    mythbusterma

    @ProMCKingz

    First off, that's a "task," not a "scheduler."

    Second, there's nothing stopping you from scheduling a task inside of another, so when you cancel one, schedule the other.
     
  5. Offline

    ProMCKingz

    @mythbusterma
    How though?
    This doesn't work. Sorry, never worked with delayed tasks, only worked with BukkitRunnables
    Code:
                              Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                     public void run() {
                                             inWar.remove(fac);
                                             pa.sendMessage(prefix + ChatColor.RED + "Your preperation time has ended!");
                                             Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                                 public void run() {
                                                         inWar.remove(fac);
                                                         pa.sendMessage(prefix + ChatColor.RED + "Your preperation time has ended!");
                                                 }
                                         }, 100L);
                                     }
                             }, 100L);
                        }
    The method scheduleSyncDelayedTask(Plugin, Runnable, long) in the type BukkitScheduler is not applicable for the arguments (new Runnable(){}, new Runnable(){}, long)
     
  6. Offline

    Rocoty

    Because in that context, 'this' refers to the enclosing Runnable instance, and not your plugin instance. If you want to refer to the enclosing plugin instance you must use MainClassName.this

    That works only because the Runnable is an inner non-static class. Or, more specifically, an anonymous class.

    HIH
     
Thread Status:
Not open for further replies.

Share This Page