Developers

Developers

Add the GeoIPTools.jar as a library to your plugin project. To get an instance of GeoIPLookup add the following method to your plugin:

private GeoIPLookup getGeoIPLookup() {
    Plugin pl = this.getServer().getPluginManager().getPlugin("GeoIPTools");
    if(pl != null) {
        return ((GeoIPTools) pl).getGeoIPLookup();
    } else {
        return null;
    }
}

and call it where ever you need it. When an error occurs while loading the database the method will return null and the error will be logged to console.

GeoIPLookup has 2 important public methods:

public Country getCountry(InetAddress inet)
public Location getLocation(InetAddress inet)

getCountry will get you a Country, from which you can call .getName() to acquire the country name.

getLocation returns a Location which contains all sorts of fun data stored as public variables.

Example code to get a user's city is below (this is all one line, it just goes onto the next)

Bukkit.broadcast(player.getName() + " is from " + geoiplookup.getCountry(player.getAddress().getAddress()).getName());