Teleport Timer, Disabled if player is moved.

Discussion in 'Plugin Development' started by Eggspurt, Jul 17, 2015.

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

    Eggspurt

    I understand you use events to do this, but I am not sure how to do it properly, perhaps an example would do me well!


    All I want to do is make it so when a player types /spawn it takes 5 seconds, I understand what essentials is, but I want to program it myself for learning purposes.
     
  2. Offline

    BrickBoy55

    @Eggspurt I'd make an ArrayList<Player> and in your spawn code, add them to the list. Create a task that will wait 5 seconds to teleport and check if they are still in the list, if they are teleport them. In a PlayerMoveEvent, check if they are in the list, if they are remove them.
     
  3. Offline

    Eggspurt

    Ahh alright that makes sense. I'll try something out and let you know! :)

    How exactly do tasks work? Do I have to cancel the task after I use it? Or does it always loop even if it's being used or not?

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

    Jimfutsu

    You would create a delayed task to check if the player is in the array list, if he is, then TP, if he isn't then don't TP.
     
  5. Offline

    Eggspurt

    I figured it out, I am just asking. When you finish the task, does it keep looping the task?
     
  6. Offline

    Jimfutsu

    No, a delayed task does not repeat after it is complete, only a repeating task.
     
  7. Offline

    Eggspurt

    Well, do I have to do something to cancel a repeating task? Or does it not matter if it keeps repeating. It's in a command when the task is called.
     
  8. Offline

    nj2miami

    To cancel a repeating task, either you must check for a condition within in and self cancel or store the task to be cancelled by some other method later on.

    http://wiki.bukkit.org/Scheduler_Programming
     
  9. Offline

    Eggspurt

    Code:
              BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
               scheduler.scheduleSyncRepeatingTask(plugin, new Runnable() {
    How would I cancel this task? I understand I need to the run code as-well but I am just showing you what type of Task it is.
     
Thread Status:
Not open for further replies.

Share This Page