Fix Gson compatibility errors & clean comments
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>dev.bailey</groupId>
|
<groupId>dev.bailey</groupId>
|
||||||
<artifactId>ETPlaceholders</artifactId>
|
<artifactId>ETPlaceholders</artifactId>
|
||||||
<version>1.0.1</version>
|
<version>1.0.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>ETPlaceholders</name>
|
<name>ETPlaceholders</name>
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>et_placeholders1.0.1</finalName>
|
<finalName>et_placeholders1.0.2</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
|||||||
@@ -49,22 +49,20 @@ public class DataManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getApiUrl() {
|
private String getApiUrl() {
|
||||||
String url = plugin.getConfig().getString("api-url", "https://api.eaglertiers.com/api");
|
return "https://api.eaglertiers.com/api";
|
||||||
if (url.endsWith("/")) {
|
|
||||||
url = url.substring(0, url.length() - 1);
|
|
||||||
}
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpURLConnection createConnection(String endpoint) throws Exception {
|
private HttpURLConnection createConnection(String endpoint) throws Exception {
|
||||||
String urlStr = getApiUrl() + endpoint;
|
|
||||||
String key = plugin.getConfig().getString("api-key", "");
|
String key = plugin.getConfig().getString("api-key", "");
|
||||||
if (key != null && !key.trim().isEmpty()) {
|
if (key == null || key.trim().isEmpty()) {
|
||||||
if (urlStr.contains("?")) {
|
throw new IllegalArgumentException("API key is missing in config.yml! ETPlaceholders requires an API key to function.");
|
||||||
urlStr += "&key=" + key;
|
}
|
||||||
} else {
|
|
||||||
urlStr += "?key=" + key;
|
String urlStr = getApiUrl() + endpoint;
|
||||||
}
|
if (urlStr.contains("?")) {
|
||||||
|
urlStr += "&key=" + key;
|
||||||
|
} else {
|
||||||
|
urlStr += "?key=" + key;
|
||||||
}
|
}
|
||||||
|
|
||||||
URL url = new URL(urlStr);
|
URL url = new URL(urlStr);
|
||||||
@@ -73,10 +71,7 @@ public class DataManager {
|
|||||||
conn.setRequestProperty("Accept", "application/json");
|
conn.setRequestProperty("Accept", "application/json");
|
||||||
conn.setConnectTimeout(5000);
|
conn.setConnectTimeout(5000);
|
||||||
conn.setReadTimeout(5000);
|
conn.setReadTimeout(5000);
|
||||||
|
conn.setRequestProperty("X-API-Key", key);
|
||||||
if (key != null && !key.trim().isEmpty()) {
|
|
||||||
conn.setRequestProperty("X-API-Key", key);
|
|
||||||
}
|
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
@@ -104,7 +99,7 @@ public class DataManager {
|
|||||||
|
|
||||||
String tier = plugin.getConfig().getString("not-found-text", "Unranked");
|
String tier = plugin.getConfig().getString("not-found-text", "Unranked");
|
||||||
if (pObj.has("tiers") && !pObj.get("tiers").isJsonNull()) {
|
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()) {
|
if (tiersObj.has(mode) && !tiersObj.get(mode).isJsonNull()) {
|
||||||
tier = tiersObj.get(mode).getAsString();
|
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) {
|
} catch (Exception e) {
|
||||||
plugin.getLogger().warning("Failed to fetch leaderboard for " + mode + ": " + e.getMessage());
|
plugin.getLogger().warning("Failed to fetch leaderboard for " + mode + ": " + e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -134,7 +133,7 @@ public class DataManager {
|
|||||||
Map<String, String> pTiers = new ConcurrentHashMap<>();
|
Map<String, String> pTiers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
if (json.has("tiers") && !json.get("tiers").isJsonNull()) {
|
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()) {
|
for (Map.Entry<String, JsonElement> entry : tiersObj.entrySet()) {
|
||||||
if (!entry.getValue().isJsonNull()) {
|
if (!entry.getValue().isJsonNull()) {
|
||||||
pTiers.put(entry.getKey().toLowerCase(), entry.getValue().getAsString());
|
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) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
# ET Placeholders Configuration
|
# ET Placeholders Configuration
|
||||||
# Available Gamemodes: overall, vanilla, mace, axe, sword, smp, diamondsmp, uhc, pot, nethop, cart
|
# Available Gamemodes: overall, vanilla, mace, axe, sword, smp, diamondsmp, uhc, pot, nethop, cart
|
||||||
|
|
||||||
# The base URL of the EaglerTiers API
|
|
||||||
api-url: "https://api.eaglertiers.com/api"
|
|
||||||
|
|
||||||
# Your API key. While public read requests don't require an API key, it is highly recommended to provide one to avoid rate limits.
|
# To get an api key, open a ticket on the discord https://discord.eaglertiers.com You need a key for this
|
||||||
api-key: ""
|
api-key: ""
|
||||||
|
|
||||||
# How often (in minutes) to refresh cached player and leaderboard data.
|
# How often (in minutes) to refresh cached player and leaderboard data.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: ETPlaceholders
|
name: ETPlaceholders
|
||||||
version: 1.0.1
|
version: 1.0.2
|
||||||
main: dev.bailey.etplaceholders.ETPlaceholdersPlugin
|
main: dev.bailey.etplaceholders.ETPlaceholdersPlugin
|
||||||
api-version: "1.13"
|
api-version: "1.13"
|
||||||
softdepend: [PlaceholderAPI]
|
softdepend: [PlaceholderAPI]
|
||||||
|
|||||||
Reference in New Issue
Block a user