[SPIGOT-4113] EntityDismountEvent implements Cancellable interface Created: 23/Jul/18  Updated: 28/Jul/18  Resolved: 27/Jul/18

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: BillyGalbreath Assignee: Hex
Resolution: Fixed Votes: 0
Labels: None

Attachments: Java Archive File TestPlugin.jar     Java Archive File TestPlugin2.jar    
Issue Links:
Cloners
is cloned by SPIGOT-4163 Inconsistent Behaviour Cancelling Ent... Resolved
Version: git-Spigot-ed1cec9-d4297cb

 Description   

The EntityDismountEvent should implement the Cancellable interface so plugins can cancel the event.

This feature would be useful for making mobs like Dolphins ridable since you get dismounted from mobs when in water.

Right now the only workaround is re-attaching the passenger, but results in a glitchy experience.

With a cancellable event the rider would never get dismounted for a much better user experience without all the visual glitchiness.



 Comments   
Comment by md_5 [ 28/Jul/18 ]

It’s more maintainable to keep the code changes at the call site, that way if the behaviour of those variables changes it will be caught in the update process.

Comment by BillyGalbreath [ 28/Jul/18 ]

Thank you for fixing this, although the way you did it was not necessary. The 'p' method should be named 'ejectPassenger' or 'removePassenger' and the Entity parameter is the passenger being ejected/removed. In the context of the 'p' method 'this' is the vehicle ejecting it's passenger. My suggestion was not a "blind" assignment at all.

Comment by BillyGalbreath [ 26/Jul/18 ]

Technically speaking, you could fix this by just setting the vehicle back when either of the events are cancelled. But since thats a requirement I figured why not just set it before firing the events so we have visibility of it using Entity#getVehicle() in the events and then removing it if the events were never cancelled...

Comment by BillyGalbreath [ 26/Jul/18 ]

Vehicle event is broken too.

TestPlugin2.jar

public class TestPlugin extends JavaPlugin implements Listener {
    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void on(VehicleExitEvent event) {
        event.setCancelled(true);
    }
}

Steps to reproduce:

1) lay down some rails

2) set minecart on rails

3) right click minecart to enter minecart

4) press shift to exit minecart

5) experience same thing (stuck in limbo, including all loss of control over minecart)

Comment by md_5 [ 26/Jul/18 ]

What about the vehicle event, its been cancellable for ages?

Comment by BillyGalbreath [ 26/Jul/18 ]

Try this one @md_5

1) Summon pig

2) Get carrot on a stick

3) Mount pig

4) Press shift to dismount pig

5) Make pig move using carrot on a stick

6) remove carrot on a stick from your hand

7) Watch as the server finally updates you back to your original position because you are stuck in limbo

Comment by Phoenix616 [ 26/Jul/18 ]

I can confirm that there is something fishy going on here: On a tamed horse I can't open the inventory anymore after trying to dismount. I can still move it client side though but when I relog I join back to where I first mounted it.

Comment by md_5 [ 26/Jul/18 ]

Tested with villagers when I implemented the event and could not reproduce.

Comment by BillyGalbreath [ 26/Jul/18 ]

TestPlugin.jar

public class TestPlugin extends JavaPlugin implements Listener {
    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void on(PlayerInteractAtEntityEvent event) {
        event.getRightClicked().addPassenger(event.getPlayer());
    }

    @EventHandler
    public void on(EntityDismountEvent event) {
        event.setCancelled(true);
    }
}

Steps to reproduce:

1) Right click any entity to mount them (like a cow, or whatever)

2) Press shift to dismount

3) Experience being stuck in limbo. Cant move, cant dismount. (even the entity you mounted wont move. sometimes it looks like it tries, but its stuck, too)

Comment by md_5 [ 26/Jul/18 ]

I tested this and did not see any issues with cancelling the dismount event.
Can you please be more specific about how to reproduce the issue; and why does that not affect the existing vehicle event.
Also that code to just blindly set .ax before firing the event and then remove it after looks incredibly suspicious to me.

Comment by Hex [ 26/Jul/18 ]

Reopened for further evaluation.

Comment by BillyGalbreath [ 26/Jul/18 ]

This actually isn't finished. There's one important thing that wasn't implemented, and that's the "vehicle" gets lost (field Entity#ax).

To fix, you would simply have to re-set the vehicle, then if the events (both vehicle and dismount events) were not cancelled, set the vehicle back to null.

Here is a screenshot to aid in the implementation:

Without this, cancelling the dismount event will half eject the player, leaving them in a state of "being stuck" where they are in limbo. stuck between mounted and unmounted.

 

Generated at Tue Apr 22 04:41:55 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.