Skip to content

Fix leash event for boats and elytra#13697

Open
harrybridgen wants to merge 1 commit intoPaperMC:mainfrom
harrybridgen:fix-leash-event
Open

Fix leash event for boats and elytra#13697
harrybridgen wants to merge 1 commit intoPaperMC:mainfrom
harrybridgen:fix-leash-event

Conversation

@harrybridgen
Copy link

@harrybridgen harrybridgen commented Mar 12, 2026

Fixes #13696

This fix needs testing

@harrybridgen harrybridgen requested a review from a team as a code owner March 12, 2026 10:13
@github-project-automation github-project-automation bot moved this to Awaiting review in Paper PR Queue Mar 12, 2026
@Doc94
Copy link
Member

Doc94 commented Mar 12, 2026

I run this and works.. but i find one case where with Elytra+Rockets and a boat leashed not sure how the leash was cut even with the cancel in true... and the console flood with the message added in the event... but maybe that is another thing...

    @EventHandler
    public void onPlayerUnleashEntityEvent(final PlayerUnleashEntityEvent event) {
        this.getLogger().info("PlayerUnleashEntityEvent");
        this.getLogger().info("event.getPlayer() -> " + event.getPlayer().getName());
        this.getLogger().info("event.getEntity() -> " + event.getEntity().getName());
        event.setCancelled(true);
    }

    @EventHandler
    public void onEntityUnleashEvent(final EntityUnleashEvent event) {
        this.getLogger().info("EntityUnleashEvent");
        this.getLogger().info("event.getReason() -> " + event.getReason());
        this.getLogger().info("event.getEntity() -> " + event.getEntity().getName());
        event.setCancelled(true);
    }

@harrybridgen
Copy link
Author

harrybridgen commented Mar 12, 2026

I run this and works.. but i find one case where with Elytra+Rockets and a boat leashed not sure how the leash was cut even with the cancel in true... and the console flood with the message added in the event... but maybe that is another thing...

    @EventHandler
    public void onPlayerUnleashEntityEvent(final PlayerUnleashEntityEvent event) {
        this.getLogger().info("PlayerUnleashEntityEvent");
        this.getLogger().info("event.getPlayer() -> " + event.getPlayer().getName());
        this.getLogger().info("event.getEntity() -> " + event.getEntity().getName());
        event.setCancelled(true);
    }

    @EventHandler
    public void onEntityUnleashEvent(final EntityUnleashEvent event) {
        this.getLogger().info("EntityUnleashEvent");
        this.getLogger().info("event.getReason() -> " + event.getReason());
        this.getLogger().info("event.getEntity() -> " + event.getEntity().getName());
        event.setCancelled(true);
    }

I think I may have found another bug:
In Leashable.java lines 160-167, it doesn't respect if the event was cancelled and removes the leash anyway. I'll update the code to fix this.

@harrybridgen
Copy link
Author

@Doc94 Please try your test plugin again, I have pushed a potential fix to the leash breaking even though it was cancelled.

@Lulu13022002
Copy link
Contributor

In Leashable.java lines 160-167, it doesn't respect if the event was cancelled and removes the leash anyway. I'll update the code to fix this.

I think this has been done on purpose see: #4993 and the javadoc of the EntityUnleashEvent

@harrybridgen
Copy link
Author

In Leashable.java lines 160-167, it doesn't respect if the event was cancelled and removes the leash anyway. I'll update the code to fix this.

I think this has been done on purpose see: #4993 and the javadoc of the EntityUnleashEvent

You're absolutely right. Thanks for clearing that up. I removed my change, leaving only the original fix.

@harrybridgen harrybridgen force-pushed the fix-leash-event branch 2 times, most recently from 324da0b to 3166311 Compare March 12, 2026 19:28
@kennytv
Copy link
Member

kennytv commented Mar 13, 2026

I couldn't find what happens when any other entity dies, that might be worth investigating too

@Doc94
Copy link
Member

Doc94 commented Mar 13, 2026

I couldn't find what happens when any other entity dies, that might be worth investigating too

Maybe just call the PLAYER_UNLEASH like here?

i dont find another case... because things like llama despawn or copper golem turn into statue not call the event for notice...

@harrybridgen
Copy link
Author

harrybridgen commented Mar 13, 2026

@kennytv @Doc94 I found that in Leashable.java the reason for unleashing in tickLeash was wrong, so I updated it to have the new LEASHED_GONE reason. Line 157 in Leashable.java.

Additionally, I found that when an entity changes dimensions, the unleash reason is UNKNOWN. Maybe we could update this so it has a new CHANGE_DIMENSION reason, or we can use the new LEASHED_GONE reason?

And when a mob starts riding another entity, the unleash reason is also UNKNOWN. Maybe a new STARTED_RIDING reason would work here? Line 1487 in Mob.java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

EntityUnleashEvent is not fired under specific circumstances

4 participants