Skip to content

Add EntityAttemptSmashAttackEvent#12113

Merged
lynxplay merged 5 commits into
PaperMC:mainfrom
Chaosdave34:feat/smash-attack-event
Feb 16, 2025
Merged

Add EntityAttemptSmashAttackEvent#12113
lynxplay merged 5 commits into
PaperMC:mainfrom
Chaosdave34:feat/smash-attack-event

Conversation

@Chaosdave34
Copy link
Copy Markdown
Contributor

Allows controlling of smash attacks. Makes it possible to bypass vanilla requirements (high enough fall distance and not flying) or set your own.

@Chaosdave34 Chaosdave34 requested a review from a team as a code owner February 14, 2025 22:23
@lynxplay
Copy link
Copy Markdown
Contributor

I think we'd benefit from potential passing the "result" as well? Also this is very much like, PlayerAttemptSmashAttackEvent (what a name). But just attack event might make it sound like this is the actual attack instead of just an event to control the check.

@Chaosdave34
Copy link
Copy Markdown
Contributor Author

PlayerAttemptSmashAttackEvent does describe the event better. What do you mean with "passing the "result" as well"?

@Chaosdave34 Chaosdave34 reopened this Feb 14, 2025
@lynxplay
Copy link
Copy Markdown
Contributor

Well, it would be nice for plugins to know if the player can actually perform such an attack via the event.
So, instead of computing the value after and using the Result type, we could instead just fire the event pre-cancelled in case players do not meet the requirements.

@Chaosdave34
Copy link
Copy Markdown
Contributor Author

Oh I see, yeah that makes sense. I would still run the event always when the player attempts a smash attack and add a boolean field canSmashAttack, that tells if the player is allowed to perform a smash attack before any modifications, because the event can still be used to to something if there has been a successful smash attack.

@lynxplay
Copy link
Copy Markdown
Contributor

Yea kinda. You'd basically mark the event as "cancelled" by setting event.setCancelled(!canSmashAttack(player)) before calling it.
That way, plugins can "override" vanillas behaviour by setting cancelled back tofalse.

@lynxplay
Copy link
Copy Markdown
Contributor

Hi, thanks for the changes. Right now tho, every attack is a smash attack because it is just passing the vanilla canSmash value to the event.
Just remove that boolean from the event again, as I said above, you'd just event.setCancelled(vanillaSmashFlagHere) before calling.

@Chaosdave34
Copy link
Copy Markdown
Contributor Author

My idea was that the information about the vanilla behviour persists, even when other plugins "uncancel" the event.
The event is set to cancelled depending on canSmashAttack in the event constructor.

@lynxplay
Copy link
Copy Markdown
Contributor

Fair point, that sounds smart!
Can you still (just for my sanity) move the cancelled setter to the callside instead of the constructor.
That is how all the other "pre-canclled" cases look, avoids surprises down the road.

@lynxplay lynxplay added type: feature Request for a new Feature. scope: api labels Feb 16, 2025
@lynxplay lynxplay force-pushed the feat/smash-attack-event branch from 9f94fdd to 8d14e25 Compare February 16, 2025 18:36
@lynxplay
Copy link
Copy Markdown
Contributor

After some more review, I did end up changing this back to result xD
Sorry for the extra work, thank you for the PR!

@Machine-Maker Machine-Maker changed the title Add EntitySmashAttackEvent Add EntityAttemptSmashAttackEvent Feb 16, 2025
@lynxplay lynxplay merged commit b9023b5 into PaperMC:main Feb 16, 2025
Y2Kwastaken pushed a commit to Y2Kwastaken/Paper that referenced this pull request Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: api type: feature Request for a new Feature.

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

3 participants