forked from TuxCoding/FastLogin
Read the fully input from mcapi.ca instead of just one line
This commit is contained in:
@ -83,37 +83,37 @@ public abstract class MojangApiConnector {
|
|||||||
*/
|
*/
|
||||||
public UUID getPremiumUUID(String playerName) {
|
public UUID getPremiumUUID(String playerName) {
|
||||||
//check if it's a valid playername
|
//check if it's a valid playername
|
||||||
if (playernameMatcher.matcher(playerName).matches()) {
|
// if (playernameMatcher.matcher(playerName).matches()) {
|
||||||
//only make a API call if the name is valid existing mojang account
|
//only make a API call if the name is valid existing mojang account
|
||||||
|
|
||||||
if (requests.size() >= rateLimit || System.currentTimeMillis() - lastRateLimit < 1_000 * 60 * 10) {
|
// if (requests.size() >= rateLimit || System.currentTimeMillis() - lastRateLimit < 1_000 * 60 * 10) {
|
||||||
// plugin.getLogger().fine("STILL WAITING FOR RATE_LIMIT - TRYING Third-party API");
|
// plugin.getLogger().fine("STILL WAITING FOR RATE_LIMIT - TRYING Third-party API");
|
||||||
return getUUIDFromAPI(playerName);
|
return getUUIDFromAPI(playerName);
|
||||||
}
|
// }
|
||||||
|
|
||||||
requests.put(new Object(), new Object());
|
// requests.put(new Object(), new Object());
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
HttpsURLConnection connection = getConnection(UUID_LINK + playerName);
|
// HttpsURLConnection connection = getConnection(UUID_LINK + playerName);
|
||||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
// if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
// BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
String line = reader.readLine();
|
// String line = reader.readLine();
|
||||||
if (line != null && !line.equals("null")) {
|
// if (line != null && !line.equals("null")) {
|
||||||
return getUUIDFromJson(line);
|
// return getUUIDFromJson(line);
|
||||||
}
|
// }
|
||||||
} else if (connection.getResponseCode() == RATE_LIMIT_CODE) {
|
// } else if (connection.getResponseCode() == RATE_LIMIT_CODE) {
|
||||||
logger.info("RATE_LIMIT REACHED - TRYING THIRD-PARTY API");
|
// logger.info("RATE_LIMIT REACHED - TRYING THIRD-PARTY API");
|
||||||
lastRateLimit = System.currentTimeMillis();
|
// lastRateLimit = System.currentTimeMillis();
|
||||||
return getUUIDFromAPI(playerName);
|
// return getUUIDFromAPI(playerName);
|
||||||
}
|
// }
|
||||||
//204 - no content for not found
|
// //204 - no content for not found
|
||||||
} catch (Exception ex) {
|
// } catch (Exception ex) {
|
||||||
logger.log(Level.SEVERE, "Failed to check if player has a paid account", ex);
|
// logger.log(Level.SEVERE, "Failed to check if player has a paid account", ex);
|
||||||
}
|
// }
|
||||||
//this connection doesn't need to be closed. So can make use of keep alive in java
|
// //this connection doesn't need to be closed. So can make use of keep alive in java
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return null;
|
// return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUUIDFromAPI(String playerName) {
|
public UUID getUUIDFromAPI(String playerName) {
|
||||||
@ -128,10 +128,14 @@ public abstract class MojangApiConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
|
||||||
String line = reader.readLine();
|
StringBuilder inputBuilder = new StringBuilder();
|
||||||
if (line != null && !line.equals("null")) {
|
String line;
|
||||||
return getUUIDFromJson(line);
|
while ((line = reader.readLine()) != null) {
|
||||||
|
inputBuilder.append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String input = inputBuilder.toString();
|
||||||
|
return getUUIDFromJson(input);
|
||||||
} catch (IOException iOException) {
|
} catch (IOException iOException) {
|
||||||
logger.log(Level.SEVERE, "Tried converting name->uuid from third-party api", iOException);
|
logger.log(Level.SEVERE, "Tried converting name->uuid from third-party api", iOException);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user