diff options
author | ementalo <me@ementalo.com> | 2015-04-11 21:47:56 +0100 |
---|---|---|
committer | ementalo <me@ementalo.com> | 2015-04-11 21:47:56 +0100 |
commit | 9e6c686c297eb233dfa19872f2f42bbd2a8f421f (patch) | |
tree | bc1dfa4e3ec7ca5ce8c459baaaebe4bd2b09ec5e /EssentialsGeoIP/src/com/earth2me/essentials/geoip | |
parent | ce8313bd688ecad3ed98decaf5ef9029fca8f100 (diff) | |
download | Essentials-9e6c686c297eb233dfa19872f2f42bbd2a8f421f.tar Essentials-9e6c686c297eb233dfa19872f2f42bbd2a8f421f.tar.gz Essentials-9e6c686c297eb233dfa19872f2f42bbd2a8f421f.tar.lz Essentials-9e6c686c297eb233dfa19872f2f42bbd2a8f421f.tar.xz Essentials-9e6c686c297eb233dfa19872f2f42bbd2a8f421f.zip |
Change namespace from com.earth2me to org.mcess - net.ess3.api changes still required
Diffstat (limited to 'EssentialsGeoIP/src/com/earth2me/essentials/geoip')
-rw-r--r-- | EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java | 40 | ||||
-rw-r--r-- | EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java | 189 |
2 files changed, 0 insertions, 229 deletions
diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java deleted file mode 100644 index aced4ccb8..000000000 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.earth2me.essentials.geoip; - -import static com.earth2me.essentials.I18n.tl; -import net.ess3.api.IEssentials; -import java.util.logging.Level; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - - -public class EssentialsGeoIP extends JavaPlugin -{ - public EssentialsGeoIP() - { - } - - @Override - public void onDisable() - { - } - - @Override - public void onEnable() - { - final PluginManager pm = getServer().getPluginManager(); - final IEssentials ess = (IEssentials)pm.getPlugin("Essentials"); - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) - { - getLogger().log(Level.WARNING, tl("versionMismatchAll")); - } - if (!ess.isEnabled()) { - this.setEnabled(false); - return; - } - final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(getDataFolder(), ess); - pm.registerEvents(playerListener, this); - - - getLogger().log(Level.INFO, "This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/."); - } -} diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java deleted file mode 100644 index a6cb28ddc..000000000 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ /dev/null @@ -1,189 +0,0 @@ -package com.earth2me.essentials.geoip; - -import com.earth2me.essentials.EssentialsConf; -import static com.earth2me.essentials.I18n.tl; -import com.earth2me.essentials.IConf; -import com.earth2me.essentials.User; -import net.ess3.api.IEssentials; -import com.maxmind.geoip.Location; -import com.maxmind.geoip.LookupService; -import com.maxmind.geoip.regionName; -import java.io.*; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.zip.GZIPInputStream; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - - -public class EssentialsGeoIPPlayerListener implements Listener, IConf -{ - LookupService ls = null; - private static final Logger logger = Logger.getLogger("Minecraft"); - File databaseFile; - File dataFolder; - final EssentialsConf config; - private final transient IEssentials ess; - - public EssentialsGeoIPPlayerListener(File dataFolder, IEssentials ess) - { - this.ess = ess; - this.dataFolder = dataFolder; - this.config = new EssentialsConf(new File(dataFolder, "config.yml")); - config.setTemplateName("/config.yml", EssentialsGeoIP.class); - reloadConfig(); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerJoin(final PlayerJoinEvent event) - { - ess.runTaskAsynchronously(new Runnable() - { - @Override - public void run() - { - delayedJoin(event.getPlayer()); - } - }); - } - - public void delayedJoin(Player player) - { - User u = ess.getUser(player); - if (u.isAuthorized("essentials.geoip.hide") || player.getAddress() == null) - { - return; - } - InetAddress address = player.getAddress().getAddress(); - StringBuilder sb = new StringBuilder(); - if (config.getBoolean("database.show-cities", false)) - { - Location loc = ls.getLocation(address); - if (loc == null) - { - return; - } - if (loc.city != null) - { - sb.append(loc.city).append(", "); - } - String region = regionName.regionNameByCode(loc.countryCode, loc.region); - if (region != null) - { - sb.append(region).append(", "); - } - sb.append(loc.countryName); - } - else - { - sb.append(ls.getCountry(address).getName()); - } - if (config.getBoolean("show-on-whois", true)) - { - u.setGeoLocation(sb.toString()); - } - if (config.getBoolean("show-on-login", true) && !u.isHidden()) - { - for (Player onlinePlayer : player.getServer().getOnlinePlayers()) - { - User user = ess.getUser(onlinePlayer); - if (user.isAuthorized("essentials.geoip.show")) - { - user.sendMessage(tl("geoipJoinFormat", u.getDisplayName(), sb.toString())); - } - } - } - } - - @Override - public final void reloadConfig() - { - config.load(); - - if (config.getBoolean("database.show-cities", false)) - { - databaseFile = new File(dataFolder, "GeoIPCity.dat"); - } - else - { - databaseFile = new File(dataFolder, "GeoIP.dat"); - } - if (!databaseFile.exists()) - { - if (config.getBoolean("database.download-if-missing", true)) - { - downloadDatabase(); - } - else - { - logger.log(Level.SEVERE, tl("cantFindGeoIpDB")); - return; - } - } - try - { - ls = new LookupService(databaseFile); - } - catch (IOException ex) - { - logger.log(Level.SEVERE, tl("cantReadGeoIpDB"), ex); - } - } - - private void downloadDatabase() - { - try - { - String url; - if (config.getBoolean("database.show-cities", false)) - { - url = config.getString("database.download-url-city"); - } - else - { - url = config.getString("database.download-url"); - } - if (url == null || url.isEmpty()) - { - logger.log(Level.SEVERE, tl("geoIpUrlEmpty")); - return; - } - logger.log(Level.INFO, tl("downloadingGeoIp")); - URL downloadUrl = new URL(url); - URLConnection conn = downloadUrl.openConnection(); - conn.setConnectTimeout(10000); - conn.connect(); - InputStream input = conn.getInputStream(); - if (url.endsWith(".gz")) - { - input = new GZIPInputStream(input); - } - OutputStream output = new FileOutputStream(databaseFile); - byte[] buffer = new byte[2048]; - int length = input.read(buffer); - while (length >= 0) - { - output.write(buffer, 0, length); - length = input.read(buffer); - } - output.close(); - input.close(); - } - catch (MalformedURLException ex) - { - logger.log(Level.SEVERE, tl("geoIpUrlInvalid"), ex); - return; - } - catch (IOException ex) - { - logger.log(Level.SEVERE, tl("connectionFailed"), ex); - } - } -} |