diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 36f9f945c..dfbaf43d4 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -141,6 +141,7 @@ gcmax=\u00a76Maximum memory\:\u00a7c {0} MB. gctotal=\u00a76Allocated memory\:\u00a7c {0} MB. gcWorld=\u00a76{0} "\u00a7c{1}\u00a76"\: \u00a7c{2}\u00a76 chunks, \u00a7c{3}\u00a76 entities, \u00a7c{4}\u00a76 tiles. geoipJoinFormat=\u00a76Player \u00a7c{0} \u00a76comes from \u00a7c{1}\u00a76. +geoipCantFind=\u00a76Player \u00a7c{0} \u00a76comes from \u00a7an unknown country\u00a76. geoIpUrlEmpty=GeoIP download url is empty. geoIpUrlInvalid=GeoIP download url is invalid. givenSkull=\u00a76You have been given the skull of \u00a7c{0}\u00a76. diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index 9e64aaf57..86175e6ad 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -15,10 +15,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import java.io.*; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; +import java.net.*; import java.util.logging.Level; import java.util.Date; import java.util.logging.Logger; @@ -58,6 +55,8 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf { } InetAddress address = player.getAddress().getAddress(); StringBuilder sb = new StringBuilder(); + + try { if (config.getBoolean("database.show-cities", false)) { CityResponse response = mmreader.city(address); @@ -82,6 +81,16 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf { sb.append(response.getCountry().getName()); } } catch (AddressNotFoundException ex) { + + if (checkIfLocal(address)) { + for (Player online : player.getServer().getOnlinePlayers()) { + User user = ess.getUser(online); + if (user.isAuthorized("essentials.geoip.show")) { + user.sendMessage(tl("geoipCantFind", u.getDisplayName())); + } + } + return; + } // GeoIP2 API forced this when address not found in their DB. jar will not complied without this. // TODO: Maybe, we can set a new custom msg about addr-not-found in messages.properties. logger.log(Level.INFO, tl("cantReadGeoIpDB") + " " + ex.getLocalizedMessage()); @@ -205,4 +214,17 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf { logger.log(Level.SEVERE, tl("connectionFailed"), ex); } } -} + + private boolean checkIfLocal(InetAddress address) { + if (address.isAnyLocalAddress() || address.isLoopbackAddress()) { + return true; + } + + // Double checks if address is defined on any interface + try { + return NetworkInterface.getByInetAddress(address) != null; + } catch (SocketException e) { + return false; + } + } +} \ No newline at end of file