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

fix(annotations): prevent the OnlyIn annotation being used on EventBusSubscriber and Mod annotated classes #9891

Open
wants to merge 5 commits into
base: 1.20.x
Choose a base branch
from

Conversation

danorris709
Copy link

Adds checks to prevent the OnlyIn annotation being used in erroneous places such as classes annotated with the @Mod, or @EventBusSubscriber as outlined here

@autoforge autoforge bot added Triage This request requires the active attention of the Triage Team. Requires labelling or reviews. 1.20 labels Mar 21, 2024
@autoforge autoforge bot requested a review from a team March 21, 2024 15:58
@PaintNinja PaintNinja self-requested a review March 21, 2024 20:16
@LexManos
Copy link
Member

Is there a real need for this? Have you seen many mods do this?
The code looks fine, a little verbose, but good enough.
If Paint wants it, he can pull it.

if (!FMLEnvironment.production && hasOnlyInWithModAnnotation(classNode.visibleAnnotations))
{
LOGGER.error(DISTXFORM, "Attempted to load class {} with @Mod and @OnlyIn/@OnlyIns annotations", classNode.name);
throw new RuntimeException("Attempted to load class "+ classNode.name + " with @Mod and @OnlyIn/@OnlyIns annotations you should instead use the side setting in the mods.toml");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw new RuntimeException("Attempted to load class "+ classNode.name + " with @Mod and @OnlyIn/@OnlyIns annotations you should instead use the side setting in the mods.toml");
throw new RuntimeException("Found @OnlyIn on @Mod class "+ classNode.name + " - this is not allowed as it causes crashes. Remove the OnlyIn and consider setting clientSideOnly=true in the root of your mods.toml instead");

@PaintNinja
Copy link
Contributor

PaintNinja commented Mar 22, 2024

Is there a real need for this? Have you seen many mods do this?

I added it to the wishlist because I noticed some devs do this thinking it fixes crashing servers, when in reality it just gives a different error at best. It's not common, but the less mods using OnlyIn incorrectly, the better for everyone.

The code looks fine, a little verbose, but good enough. If Paint wants it, he can pull it.

Thanks, I'll merge once my requested changes are implemented. As for the verbosity, half of it seems to be a cleanup of the RuntimeDistCleaner to use less streams

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.20 Triage This request requires the active attention of the Triage Team. Requires labelling or reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants