Skip to content

Commit 0a3c369

Browse files
committed
chore: update profile name lookup endpoint
1 parent 11cd95d commit 0a3c369

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

api/src/main/java/com/github/juliarn/npclib/api/profile/MojangProfileResolver.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import java.net.HttpURLConnection;
4242
import java.net.URL;
4343
import java.nio.charset.StandardCharsets;
44+
import java.util.Locale;
45+
import java.util.Objects;
4446
import java.util.Set;
4547
import java.util.UUID;
4648
import java.util.concurrent.CompletableFuture;
@@ -64,7 +66,7 @@ final class MojangProfileResolver implements ProfileResolver {
6466
private static final Pattern UUID_NO_DASH_PATTERN = Pattern.compile("-", Pattern.LITERAL);
6567
private static final Pattern UUID_DASHER_PATTERN = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})");
6668

67-
private static final String NAME_TO_UUID_ENDPOINT = "https://api.mojang.com/users/profiles/minecraft/%s";
69+
private static final String NAME_TO_UUID_ENDPOINT = "https://api.minecraftservices.com/minecraft/profile/lookup/name/%s";
6870
private static final String UUID_TO_PROFILE_ENDPOINT = "https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false";
6971

7072
private static @NotNull JsonObject makeRequest(@NotNull String endpoint) throws IOException {
@@ -136,7 +138,8 @@ final class MojangProfileResolver implements ProfileResolver {
136138
UUID uniqueId = profile.uniqueId();
137139
if (uniqueId == null) {
138140
// this will give us either a valid object or throw an exception
139-
JsonObject responseData = makeRequest(String.format(NAME_TO_UUID_ENDPOINT, profile.name()));
141+
String name = Objects.requireNonNull(profile.name(), "either profile name or uuid must be given");
142+
JsonObject responseData = makeRequest(String.format(NAME_TO_UUID_ENDPOINT, name.toLowerCase(Locale.ROOT)));
140143
String rawUniqueId = responseData.get("id").getAsString();
141144

142145
// insert dashes into the unique id string we get to parse it

0 commit comments

Comments
 (0)