feat: add user-agent

This commit is contained in:
ineanto 2025-06-12 19:13:31 +02:00
parent 7fe5985391
commit 1a169f7709
Signed by: ineanto
GPG key ID: E511F9CAA2F9CE84
2 changed files with 8 additions and 7 deletions

View file

@ -72,7 +72,6 @@ public class FavoriteAddItem {
final List<Appearance> favorites = profile.getFavorites(); final List<Appearance> favorites = profile.getFavorites();
favorites.add(profile.getAppearance()); favorites.add(profile.getAppearance());
profile.setFavorites(favorites);
dataStore.updateCache(player.getUniqueId(), profile); dataStore.updateCache(player.getUniqueId(), profile);
new FavoritesGUI(player).open(); new FavoritesGUI(player).open();
return true; return true;

View file

@ -105,11 +105,13 @@ public class MojangAPI {
private JsonObject getRequestToUrl(String parametrizedUrl) throws ExecutionException, InterruptedException { private JsonObject getRequestToUrl(String parametrizedUrl) throws ExecutionException, InterruptedException {
return worker.submit(() -> { return worker.submit(() -> {
final URL url = URI.create(parametrizedUrl).toURL(); final URL url = URI.create(parametrizedUrl).toURL();
final HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
con.setDoInput(true);
con.setRequestMethod("GET");
switch (con.getResponseCode()) { connection.setDoInput(true);
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0");
connection.setRequestMethod("GET");
switch (connection.getResponseCode()) {
case 403: case 403:
logger.warning("Failed to parse request: forbidden?"); logger.warning("Failed to parse request: forbidden?");
return getErrorObject(); return getErrorObject();
@ -121,7 +123,7 @@ public class MojangAPI {
logger.warning("Failed to parse request: The connection is throttled."); logger.warning("Failed to parse request: The connection is throttled.");
return getErrorObject(); return getErrorObject();
case 200: case 200:
final BufferedReader input = new BufferedReader(new InputStreamReader(con.getInputStream())); final BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream()));
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
String line; String line;
while ((line = input.readLine()) != null) { while ((line = input.readLine()) != null) {
@ -136,7 +138,7 @@ public class MojangAPI {
return getErrorObject(); return getErrorObject();
} }
default: default:
logger.warning("Unhandled response code from Mojang: " + con.getResponseCode()); logger.warning("Unhandled response code from Mojang: " + connection.getResponseCode());
return getErrorObject(); return getErrorObject();
} }
}).get(); }).get();