Skip to content

feat(api): Make ComponentLike extends ComponentBuilderApplicable #1166

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

Open
wants to merge 1 commit into
base: main/4
Choose a base branch
from

Conversation

indyteo
Copy link

@indyteo indyteo commented Feb 24, 2025

This PR make the ComponentLike interface extends ComponentBuilderApplicable.

The main advantage of doing so is to allow using ComponentLikes in the LinearComponents#linear method. Imagine something in the lines of:

LinearComponent.linear(NamedTextColor.YELLOW, player, NamedTextColor.AQUA, text(" just obtained "), reward, text("!"));

With player and reward being instances of a class that declares itself ComponentLike. It would be very clear syntax! Actually, we need to add .asComponent() so it takes away unnecessarily a bit of readability, I think.

Overall, I feel this serves well the purpose of LinearComponents#linear being to reduce the verbosity of declaring a succession of components.

Side note about the FunctionalInterfaceMethodChanged warning, I suppressed it after discussing about it on Discord here.

Thanks!

Copy link
Member

@kezz kezz left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@kashike
Copy link
Member

kashike commented Feb 25, 2025

I'm unsure if it's best to do this, or adapt LinearComponents#linear to accept more types.

@kezz
Copy link
Member

kezz commented Feb 25, 2025

The only way we'd be able to do this (allow usage of ComponentLike in LinearComponents alongside style elements) is allowing an Object... accepting method which is ugly.

@indyteo
Copy link
Author

indyteo commented Feb 25, 2025

The only way we'd be able to do this (allow usage of ComponentLike in LinearComponents alongside style elements) is allowing an Object... accepting method which is ugly.

Technically, we could add another interface above to both ComponentLike and ComponentBuilderApplicable, and make the LinearComponents#linear function accepts this new super-interface instead. But I feel this is already kind of the purpose of ComponentBuilderApplicable, hence why I made it this way

@zml2008 zml2008 modified the milestones: 4.20.0, 4.21.0 Mar 7, 2025
@kezz kezz modified the milestones: 4.21.0, 4.22.0 Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants