Sync repeating task help

Discussion in 'Plugin Development' started by crushh87, Jan 23, 2013.

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

    crushh87

    So I have a SyncRepeatingTask that I use for a countdown but for some reason the countdown will only run one time so...
    Player1 & Player2 Join
    Countdown occurs 10...9...8...7...6...etc...
    Players Box
    One Player wins
    They try to join and box again
    No Countdown

    Here is the code
    Code:
    task1 = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
     
    int count = 10;
    Player p;
    public void run(){
    if(!player1.isEmpty() && !player2.isEmpty()){
     
    for(String player : player1){
    p = Bukkit.getPlayer(player);
    p.sendMessage(ChatColor.GREEN + "Boxing Match Starting in " + ChatColor.GOLD +count+ ChatColor.GREEN + " seconds");
     
    }
     
    for(String player3 : player2){
    p = Bukkit.getPlayer(player3);
    p.sendMessage(ChatColor.GREEN + "Boxing Match Starting in " + ChatColor.GOLD +count+ ChatColor.GREEN + " seconds");
     
     
    }
     
    count--;
    if(count == -1){
    Bukkit.getScheduler().cancelTask(task1);
    for(String player : player1){
    p = Bukkit.getPlayer(player);
     
    p.teleport(spawn1);
    }
     
    for(String player3 : player2){
    p = Bukkit.getPlayer(player3);
     
    p.teleport(spawn2);
     
    }
     
     
    }
     
    }
    }
     
    }, 0L, 20L);
    Also i have tried it with an AsyncRepeatingTask
    and My guess is it has something to do with the canceling of the task somehow.

    In case I never explained this well enough the problem is the countdown running the second time BTW

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

    ZeusAllMighty11

    Call the task again?
     
  3. Offline

    chasechocolate

    Have you heard of BukkitRunnables? They are basically the new version of getScheduler(). I'll post an example when I get on my computer. But I would make a void that will start the countdown and when one player wins, call the method again.
     
  4. Offline

    crushh87

    Now the type of question I hate asking.... How do I call the task again?
     
  5. Offline

    chasechocolate

    I would make a method for it and just call the method again.
     
  6. Offline

    AstramG

    Sorry that this is an old thread, but I didn't want to start a new one. I have a same sort of system as this and I'm having issues canceling the task. I have the integer returned from scheduling the task and I try to cancel it with something like: Bukkit.getServer().getScheduler().cancelTask(taskid); but it doesn't seem to stop running and this is an issue with my plugin.
     
  7. Offline

    Compressions

    AstramG How did you assign the integer to the scheduler?
     
  8. Offline

    AstramG

    Compressions
    I'm using:
    task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, startingGame, 20L, 20L);
     
  9. Offline

    ShadowDog007

    AstramG
    That method is deprecated...

    You should be using this.
    Code:
    BukkitTask task = Bukkit.getScheduler().runTaskTimer(plugin, startingGame, 20L, 20L);
    task.cancel();
    Also you should have just made a new thread. Your issue is not related.
     
  10. Offline

    AstramG

    Thank you, I'm new to the scheduler styled programming so thank you for helping me with my issue :)
     
  11. Offline

    JUSTCAMH

    I created a listener with a scheduler and the scheduler doesn't work. Help?
     
Thread Status:
Not open for further replies.

Share This Page