How to cancel scheduler if player moves

Discussion in 'Plugin Development' started by KungFuGoat, Mar 25, 2014.

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

    KungFuGoat

    Hello,

    I'm making a basic /togglepvp plugin, but I'm not sure how to cancel the warmup if the player moves.

    When the player does the /togglepvp command, he gets put into an arraylist. Then I have a PlayerMoveEvent checking for a player in that arraylist. If the player moves, he gets kicked out of the list. I'm just not sure how to check if the player is no longer in that arraylist while the scheduler is running so I can cancel it.
     
  2. Offline

    Wolfey

    Well, if you're using a BukkitRunnable, you should use the cancel() method.
     
  3. Offline

    KungFuGoat

    Yes, but how do I get the scheduler to check if the player has indeed been kicked out of the arraylist?
     
  4. KungFuGoat
    Why don't you cancel the scheduler after you kick him from the arraylist (PlayerMoveEvent) ?
     
  5. Offline

    KungFuGoat

    Can I cancel from inside the player move event? I'm really new to this stuff :p
     
  6. I didn't try this yet, but I think you can.
     
  7. Offline

    KungFuGoat

    I don't seem to able to
     
  8. Offline

    amhokies

    KungFuGoat
    Create a Map with the player's name as a key, and the id of their task as the value. Then, in the PlayerMoveEvent listener, you can check the Map for the player's name, and if it does exist, the value returned with their name as a key can be used to cancel the task.
     
  9. Offline

    Barinade

    And here's one of the most common questions, again similar post
     
  10. Offline

    KungFuGoat

    amhokies

    Could you give me some example code please?

    He seems to be having a different issue :p

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

    Barinade

    Same concept
     
Thread Status:
Not open for further replies.

Share This Page