Solved Get location of entity after exiting vehicle

Discussion in 'Plugin Development' started by GusGold, Oct 22, 2013.

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

    GusGold

    Due to the mechanics of players exiting a vehicle, it is something that is calculated after the player exits, meaning that the VehicleExitEvent does not contain any information on where the player will end up being put.

    So then, what's the best way to get the players final position? My guess is something like a RunTask which runs 1 tick later, after the player has been allocated an exit position, but how do I include a parameter of the player's name to check it again in a runnable?

    Thanks.
     
  2. Offline

    Minecrell

    GusGold
    Did you try using this? :)
    Code:java
    1. @EventHandler
    2. public void onVehicleExit(VehicleExitEvent event) {
    3. final LivingEntity exited = event.getExited();
    4.  
    5. new BukkitRunnable() {
    6.  
    7. @Override
    8. public void run() {
    9. Location location = exited.getLocation();
    10. // Do something with the location
    11. }
    12. }.runTaskLater(this, 1L);
    13. }
     
    GusGold likes this.
  3. Offline

    GusGold

    No I didn't because I assumed
    Code:java
    1. exited.getLocation()
    wouldn't update to the new location, but rather maintain its value from the original evaluation.
     
  4. Offline

    Minecrell

    GusGold
    I don't know when the new location is calculated, but if it was calculated within the tick, it should be the right one.
     
  5. Offline

    GusGold

    Minecrell
    Yeah it gets calculated that next tick, and that works as well. Thanks!
     
    Minecrell likes this.
Thread Status:
Not open for further replies.

Share This Page