Teleportation Cancel

Discussion in 'Plugin Development' started by TomTheDeveloper, Mar 17, 2013.

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

    TomTheDeveloper

    Hey, i am trying to make an new minigame, but there is one thing that i can't figure out how to do it.

    When a player is standing on a platform, there is a message that says: "Stay on this platform for 6 seconds and you will be teleported to the spawn". But if he runs of the platform, it will say immediatly: "Teleportation Cancelled". How can i do this?

    First i check the coordinates, and i check if he is on the platform, then i put a delayed task, but how can i cancel it when he runs off of the platform?
     
  2. Offline

    Rprrr

    PlayerMoveEvent, add him to a list / some storage when he's entering the platform, start a repeating runnable, keep checking if he's still in the list, if he has been there for long enough, teleport him, remove him from the list and cancel the task.

    So in your PlayerMoveEvent listener you should:
    * Check if a player moves on the platform, if he wasn't in the list, add him to it.
    * Check if a player moves from (/ not on) the platform, if he was in the list, remove him from it.
     
    TomTheDeveloper likes this.
  3. Offline

    TomTheDeveloper

    Rprrr

    Hmm, i will try it out now, but i think there is one more thing i don't understand, i wil try it now, and if i don't get it, i will ask for more information

    Rprrr But i don't need to use repeated task, because the playermove event is performed many times in one second

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

    Barinade

    Save player location when it starts, have a player move event check and see if the location he's in equals the one that was saved at the start, if not then cancel
     
  5. Offline

    Murderscene

    Short answer: Bukkit.getScheduler().cancelTask(taskid)

    1) Create a hashmap of <Integer, Player>
    2) Add the player to the hashmap when he walks onto the platform
    3) Create a delayed task for 6 seconds and store its task id in the hashmap with the player
    4) If the player moves off the platform (PlayerMoveEvent) use Bukkit.getScheduler().cancelTask(taskid)
    5) Remove from the hashmap
     
  6. Offline

    TomTheDeveloper

    If you want the code, just ask it.
     
Thread Status:
Not open for further replies.

Share This Page