Fix Gson compatibility errors & clean comments

This commit is contained in:
2026-09-20 17:35:48 -05:00
parent 6196d75d2e
commit c512fc189a
4 changed files with 24 additions and 25 deletions
@@ -49,22 +49,20 @@ public class DataManager {
}
private String getApiUrl() {
String url = plugin.getConfig().getString("api-url", "https://api.eaglertiers.com/api");
if (url.endsWith("/")) {
url = url.substring(0, url.length() - 1);
}
return url;
return "https://api.eaglertiers.com/api";
}
private HttpURLConnection createConnection(String endpoint) throws Exception {
String urlStr = getApiUrl() + endpoint;
String key = plugin.getConfig().getString("api-key", "");
if (key != null && !key.trim().isEmpty()) {
if (urlStr.contains("?")) {
urlStr += "&key=" + key;
} else {
urlStr += "?key=" + key;
}
if (key == null || key.trim().isEmpty()) {
throw new IllegalArgumentException("API key is missing in config.yml! ETPlaceholders requires an API key to function.");
}
String urlStr = getApiUrl() + endpoint;
if (urlStr.contains("?")) {
urlStr += "&key=" + key;
} else {
urlStr += "?key=" + key;
}
URL url = new URL(urlStr);
@@ -73,10 +71,7 @@ public class DataManager {
conn.setRequestProperty("Accept", "application/json");
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
if (key != null && !key.trim().isEmpty()) {
conn.setRequestProperty("X-API-Key", key);
}
conn.setRequestProperty("X-API-Key", key);
return conn;
}
@@ -104,7 +99,7 @@ public class DataManager {
String tier = plugin.getConfig().getString("not-found-text", "Unranked");
if (pObj.has("tiers") && !pObj.get("tiers").isJsonNull()) {
JsonObject tiersObj = pObj.getAsJsonObject("tiers");
JsonObject tiersObj = pObj.get("tiers").getAsJsonObject();
if (tiersObj.has(mode) && !tiersObj.get(mode).isJsonNull()) {
tier = tiersObj.get(mode).getAsString();
}
@@ -116,6 +111,10 @@ public class DataManager {
}
}
}
} catch (IllegalArgumentException e) {
plugin.getLogger().warning(e.getMessage());
stopTasks();
break;
} catch (Exception e) {
plugin.getLogger().warning("Failed to fetch leaderboard for " + mode + ": " + e.getMessage());
}
@@ -134,7 +133,7 @@ public class DataManager {
Map<String, String> pTiers = new ConcurrentHashMap<>();
if (json.has("tiers") && !json.get("tiers").isJsonNull()) {
JsonObject tiersObj = json.getAsJsonObject("tiers");
JsonObject tiersObj = json.get("tiers").getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : tiersObj.entrySet()) {
if (!entry.getValue().isJsonNull()) {
pTiers.put(entry.getKey().toLowerCase(), entry.getValue().getAsString());
@@ -150,6 +149,8 @@ public class DataManager {
}
}
}
} catch (IllegalArgumentException e) {
plugin.getLogger().warning(e.getMessage());
} catch (Exception e) {
}
});