mirror of
https://github.com/kaboomserver/extras.git
synced 2025-07-22 21:43:48 +00:00
Optimize skin URL connections
This commit is contained in:
parent
8ac5e83044
commit
6835013bef
3 changed files with 37 additions and 9 deletions
|
@ -45,9 +45,17 @@ class CommandUsername implements CommandExecutor {
|
|||
final String nameShort = nameColor.substring(0, Math.min(16, nameColor.length()));
|
||||
|
||||
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + nameShort);
|
||||
final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
||||
final HttpsURLConnection premiumCheck = (HttpsURLConnection) skinUrl.openConnection();
|
||||
premiumCheck.setConnectTimeout(0);
|
||||
premiumCheck.setRequestMethod("HEAD");
|
||||
premiumCheck.setDefaultUseCaches(false);
|
||||
premiumCheck.setUseCaches(false);
|
||||
|
||||
if (skinConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||
if (premiumCheck.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||
final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
||||
skinConnection.setConnectTimeout(0);
|
||||
skinConnection.setDefaultUseCaches(false);
|
||||
skinConnection.setUseCaches(false);
|
||||
final InputStreamReader skinStream = new InputStreamReader(skinConnection.getInputStream());
|
||||
final JsonObject response = new JsonParser().parse(skinStream).getAsJsonObject();
|
||||
final String uuid = response.get("uuid").getAsString();
|
||||
|
@ -55,9 +63,10 @@ class CommandUsername implements CommandExecutor {
|
|||
texture = rawSkin.get("value").getAsString();
|
||||
signature = rawSkin.get("signature").getAsString();
|
||||
skinStream.close();
|
||||
skinConnection.disconnect();
|
||||
}
|
||||
|
||||
skinConnection.disconnect();
|
||||
premiumCheck.disconnect();
|
||||
|
||||
final PlayerProfile profile = player.getPlayerProfile();
|
||||
profile.setName(nameShort);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue