Solved Cancel Repeating Task

Discussion in 'Plugin Development' started by xYourFreindx, Jun 11, 2014.

Thread Status:
Not open for further replies.
  1. This seems like it should be really simple, seeing as so many plugins MUST use this..​
    But all the ways I've tried to do this has ended up not working or not being what I need.​
    Simply, I'm trying to implement a pvp/pve timer, into my plugin so as to prevent players from initiating the command and escaping battle.​
    Here's it's current state...​
    Code:java
    1.  
    2.  
    3. main.pvpTimer.put(entiti.getUniqueId().toString(), main.pvpTimer.get(e.getEntity().getUniqueId().toString()).intValue() - 1);
    4. int ID = main.getServer().getScheduler().scheduleSyncRepeatingTask(main, new Runnable(){
    5. public void run() {
    6. if (main.pvpTimer.get(entiti.getUniqueId().toString()).intValue() != 0 ){
    7. main.pvpTimer.remove(entiti.getUniqueId().toString());
    8. entiti.sendMessage(ChatColor.YELLOW + "OUT " + main.pvpTimer.get(entiti));
    9. }else{
    10. Bukkit.getScheduler().cancelTask(ID);
    11. }
    12. }
    13. },0L, 20 * main.getConfig().getLong("CameraMode.PvpTimer"));

    The ID is underlined in yellow where I define it, and in red where I try and use it.​
    Changing it to "final int ID" also doesn't help.​

    If all else fails and nobody can offer a clean solution, I'll just use a while loop and stick a delayed task runner in there.

    EDIT:
    While Loop = Crashed sever.

    ProTip:
    Do not use While Loop.

    Ever. ​

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

    drtshock

    Store the id of the task and then cancel it using that if you need.
     
  3. drtshock As I pasted in my original post, I've tried that.
    Obviously I must be doing something wrong, because it doesn't recognize it.
    Could you look at my fist posted code, and tell me if you see anything wrong? Because it certainly isn't working.
     
  4. Offline

    drtshock

  5. drtshock Thanks! That's just the thread I was searching for.
     
Thread Status:
Not open for further replies.

Share This Page