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

Add listing API for PlayerProfile #10392

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Flo0
Copy link
Contributor

@Flo0 Flo0 commented Apr 6, 2024

This enables listing, unlisting and updating any of [latyncy, gamemode, displayname] for PlayerProfiles in the tablist.

Burden of tracking those listings is on the caller.

Extends the ClientboundPlayerInfoUpdatePacket class and its nested Entry class for ease of use.

Test video

@Flo0 Flo0 requested a review from a team as a code owner April 6, 2024 21:20
Copy link
Contributor

@yannicklamprecht yannicklamprecht left a comment

Choose a reason for hiding this comment

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

Fixed imports patch should be squashed into into original patch.

@Flo0 Flo0 force-pushed the player-profile-listing-api branch 7 times, most recently from 308af9a to 7abad79 Compare April 6, 2024 23:35
@Flo0 Flo0 force-pushed the player-profile-listing-api branch from 7abad79 to 97a499f Compare April 6, 2024 23:58
Copy link
Contributor

@yannicklamprecht yannicklamprecht left a comment

Choose a reason for hiding this comment

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

nit: spaces between the packet factory methods like updateLatency and so on. Probably a non issue for the Paper team.

+ * @param gameMode The game mode of the profile.
+ * @param displayName The display name of the profile.
+ */
+ void listProfile(@NotNull com.destroystokyo.paper.profile.PlayerProfile profile, int latency, @NotNull GameMode gameMode, @Nullable net.kyori.adventure.text.Component displayName);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not satisfied with the name of this method. I think it should be send something like the other "packet-only" methods we have in the API. Something like sendPlayerTabListProfile or some combinations of those words.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes makes sense. Ill change those.

Comment on lines +37 to +39
+ default void listProfile(@NotNull com.destroystokyo.paper.profile.PlayerProfile profile) {
+ listProfile(profile, 0, GameMode.SURVIVAL, null);
+ }
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure having this method makes much sense here. These defaults are a little arbitrary. Like 0 ping? why survival? what if its a creative server? I'm not sure we need anything except the full method with all the options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those default values where taken from the internal EntryBuilder of the ClientboundPlayerInfoUpdatePacket.
Its honestly just a quol method. Would be nice to have a second opinion of this ^^

Copy link
Member

Choose a reason for hiding this comment

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

I don't think listed is a descriptive enough word to be used alone to describe this kind of API. Along with my msg about the listProfile method name, the various update names should be changed to be like sendTabListLatency, sendTabListDisplayName, etc.

Additionally, there is no method to remove a profile, only disable it's listed status. These things are separate and should be controlled separately. Send a fake Profile but also have a separate option for listing it or not. And have methods to change the listed nature of that profile, but also have a method for removing that profile.

All of the methods except the ones that sends the initial ClientboundPlayerInfoUpdatePacket do not require the full PlayerProfile, only the UUID, although we may not care and just require that you pass the full PlayerProfile instead, unsure on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, separating adding and listing makes sense.
I would argue against using UUIDs as it carries some ambiguity (and possible confusion) with it.

+
+ @Override
+ public void unlistProfile(@NotNull com.destroystokyo.paper.profile.PlayerProfile profile) {
+ Preconditions.checkNotNull(profile, "profile cannot be null");
Copy link
Member

Choose a reason for hiding this comment

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

We prefer using checkArgument(profile != null) because that will throw an IllegalArgumentException instead of an NullPointerException.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im also not a fan of this check. I was just copying this from another paper method.

@kashike kashike added the type: feature Request for a new Feature. label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Request for a new Feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants