Open
Description
General Troubleshooting
- I am using the latest version of the LabyMod 4 Server API.
- I have checked for similar issues on the Issue-tracker.
- I have checked for Pull Requests that might already address this issue.
Feature Request
So that even inexperienced programmers can query the country of a player and then set the flag for it in a simplified manner.
Example Use-Case
public static String getCountryCode(String ip) {
String apiUrl = "http://ip-api.com/json/" + ip;
try {
URL url = new URL(apiUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
Map<String, Object> json = new Gson().fromJson(reader, Map.class);
reader.close();
return json.containsKey("countryCode") ? (String) json.get("countryCode") : "Unknown";
} catch (Exception e) {
e.printStackTrace();
return "Error";
}
}