Sueta

[API] GeoIP

2.0

An simple api to see the location of a player.

·Plugin

geolocation-300x207.png Geoip API
Please dont report issues in the review, and dont report issues if you are not sure its a problem of the api.

What does it?
With this api you can get the location of an ip/player, it uses GeoLite data created by MaxMind http://www.maxmind.com. The api will automatically download the database from the maxmind mirror!

LocalIP
Its not working with an localip like 127.0.0.1 this is because it cant get your external ip.

Its returns null?
If the api return null this is most of the times because your ip is not in the geoip database. Thats why you always need to check if the output is not null!

How to use?

//Get the ip from a player
InetAddress ip = player.getAddress().getAddress();

//Check if the ip is not null
if(ip == null){
   return;
}
 
//Check if the ip is not local   
if(ip.isAnyLocalAddress() || ip.isLoopbackAddress()){
   return;
}

//get the country, city & timezone of the user
GeoIP geo = new GeoIP(ip);
geo.countryName;
geo.city;
// etc

Plugin.yml
add this to your plugin.yml

depend: [GeoipAPI]

Links

Similar projects

Plugin →