Is there a way to store references to runnables?

Discussion in 'Plugin Development' started by ohtwo, Apr 4, 2013.

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

    ohtwo

    Is there a way to store references to sync-runnables? I basically want to be able to start a runnable when an event fires, and be able to cancel it if another event fires. For example, start a runnable when a projectile hits a player. But if that player breaks a block, cancel the runnable. This is a pretty bad example, but that's the best way I can put it.
     
  2. Offline

    chasechocolate

    I suggest using BukkitRunnables and doing a check to see if something has happened (use a boolean) and use this.cancel().
     
    ohtwo likes this.
  3. Yes, you can, depending on what method you use you can either:
    - store BukkitTask object returned from getScheduler().schedule*() methods
    - store the class itself if it extends BukkitRunnable
    Both of those have a cancel() method.
    I also recommend using BukkitRunnable because it's easier, you can use cancel() and run*() directly on the class, and of course inside the class as well.

    If you're storing them per player then a simple Map<String, BukkitRunnable or BukkitTask> would do.
     
    ohtwo likes this.
  4. Offline

    ohtwo

Thread Status:
Not open for further replies.

Share This Page