Skip to content

Commit

Permalink
Java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Sep 26, 2023
1 parent eb4ccb2 commit 985df92
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
java-version: 17
- uses: actions/cache@v3
with:
path: |
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version = "1.0.0-SNAPSHOT"
group = "de.florianmichael"

repositories {
mavenCentral()
maven {
url "https://libraries.minecraft.net"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public void logIn() throws Exception {
if (this.username == null || this.username.isEmpty())
throw new InvalidCredentialsException("Invalid username.");

final boolean refreshAccessToken = this.accessToken != null && !this.accessToken.isEmpty();
final boolean newAuthentication = this.password != null && !this.password.isEmpty();
final var refreshAccessToken = this.accessToken != null && !this.accessToken.isEmpty();
final var newAuthentication = this.password != null && !this.password.isEmpty();

if (!refreshAccessToken && !newAuthentication)
throw new InvalidCredentialsException("Invalid password or access token.");
Expand All @@ -118,7 +118,8 @@ public void logIn() throws Exception {
response = client.post(this.baseURI.resolve(ROUTE_AUTHENTICATE).toURL(), new AuthenticationRequest(Agent.MINECRAFT, this.username, this.password, this.clientToken), AuthenticateRefreshResponse.class);
}

if (response == null) throw new InvalidRequestException("Server didn't sent a response.");
if (response == null)
throw new InvalidRequestException("Server didn't sent a response.");
if (!response.clientToken.equals(this.clientToken))
throw new InvalidRequestException("Server token and provided token doesn't match.");

Expand All @@ -142,7 +143,7 @@ public void logIn() throws Exception {
}

public boolean checkTokenValidity() {
final ValidateRequest request = new ValidateRequest(accessToken, clientToken);
final var request = new ValidateRequest(accessToken, clientToken);

try {
client.post(this.baseURI.resolve(ROUTE_VALIDATE).toURL(), request, Response.class);
Expand All @@ -158,8 +159,8 @@ public boolean checkTokenValidity() {
* @throws Exception If the server didn't send a response or the client token doesn't match.
*/
public void logOut() throws Exception {
final InvalidateRequest request = new InvalidateRequest(this.clientToken, this.accessToken);
final Response response = client.post(this.baseURI.resolve(ROUTE_INVALIDATE).toURL(), request, Response.class); // Mojang doesn't send this request, but it seems useful to invalidate the token.
final var request = new InvalidateRequest(this.clientToken, this.accessToken);
final var response = client.post(this.baseURI.resolve(ROUTE_INVALIDATE).toURL(), request, Response.class); // Mojang doesn't send this request, but it seems useful to invalidate the token.

if (!this.loggedIn) throw new IllegalStateException("Cannot log out while not logged in.");

Expand Down

0 comments on commit 985df92

Please sign in to comment.