Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/main/java/ogcl/fun/PlayerIPadminAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void getPlayerLocationAsync(String ip, LocationInfoCallback callback) {
* @return 返回地理位置信息,如果失败则返回"未知"。
*/
private String getLocationInfo(String ip) {
String apiUrl = "https://www.ip.cn/api/index?ip=" + ip + "&type=1";
String apiUrl = "http://ip-api.com/json/" + ip + "?lang=zh-CN";
try {
URL url = new URL(apiUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Expand All @@ -64,11 +64,16 @@ private String getLocationInfo(String ip) {
}
in.close();
JsonObject jsonResponse = JsonParser.parseString(response.toString()).getAsJsonObject();
if (jsonResponse.get("code").getAsInt() == 0) {
return jsonResponse.get("address").getAsString();
if (jsonResponse.get("status").getAsString().equals("success")) {
String country = jsonResponse.get("country").getAsString();
String regionName = jsonResponse.get("regionName").getAsString();
String city = jsonResponse.get("city").getAsString();
return country + ", " + regionName + ", " + city;
} else {
plugin.getLogger().warning("[PlayerIPadmin] IP API 请求失败,错误信息: " + jsonResponse.get("message").getAsString());
}
} catch (Exception e) {
Bukkit.getLogger().warning("[PlayerIPadmin] Failed to fetch location for IP: " + ip + " - " + e.getMessage());
plugin.getLogger().warning("[PlayerIPadmin] Failed to fetch location for IP: " + ip + " - " + e.getMessage());
}
return "未知";
}
Expand Down