Start timer in new Thread

Discussion in 'Plugin Development' started by Welite, Mar 5, 2014.

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

    Welite

    Hi, is there any way how to start Bukkit timer in new Thread ?


    Exactly this timer:
    Code:java
    1.  
    2. Bukkit.getScheduler().runTaskTimer(plugin, new Runnable() {
    3. @Override
    4. public void run() {
    5.  
    6. //repeating timer and inside this timer I need to run other timers
    7.  
    8. Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    9. @Override
    10. public void run() {
    11.  
    12. //like this
    13.  
    14. } }, 20*1+20L);
    15.  
    16.  
    17. } }, 20L, (20*1) + 7*20L);
    18. //and finally I want to cancell it
    19.  



    My problem is that I am working on minigame plugin and I need to run this timer while arena is running and I need new thread or something because when the game starts in second arena I need to create "new" timer because I cannot override the first timer because the game in arena 1 is still running for example.
     
  2. Offline

    CubieX

    What hinders you to create a task within a task?
    You solution above would work.
    Just make sure you can still manage those timed tasks (when is what running and for how long and how often)
    in your brain. ;)

    And please don't mix up "thread" and "task".
    Your synchronous timer tasks defined in your post are all run by the servers main thread.
    Creating different threads is not trivial. But you should not need this here anyway.
     
  3. Offline

    Welite

    CubieX
    My problem was how to cancel the timer if there are 2 instances of timer running at the same time. I think I have solved it now my using Threads.
     
  4. Offline

    Barinade

  5. Offline

    CubieX

    Save the TaskID you get from the timer call in some array or HashMap and then you can cancel tasks by using
    Code:
    Bukkit.getServer().getScheduler().cancelTask(myTaskID);
     
  6. Offline

    Garris0n

    Or use BukkitRunnables and you can use this.cancel().

    @OP What do you plan to do with this async task?
     
Thread Status:
Not open for further replies.

Share This Page