Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isCurrentEvent API changes #4884

Merged

Conversation

TPGamesNL
Copy link
Member

@TPGamesNL TPGamesNL commented Jul 9, 2022

Description

A certain pattern was found a lot throughout Skript's source code, and likely also in many addons: in a syntax element, return false if !isCurrentEvent(SomeEvent.class), and cast to SomeEvent at runtime.
However, this pattern may lead to CCEs (see for example #4872), because there may be more than 1 currentEvent at parsetime. If the syntax element can handle only one of the currentEvents, but not another, this pattern will cause a CCE if the element is called with that other event type.

This should be fixed by adding runtime checks for the provided event, which is what most file changes in this PR are.
I've also added Javadocs to the isCurrentEvent methods, explaining the situation and what to do.


Target Minecraft Versions: any
Requirements: none
Related Issues: #4872

@TPGamesNL TPGamesNL added enhancement Feature request, an issue about something that could be improved, or a PR improving something. up for debate When the decision is yet to be debated on the issue in question labels Jul 9, 2022
@TPGamesNL TPGamesNL marked this pull request as draft July 9, 2022 10:21
@TPGamesNL TPGamesNL marked this pull request as ready for review July 9, 2022 10:37
@TheLimeGlass
Copy link
Contributor

TheLimeGlass commented Jul 12, 2022

Is this still in draft? Where are the methods mentioned? Why did you add instance checking of the events? Isn't the whole point of the isCurrentEvent to setup the getting method to instantly cast, as the init/isCurrentEvent does the instanceof checking?

I agree with the new methods, deprecate the old ones and default isCurrentEvent to isAnyCurrentEvent.

For ExprIP the boolean fields relating to the event can be removed and just use instanceof checking in the check/get method as the fields don't pose any use at that point for multiple event syntaxes.

@TheLimeGlass TheLimeGlass added the breaking changes Pull or feature requests that contain breaking changes (API, syntax, etc.) label Jul 12, 2022
@TPGamesNL
Copy link
Member Author

Talked with pickle in DMs about the changes, changed stuff around after that but forgot to edit the PR description.

PR description is now accurate again.

@TPGamesNL TPGamesNL removed breaking changes Pull or feature requests that contain breaking changes (API, syntax, etc.) up for debate When the decision is yet to be debated on the issue in question labels Jul 12, 2022
@TheLimeGlass
Copy link
Contributor

TheLimeGlass commented Jul 12, 2022

I'm still confused, this isn't going to fix addons. The original API idea changes should be applied for any and all?

@TPGamesNL
Copy link
Member Author

Said already on Discord, but leaving here for reference:
image

Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the question, but LGTM

TPGamesNL and others added 2 commits July 15, 2022 16:05
@TPGamesNL TPGamesNL merged commit 0372ad6 into SkriptLang:master Jul 15, 2022
@TPGamesNL TPGamesNL deleted the enhancement/is-current-event-change branch July 15, 2022 15:02
@TPGamesNL TPGamesNL mentioned this pull request Jul 27, 2022
ALOBugTea pushed a commit to ALOBugTea/Skript that referenced this pull request Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants