Skip to content

Commit ceb1000

Browse files
Respect overridden sessionserver & api urls
1 parent 748b4ef commit ceb1000

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

src/main/java/pw/kaboom/extras/modules/player/skin/SkinManager.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ public final class SkinManager {
3737
private static final Gson GSON = new Gson();
3838
private static final ExecutorService executorService = Executors
3939
.newCachedThreadPool();
40+
private static final URI SESSION_HOST =
41+
URI.create(
42+
System.getProperty(
43+
"minecraft.api.session.host",
44+
"https://sessionserver.mojang.com"
45+
)
46+
);
47+
private static final URI PROFILE_ENDPOINT = URI.create(
48+
// 1.21.9+
49+
System.getProperty(
50+
"minecraft.api.profiles.host",
51+
System.getProperty(
52+
// 1.21.9-
53+
"minecraft.api.session.host",
54+
"https://api.mojang.com"
55+
)
56+
)
57+
);
4058

4159
public static void resetSkin(final Player player, final boolean shouldSendMessage) {
4260
executorService.submit(() -> {
@@ -128,8 +146,10 @@ public static CompletableFuture<SkinData> getSkinData(final String playerName) {
128146
public static CompletableFuture<SkinData> getSkinData(final UUID uuid) {
129147
return CompletableFuture.supplyAsync(() -> {
130148
final SkinResponse response = sendRequestForJSON(
131-
"https://sessionserver.mojang.com/session/minecraft/profile/"
132-
+ uuid + "?unsigned=false", SkinResponse.class);
149+
SESSION_HOST,
150+
"/session/minecraft/profile/" + uuid + "?unsigned=false",
151+
SkinResponse.class
152+
);
133153

134154
final List<ProfileProperty> properties = response.properties();
135155

@@ -145,10 +165,10 @@ public static CompletableFuture<SkinData> getSkinData(final UUID uuid) {
145165
}, executorService);
146166
}
147167

148-
private static <T> T sendRequestForJSON(String url, Class<T> clazz) {
168+
private static <T> T sendRequestForJSON(URI uri, String endpoint, Class<T> clazz) {
149169
final HttpRequest request = HttpRequest.newBuilder()
150170
.GET()
151-
.uri(URI.create(url))
171+
.uri(uri.resolve(endpoint))
152172
.build();
153173

154174
final HttpResponse<String> response;
@@ -164,9 +184,11 @@ private static <T> T sendRequestForJSON(String url, Class<T> clazz) {
164184

165185
private static CompletableFuture<UUID> getUUID(final String playerName) {
166186
return CompletableFuture.supplyAsync(() -> {
167-
final ProfileResponse parsedResponse = sendRequestForJSON
168-
("https://api.mojang.com/users/profiles/minecraft/" + playerName,
169-
ProfileResponse.class);
187+
final ProfileResponse parsedResponse = sendRequestForJSON(
188+
PROFILE_ENDPOINT,
189+
"/users/profiles/minecraft/" + playerName,
190+
ProfileResponse.class
191+
);
170192

171193
final String dashedUuid = parsedResponse
172194
.id()

0 commit comments

Comments
 (0)