diff --git a/src/main/java/pw/kaboom/extras/commands/CommandSkin.java b/src/main/java/pw/kaboom/extras/commands/CommandSkin.java index 8333062..b7ffa3d 100644 --- a/src/main/java/pw/kaboom/extras/commands/CommandSkin.java +++ b/src/main/java/pw/kaboom/extras/commands/CommandSkin.java @@ -38,9 +38,17 @@ class CommandSkin implements CommandExecutor { public void run() { try { final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + name); - 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(); @@ -48,6 +56,7 @@ class CommandSkin implements CommandExecutor { final String texture = rawSkin.get("value").getAsString(); final String signature = rawSkin.get("signature").getAsString(); skinStream.close(); + skinConnection.disconnect(); final PlayerProfile textureProfile = player.getPlayerProfile(); textureProfile.clearProperties(); @@ -63,7 +72,7 @@ class CommandSkin implements CommandExecutor { player.sendMessage("A player with that username doesn't exist"); } - skinConnection.disconnect(); + premiumCheck.disconnect(); } catch (Exception exception) { } } diff --git a/src/main/java/pw/kaboom/extras/commands/CommandUsername.java b/src/main/java/pw/kaboom/extras/commands/CommandUsername.java index 3de2806..b40f789 100644 --- a/src/main/java/pw/kaboom/extras/commands/CommandUsername.java +++ b/src/main/java/pw/kaboom/extras/commands/CommandUsername.java @@ -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); diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java index 7276167..1e099a0 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java @@ -42,9 +42,18 @@ class PlayerConnection implements Listener { void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) { try { final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + event.getName()); - final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection(); + final HttpsURLConnection premiumCheck = (HttpsURLConnection) skinUrl.openConnection(); + premiumCheck.setConnectTimeout(0); + premiumCheck.setRequestMethod("HEAD"); + premiumCheck.setDefaultUseCaches(false); + premiumCheck.setUseCaches(false); + System.out.println(premiumCheck.getResponseCode()); - 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(); @@ -52,6 +61,7 @@ class PlayerConnection implements Listener { final String texture = rawSkin.get("value").getAsString(); final String signature = rawSkin.get("signature").getAsString(); skinStream.close(); + skinConnection.disconnect(); final PlayerProfile textureProfile = event.getPlayerProfile(); textureProfile.clearProperties(); @@ -60,7 +70,7 @@ class PlayerConnection implements Listener { main.playerProfile.put(event.getName(), textureProfile); } - skinConnection.disconnect(); + premiumCheck.disconnect(); } catch (Exception exception) { }