1.15.2 VehicleExitEvent Firing on Entering Vehicle

Discussion in 'Spigot Plugin Development' started by OutOfTime, Jan 22, 2020.

  1. Hey all,
    I'm not quite sure if this is an API bug, or if I'm just stupid. Whilst troubleshooting a bug in one of my plugins, I noticed that trying to get into a boat appeared to be throwing a VehicleExitEvent. Now, that's rather peculiar, as the player is trying to enter a vehicle, not exit one.

    I tried testing this on a fresh server with just a 1.15.1 spigot jar and a test plugin installed. Same thing, trying to enter a boat throws an identical event to leaving one. Am I missing something here, or is this possibly the API being wacky again?

    I've also tried this using EntityDismountEvent; same result. The event fires in both boarding and exiting a boat.

    Some Googling indicated that the VehicleExitEvent has been causing problems for some time, and the EntityDismountEvent was suggested as a backup, but others have reported that there are problems with this too. Is this an issue I've somehow failed to notice before now?
     
  2. md_5

    Administrator Developer

    I suggest you open a bug report, if that is true it clearly sounds like a bug
     
  3. TeamBergerhealer

    Supporter

    I've noticed this too, with minecarts, but the situation was different. Judging by my code comment here, a vehicle exit event was fired when a vehicle enter event was cancelled. Are you or another plugin cancelling the enter event?

    I haven't noticed the issue you're describing myself, but I have heard from others that the vehicle enter/exit events have been causing them problems too, so it wouldn't surprise me if it is indeed a bug.
     
  4. Meanwhile the bug is getting fixed by spigot you can create a hashmap that contains whether a player is in an vehicle or not.

    Code (Java):
    List<UUID> inVehicle = new ArrayList<>();

    onVehicleEnter
    inVehicle.add(player#getUUID)

    onVehicleLeave
    boolean inVehicle = false;
    if (inVehicle = this.inVehicle.contains(uuid))
    this.inVehicle.remove(uuid);
    it's only an idea.
     
  5. I am canceling it, however when testing, I tried entirely removing the cancellation functionality and just output when the event was thrown. I still got a VehicleExitEvent then.

    In my case, I've solved it by using a 1-tick delay; that way, the result of the event is already completed, and I can tell based on whether a player is in a vehicle or not after the 1-tick delay to see which direction they were going, entering or leaving. Thanks for the suggestion though :)