onPlayerEnterVehicleEvent passengers are null

The official Rising World Soundtrack is available!
You can also get the Soundtrack on Steam
  • The event onPlayerEnterVehicleEvent


    Java
    event.getVehicle().getPassenger(i)


    Returns null values. So even though the console states:


    Code
    Passengers (Vehicle 9390639): (0) Yahwho


    So if you try to grab the passenger Player object you get null.


    Java
    if(player == null){
        System.out.println("Name of passenger: is null");
    }
    [Java] Name of passenger: is null
  • Events are typically triggered before the particular action is performed. In this case, the PlayerEnterVehicleEvent is triggered first, and then (if the event was not cancelled by a plugin) the player is actually added to the vehicle.

    So when getting the passengers right when the event is triggered, the list won't contain the player yet who just entered the vehicle...


    In these cases, it's better to rely on the data of the event instead. In this case, you can get the player who entered the vehicle as well as the target seat from the PlayerEnterVehicleEvent.

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!