forked from kaboomserver/extras
Optimize skin URL connections
This commit is contained in:
parent
8ac5e83044
commit
6835013bef
3 changed files with 37 additions and 9 deletions
|
@ -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) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue