How do i create a warmup for teleports

Discussion in 'Plugin Development' started by Michiman, Jun 10, 2015.

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

    Michiman

    Ive looked at a few tutorials on how to code this but it isn't working. How do i make a warmup for like tpa and home so if the player gets hit it cancels the teleport. Like it takes 3 seconds to teleport and if they move or get hit it will cancel the teleport and tell them.
     
  2. Add them to an ArrayList
    Start a new syncDelayedTask
    Inside it, check if the player is still in the ArrayList. If he is, remove him from the ArrayList and teleport
    In PlayerQuitEvent and EntityDamageEvent (check inheritance) remove the player from the ArrayList
     
  3. Offline

    Michiman

    yea thats what im reading but i dont know what order to put them in or what to put were. I also keep seeing people saying to use hashmaps. But i dont know how to add them to the array. and check if they are there
     
  4. Offline

    CraftBang

    @FisheyLP where exactly is the part with the movement? :p
    I guess making a HashMap<String, Location> and save the BLOCK location to the hashmap.
    Then on PlayerMoveEvent check if the Location the player is moving to (And use getBlock, and then get Location again) is not equal to the location in the HashMap.
    If this happens, then remove the player from the HashMap :)

    By the way, don't forget to use the Location of the block instead of the normal location.


    EDITED: @FisheyLP outsmarted me so don't use a hashmap lol.

    Oh and @FisheyLP please correct me if I'm wrong about my Block location idea (or something else offcourse :))

    Oh and for DelayedTasks etc :
    https://bukkit.org/threads/task-manager-easy-schedulers.361669/
     
    Last edited: Jun 11, 2015
  5. No HashMap needed. For the MoveEvent:
    if (e.getFrom().getYaw() == e.getTo().getYaw() && e.getFrom().getPitch() == e.getTo().getPitch()) {
    Remove from ArrayList

    @CraftBang there is no Util/extra class needed to make a delayed task. It's really simple with bukkit:
    Code:
    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    public void run() {
    //code
    }
    }, 3 * 20);
    3 * 20 is for 3 seconds (20 ticks is 1 second)
     
    CraftBang likes this.
  6. Offline

    CraftBang

    @FisheyLP ow that's true though, my bad will edit it :).
    I just really like the Util since it looks way better :p

    But is the PlayerMoveEvent triggered if the player gets teleported? I don't think so
    Not really really important though but in fact the player does "move" so should be removed from the ArrayList. (In my opinion)
    But it's what @Michiman wants, if he wants to he can add the PlayerTeleportEvent I guess.
     
  7. Offline

    Michiman


    OK thanks but what do i put in the //code area. and do i put this in a listener?
     
    Last edited: Jun 11, 2015
  8. Offline

    Michiman

    *Bump* I didnt know i was allowed to bump posts

    But what is suppose to go inside of the //code area.
     
Thread Status:
Not open for further replies.

Share This Page