Solved Tasks

Discussion in 'Plugin Development' started by TehVoyager, Nov 3, 2013.

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

    TehVoyager

    Hello, I have a game plugin and I need to run a countdown and when it gets to 0 end the task. how would i do that?
    I have tried using the scheduler but I am not able to cancel the task /:
    Any help is appriciated.

    Code:java
    1. public void onEnable(){
    2. new ArenaManager(this);
    3. ArenaManager.getManager().getArena().setGameState(GameState.Lobby);
    4. Bukkit.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
    5. //CountDown from 600 to 0 and do ArenaManager.getManager().getArena().startGame when its 0 then stop the task,
    6. }


    Has anybody used a countdown or have a different method?

    The trouble I'm having is when the counter is 0 I can't cancel the task

    B
    U
    M
    P

    How do I get the id of the task I created?

    No replys? I'll check again in the morning

    <merged bumps xD - Iroh>

    Bump

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

    TehVoyager

    99 views, no replys. Is this possible or am I doing something wrong
     
  3. Offline

    The_Doctor_123

    TehVoyager
    Use:
    Code:java
    1.  
    2. BukkitTask task = Bukkit.getScheduler().runTaskTimer(<Plugin Instance>, <Runnable>, <Init Delay>, <Repeat Delay>);
    3.  

    To cancel:
    Code:java
    1.  
    2. task.cancel();
    3.  

    I might be a little off, I'm not on my computer right now.
     
  4. Offline

    TehVoyager

    The_Doctor_123
    I've tried to do that but I don't know what to do for the runnable, I made a countdown class the implemented runnable and put the run method but it didn't work

    The_Doctor_123
    When I try this it says that count hasn't been initialized
    Code:java
    1. BukkitTask count = Bukkit.getScheduler().runTaskTimer(this, new Runnable(){
    2.  
    3. @Override
    4. public void run() {
    5. if(counter == 0){
    6. count.cancel();
    7. }
    8. }
    9.  
    10. }, 0, 20);


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

    The_Doctor_123

    TehVoyager
    Yes, count hasn't been defined yet to the Runnable's knowledge. You can define a Runnable and make a method to pass on the BukkitTask Object. Or, don't cancel the task inside of the Runnable.
     
Thread Status:
Not open for further replies.

Share This Page