Bukkit Scheduler - Help with adding a delay timer

Discussion in 'Plugin Development' started by unv_annihlator, Jan 10, 2012.

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

    unv_annihlator

    Okay so I have searched through forums and gone over the first 2 pages or so of threads that came from the search, and I have looked at the wiki and api documentation for the scheduler function.

    Now I have some questions. I am adding a timer to a teleport function inside a pre-existing plugin and I need to make it so that there is a 5 second timer (needs to be canceled by player moving or getting damaged by player). My main issue is that I can't figure out how to set it up. Like can I make the actual execution of the coding that I want to be delayed inside a function in my main .Java file and then call it (and pass parameters) to it from my command file? Also how would I cancel the task? I'm sure I can easily figure out how to check if it needs to cancel, just need to know the code to say to cancel it.

    Or if this isn't the method I should be using to delay a commands execution then what should I be using?

    Meanwhile I will keep searching and looking around, and I apologize if this is a commonly asked question but like I said I couldn't find anything that helped me understand it any better.



    EDIT: So I have now implemented the AsyncDelayedTask, but how (if possible) can I cancel this task if I say take damage?

    EDIT 2: So after looking around more I've realized that I can get the task ID from the function and also cancel it through this ID. I think I should be able to figure out how to keep track of the players task ID and how to cancel it, but if anyone wishes to give me tips or pointers that'd be greatly appreciated.

    TRIPLE EDIT!!!!: Got everything working, couple of assumptions that are made with it though but I can go back and edit that later. For those wondering I created the task, copied the ID into a players taskID variable, when they move or take damage it checks to make sure they have an active taskID (if taskID != -1) (I set the ID to -1 by default and also when I cancel a task or complete the task I set it to -1 (This prevents the canceling of non-existent tasks.) If need be I can post up my codes for it incase anyone else has issues.
     
Thread Status:
Not open for further replies.

Share This Page