Skip to content

Conversation

@indyteo
Copy link
Contributor

@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
Contributor 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
@indyteo indyteo force-pushed the main/4 branch 2 times, most recently from 5a5e60d to 7d27812 Compare May 11, 2025 12:37
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