Skip to content

Conversation

NoyException
Copy link

Sometimes we want to know why an entity is removed in an easier way instead of listening EntityRemoveEvent. So here is the API.

@NoyException NoyException requested a review from a team as a code owner September 17, 2025 08:24
@github-project-automation github-project-automation bot moved this to Awaiting review in Paper PR Queue Sep 17, 2025
case UNLOADED_TO_CHUNK -> RemovalReason.UNLOADED_TO_CHUNK;
case UNLOADED_WITH_PLAYER -> RemovalReason.UNLOADED_WITH_PLAYER;
case CHANGED_DIMENSION -> RemovalReason.CHANGED_DIMENSION;
default -> null;
Copy link
Member

Choose a reason for hiding this comment

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

removal reason shouldn't blindly map to null, if there is a value we don't have mapped, it should be reported (and ideally prevented by having a test to validate that everything is mapped)

Copy link
Author

Choose a reason for hiding this comment

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

Sure! Let me see how to make a test

Copy link
Member

Choose a reason for hiding this comment

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

Does it really need a test? Switch expressions are exhaustive, so if reasons are added/removed, it will just fail to compile without a default case. Maybe one for testing the mapped names match? which, bleh

Copy link
Author

Choose a reason for hiding this comment

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

Does it really need a test? Switch expressions are exhaustive, so if reasons are added/removed, it will just fail to compile without a default case. Maybe one for testing the mapped names match? which, bleh

reasonable, then I'll just remove the default case and add a null case

Copy link
Member

Choose a reason for hiding this comment

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

I wasn't sure if the 'new' expressions changed something there, but, if that's the case then probs not a big deal, would be nice to have some form of validation to prevent desyncing of stuff, just a trivial thing which is easy to miss

Copy link
Author

Choose a reason for hiding this comment

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

Can these values not be generated?

Yeah it's more reasonable to generate it, but I'm not quite sure how to write the generator so I have to learn it. This may take some times...

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea it should be generated if you don't plan to add javadoc for each values, see https://github.com/PaperMC/Paper/blob/main/paper-generator/src/main/java/io/papermc/generator/Rewriters.java#L119 for an example (Panda$Gene). Then the switch can be replaced by apiEnum.valueOf(internalEnum.name()) with the null check.

Copy link
Author

Choose a reason for hiding this comment

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

Yea it should be generated if you don't plan to add javadoc for each values, see https://github.com/PaperMC/Paper/blob/main/paper-generator/src/main/java/io/papermc/generator/Rewriters.java#L119 for an example (Panda$Gene). Then the switch can be replaced by apiEnum.valueOf(internalEnum.name()) with the null check.

Thank you for your guidance! This is very helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks almost good, #argument was used for single argument on the builder but in your case your enum take multiple arguments so #arguments should be used there. Can also use an inlined return tag for the javadocs.

Copy link
Author

Choose a reason for hiding this comment

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

also use an inlined return tag for the javadocs.

Your guidance was very helpful, thank you!
I've made changes as you said. Hope it is okay this time.

@NoyException NoyException force-pushed the removal branch 2 times, most recently from c163aa2 to 67abf42 Compare September 18, 2025 03:14
@NoyException
Copy link
Author

I've replaced that enum with the generated values, thank you all for your help.

*/
public void remove();

// Paper Start
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think these comments are required anymore.

Copy link
Author

Choose a reason for hiding this comment

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

idk, I just saw that it was written the same way in other places. Should I delete them?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. Only Minecraft code needs additional marking of changes made by paper.

Copy link
Author

Choose a reason for hiding this comment

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

Understood. I deleted them just now.

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.

5 participants