Skip to content

#1448 Create AuthMePlayer to get player data from API with#2000

Merged
sgdc3 merged 4 commits intomasterfrom
1373-player-info-api
Feb 12, 2020
Merged

#1448 Create AuthMePlayer to get player data from API with#2000
sgdc3 merged 4 commits intomasterfrom
1373-player-info-api

Conversation

@ljacqu
Copy link
Copy Markdown
Member

@ljacqu ljacqu commented Jan 26, 2020

Introduces an API method to get a lot of player info with one load from the database. Unit tests will still follow but I open this PR early to get some feedback on the naming (and anything else). Ideally we won't have to remove or rename anything in the future since this is an API so it's really worth looking at our API methods carefully.

For the naming of AuthMePlayer: "ApiPlayer" would make sense for us in our codebase but not for anyone that is integrating our API. I also chose "Player" over "User" as I guess that's really the more used terminology in Minecraft (you have players on the server; it's players who register themselves in AuthMe).

cc: @RikoDEV @YellowZaki

@ljacqu ljacqu requested review from TuxCoding, hex3l and sgdc3 January 26, 2020 15:38
@ljacqu ljacqu changed the title #1448 Create AuthMePlayer to get player data from API with [WIP] #1448 Create AuthMePlayer to get player data from API with Jan 26, 2020
@ljacqu ljacqu changed the title [WIP] #1448 Create AuthMePlayer to get player data from API with #1448 Create AuthMePlayer to get player data from API with Jan 26, 2020
Copy link
Copy Markdown
Member

@sgdc3 sgdc3 left a comment

Choose a reason for hiding this comment

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

I think we should use optionals in our API

* @return AuthMe player info, or null if not available
*/
public String getRegistrationIp(String playerName) {
public AuthMePlayer getPlayerInfo(String playerName) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Api v4, deprecate api v3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Api v4, deprecate api v3

No.
This is just a method addition and shouldn't warrant a new API version. Unless you mean the removed method, but that's one that's two days old and wasn't part of any release (even beta).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fair, but i would like to change that in the future, with proper versioning, maybe by splitting the api into a separate maven module.

*
* @return player uuid, or null if not available
*/
UUID getUuid();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional

*
* @return player's email or null
*/
String getEmail();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional

/**
* @return the registration date of the player's account - never null
*/
Instant getRegistrationDate();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

One comment would have been enough :P

*
* @return the ip address used during the registration of the account, or null
*/
String getRegistrationIpAddress();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional

*
* @return date the player last logged in successfully, or null if not applicable
*/
Instant getLastLoginDate();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional

*
* @return ip address the player last logged in with successfully, or null if not applicable
*/
String getLastLoginIpAddress();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional

Copy link
Copy Markdown
Member

@TuxCoding TuxCoding left a comment

Choose a reason for hiding this comment

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

The Optional syntax would make the nullable values obvious, but it's a new concept that some might not understand. We could also use the @Nullable annotations. Personally I like Optionals more, because they provide great mapping functionality.

import java.util.UUID;

/**
* Read-only player info exposed in the AuthMe API.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With the current implementation, we should maybe also mention that this object is a copy that won't update after the API method is called. So it could be outdated later without any notification.

}

@Override
public String getLastLoginIpAddress() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason we don't use InetAddresses? I know they perform a DNS request, but only on DNS names not IP addresses.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Most cases I'm thinking of would compare the IP address with another string IP from elsewhere, or store it somewhere, no? I'm worried it will be a more annoying type than helpful as I'd anticipate a lot of uses having to unwrap it. But if you think otherwise I'm happy to change it.

(Also I'm lazy because constructing InetAddresses might throw UnknownHostException, which should never happen, but we'd still have to handle them properly 😆). It's not an excuse to not do it and as mentioned, I'm happy to do it if you really want.

Another alternative is offering both String and InetAddress but I think we should be careful with our interface(s), i.e. choose an approach and kind of stick with it. Say, if we added more fields to the AuthMePlayer it would quickly become confusing.

Copy link
Copy Markdown
Member

@TuxCoding TuxCoding Jan 27, 2020

Choose a reason for hiding this comment

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

Also I'm lazy because constructing InetAddresses might throw UnknownHostException,

Well if it's correct IP address we could ignore it. If not, it doesn't make sense to return this invalid string either.

Most cases I'm thinking of would compare the IP address with another string IP from elsewhere, or store it somewhere, no? I'm worried it will be a more annoying type than helpful as I'd anticipate a lot of uses having to unwrap it. But if you think otherwise I'm happy to change it.

Good point, then we should keep the String representation, because I think the methods of InetAddress are most likely not relevant over the mentioned String use cases (in comparison to objects like Instant).

@ljacqu
Copy link
Copy Markdown
Member Author

ljacqu commented Jan 27, 2020

Happy to use Optionals (can't reply to @games647 comment directly). Has the advantage that the user is forced to handle the "not present" state. Personally not a huge fan but for APIs it's definitely nice. Just note that it will not be in sync with the other existing methods.

@sgdc3 sgdc3 merged commit f7911ed into master Feb 12, 2020
@sgdc3 sgdc3 deleted the 1373-player-info-api branch February 12, 2020 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants