From 16d0b5c228dd8d981a0d79944c70248ea813d63b Mon Sep 17 00:00:00 2001 From: ementalo Date: Wed, 27 Jun 2012 13:35:39 +0100 Subject: package name change to net.ess3 --- .../earth2me/essentials/geoip/ConfigHolder.java | 37 ---- .../earth2me/essentials/geoip/EssentialsGeoIP.java | 32 --- .../geoip/EssentialsGeoIPPlayerListener.java | 225 --------------------- .../src/net/ess3/geoip/ConfigHolder.java | 37 ++++ .../src/net/ess3/geoip/EssentialsGeoIP.java | 32 +++ .../ess3/geoip/EssentialsGeoIPPlayerListener.java | 225 +++++++++++++++++++++ EssentialsGeoIP/src/plugin.yml | 2 +- 7 files changed, 295 insertions(+), 295 deletions(-) delete mode 100644 EssentialsGeoIP/src/com/earth2me/essentials/geoip/ConfigHolder.java delete mode 100644 EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java delete mode 100644 EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java create mode 100644 EssentialsGeoIP/src/net/ess3/geoip/ConfigHolder.java create mode 100644 EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIP.java create mode 100644 EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIPPlayerListener.java (limited to 'EssentialsGeoIP/src') diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/ConfigHolder.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/ConfigHolder.java deleted file mode 100644 index 183c591ab..000000000 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/ConfigHolder.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.earth2me.essentials.geoip; - -import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.settings.geoip.GeoIP; -import com.earth2me.essentials.storage.AsyncStorageObjectHolder; -import java.io.File; -import java.io.IOException; -import org.bukkit.plugin.Plugin; - - -public class ConfigHolder extends AsyncStorageObjectHolder -{ - private final transient Plugin geoip; - - public ConfigHolder(final IEssentials ess, final Plugin geoip) - { - super(ess, GeoIP.class); - this.geoip = geoip; - onReload(); - } - - @Override - public File getStorageFile() throws IOException - { - return new File(geoip.getDataFolder(), "config.yml"); - } - - @Override - public void finishRead() - { - } - - @Override - public void finishWrite() - { - } -} 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 43b4959da..000000000 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.earth2me.essentials.geoip; - -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.api.IEssentials; -import java.util.logging.Level; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - - -public class EssentialsGeoIP extends JavaPlugin -{ - @Override - public void onEnable() - { - final PluginManager pm = getServer().getPluginManager(); - final IEssentials ess = (IEssentials)pm.getPlugin("Essentials3"); - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) - { - getLogger().log(Level.WARNING, _("versionMismatchAll")); - } - if (!ess.isEnabled()) - { - this.setEnabled(false); - return; - } - final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(this, ess); - pm.registerEvents(playerListener, this); - ess.addReloadListener(playerListener); - - 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 158457155..000000000 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ /dev/null @@ -1,225 +0,0 @@ -package com.earth2me.essentials.geoip; - -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.api.IReload; -import com.earth2me.essentials.api.IUser; -import com.earth2me.essentials.permissions.Permissions; -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; -import org.bukkit.plugin.Plugin; - - -public class EssentialsGeoIPPlayerListener implements Listener, IReload -{ - private transient LookupService ls = null; - private static final Logger LOGGER = Logger.getLogger("Minecraft"); - private transient File databaseFile; - private final transient ConfigHolder config; - private final transient IEssentials ess; - private final transient Plugin geoip; - - public EssentialsGeoIPPlayerListener(final Plugin geoip, final IEssentials ess) - { - super(); - this.ess = ess; - this.geoip = geoip; - this.config = new ConfigHolder(ess, geoip); - onReload(); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerJoin(final PlayerJoinEvent event) - { - final IUser u = ess.getUser(event.getPlayer()); - if (Permissions.GEOIP_HIDE.isAuthorized(u)) - { - return; - } - config.acquireReadLock(); - try - { - final InetAddress address = event.getPlayer().getAddress().getAddress(); - final StringBuilder builder = new StringBuilder(); - if (config.getData().getDatabase().isShowCities()) - { - final Location loc = ls.getLocation(address); - if (loc == null) - { - return; - } - if (loc.city != null) - { - builder.append(loc.city).append(", "); - } - final String region = regionName.regionNameByCode(loc.countryCode, loc.region); - if (region != null) - { - builder.append(region).append(", "); - } - builder.append(loc.countryName); - } - else - { - builder.append(ls.getCountry(address).getName()); - } - if (config.getData().isShowOnWhois()) - { - u.acquireWriteLock(); - try - { - u.getData().setGeolocation(builder.toString()); - } - finally - { - u.unlock(); - } - } - if (config.getData().isShowOnLogin() && !u.isHidden()) - { - for (Player player : event.getPlayer().getServer().getOnlinePlayers()) - { - final IUser user = ess.getUser(player); - if (Permissions.GEOIP_SHOW.isAuthorized(user)) - { - user.sendMessage(_("geoipJoinFormat", user.getDisplayName(), builder.toString())); - } - } - } - } - finally - { - config.unlock(); - } - } - - @Override - public final void onReload() - { - config.onReload(); - config.acquireReadLock(); - try - { - if (config.getData().getDatabase().isShowCities()) - { - databaseFile = new File(geoip.getDataFolder(), "GeoIPCity.dat"); - } - else - { - databaseFile = new File(geoip.getDataFolder(), "GeoIP.dat"); - } - if (!databaseFile.exists()) - { - if (config.getData().getDatabase().isDownloadIfMissing()) - { - if (config.getData().getDatabase().isShowCities()) - { - downloadDatabase(config.getData().getDatabase().getDownloadUrlCity()); - } - else - { - downloadDatabase(config.getData().getDatabase().getDownloadUrl()); - } - } - else - { - LOGGER.log(Level.SEVERE, _("cantFindGeoIpDB")); - return; - } - } - try - { - ls = new LookupService(databaseFile); - } - catch (IOException ex) - { - LOGGER.log(Level.SEVERE, _("cantReadGeoIpDB"), ex); - } - } - finally - { - config.unlock(); - } - } - - private void downloadDatabase(final String url) - { - if (url == null || url.isEmpty()) - { - LOGGER.log(Level.SEVERE, _("geoIpUrlEmpty")); - return; - } - InputStream input = null; - OutputStream output = null; - try - { - LOGGER.log(Level.INFO, _("downloadingGeoIp")); - final URL downloadUrl = new URL(url); - final URLConnection conn = downloadUrl.openConnection(); - conn.setConnectTimeout(10000); - conn.connect(); - input = conn.getInputStream(); - if (url.endsWith(".gz")) - { - input = new GZIPInputStream(input); - } - output = new FileOutputStream(databaseFile); - final byte[] buffer = new byte[2048]; - int length = input.read(buffer); - while (length >= 0) - { - output.write(buffer, 0, length); - length = input.read(buffer); - } - input.close(); - output.close(); - } - catch (MalformedURLException ex) - { - LOGGER.log(Level.SEVERE, _("geoIpUrlInvalid"), ex); - } - catch (IOException ex) - { - LOGGER.log(Level.SEVERE, _("connectionFailed"), ex); - } - finally - { - if (output != null) - { - try - { - output.close(); - } - catch (IOException ex) - { - LOGGER.log(Level.SEVERE, _("connectionFailed"), ex); - } - } - if (input != null) - { - try - { - input.close(); - } - catch (IOException ex) - { - LOGGER.log(Level.SEVERE, _("connectionFailed"), ex); - } - } - } - } -} diff --git a/EssentialsGeoIP/src/net/ess3/geoip/ConfigHolder.java b/EssentialsGeoIP/src/net/ess3/geoip/ConfigHolder.java new file mode 100644 index 000000000..068a1ba45 --- /dev/null +++ b/EssentialsGeoIP/src/net/ess3/geoip/ConfigHolder.java @@ -0,0 +1,37 @@ +package net.ess3.geoip; + +import net.ess3.api.IEssentials; +import net.ess3.settings.geoip.GeoIP; +import net.ess3.storage.AsyncStorageObjectHolder; +import java.io.File; +import java.io.IOException; +import org.bukkit.plugin.Plugin; + + +public class ConfigHolder extends AsyncStorageObjectHolder +{ + private final transient Plugin geoip; + + public ConfigHolder(final IEssentials ess, final Plugin geoip) + { + super(ess, GeoIP.class); + this.geoip = geoip; + onReload(); + } + + @Override + public File getStorageFile() throws IOException + { + return new File(geoip.getDataFolder(), "config.yml"); + } + + @Override + public void finishRead() + { + } + + @Override + public void finishWrite() + { + } +} diff --git a/EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIP.java b/EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIP.java new file mode 100644 index 000000000..9767f213b --- /dev/null +++ b/EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIP.java @@ -0,0 +1,32 @@ +package net.ess3.geoip; + +import static net.ess3.I18n._; +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 +{ + @Override + public void onEnable() + { + final PluginManager pm = getServer().getPluginManager(); + final IEssentials ess = (IEssentials)pm.getPlugin("Essentials-3"); + if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) + { + getLogger().log(Level.WARNING, _("versionMismatchAll")); + } + if (!ess.isEnabled()) + { + this.setEnabled(false); + return; + } + final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(this, ess); + pm.registerEvents(playerListener, this); + ess.addReloadListener(playerListener); + + getLogger().log(Level.INFO, "This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/."); + } +} diff --git a/EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIPPlayerListener.java new file mode 100644 index 000000000..a6bbeffec --- /dev/null +++ b/EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIPPlayerListener.java @@ -0,0 +1,225 @@ +package net.ess3.geoip; + +import static net.ess3.I18n._; +import net.ess3.api.IEssentials; +import net.ess3.api.IReload; +import net.ess3.api.IUser; +import net.ess3.permissions.Permissions; +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; +import org.bukkit.plugin.Plugin; + + +public class EssentialsGeoIPPlayerListener implements Listener, IReload +{ + private transient LookupService ls = null; + private static final Logger LOGGER = Logger.getLogger("Minecraft"); + private transient File databaseFile; + private final transient ConfigHolder config; + private final transient IEssentials ess; + private final transient Plugin geoip; + + public EssentialsGeoIPPlayerListener(final Plugin geoip, final IEssentials ess) + { + super(); + this.ess = ess; + this.geoip = geoip; + this.config = new ConfigHolder(ess, geoip); + onReload(); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerJoin(final PlayerJoinEvent event) + { + final IUser u = ess.getUser(event.getPlayer()); + if (Permissions.GEOIP_HIDE.isAuthorized(u)) + { + return; + } + config.acquireReadLock(); + try + { + final InetAddress address = event.getPlayer().getAddress().getAddress(); + final StringBuilder builder = new StringBuilder(); + if (config.getData().getDatabase().isShowCities()) + { + final Location loc = ls.getLocation(address); + if (loc == null) + { + return; + } + if (loc.city != null) + { + builder.append(loc.city).append(", "); + } + final String region = regionName.regionNameByCode(loc.countryCode, loc.region); + if (region != null) + { + builder.append(region).append(", "); + } + builder.append(loc.countryName); + } + else + { + builder.append(ls.getCountry(address).getName()); + } + if (config.getData().isShowOnWhois()) + { + u.acquireWriteLock(); + try + { + u.getData().setGeolocation(builder.toString()); + } + finally + { + u.unlock(); + } + } + if (config.getData().isShowOnLogin() && !u.isHidden()) + { + for (Player player : event.getPlayer().getServer().getOnlinePlayers()) + { + final IUser user = ess.getUser(player); + if (Permissions.GEOIP_SHOW.isAuthorized(user)) + { + user.sendMessage(_("geoipJoinFormat", user.getDisplayName(), builder.toString())); + } + } + } + } + finally + { + config.unlock(); + } + } + + @Override + public final void onReload() + { + config.onReload(); + config.acquireReadLock(); + try + { + if (config.getData().getDatabase().isShowCities()) + { + databaseFile = new File(geoip.getDataFolder(), "GeoIPCity.dat"); + } + else + { + databaseFile = new File(geoip.getDataFolder(), "GeoIP.dat"); + } + if (!databaseFile.exists()) + { + if (config.getData().getDatabase().isDownloadIfMissing()) + { + if (config.getData().getDatabase().isShowCities()) + { + downloadDatabase(config.getData().getDatabase().getDownloadUrlCity()); + } + else + { + downloadDatabase(config.getData().getDatabase().getDownloadUrl()); + } + } + else + { + LOGGER.log(Level.SEVERE, _("cantFindGeoIpDB")); + return; + } + } + try + { + ls = new LookupService(databaseFile); + } + catch (IOException ex) + { + LOGGER.log(Level.SEVERE, _("cantReadGeoIpDB"), ex); + } + } + finally + { + config.unlock(); + } + } + + private void downloadDatabase(final String url) + { + if (url == null || url.isEmpty()) + { + LOGGER.log(Level.SEVERE, _("geoIpUrlEmpty")); + return; + } + InputStream input = null; + OutputStream output = null; + try + { + LOGGER.log(Level.INFO, _("downloadingGeoIp")); + final URL downloadUrl = new URL(url); + final URLConnection conn = downloadUrl.openConnection(); + conn.setConnectTimeout(10000); + conn.connect(); + input = conn.getInputStream(); + if (url.endsWith(".gz")) + { + input = new GZIPInputStream(input); + } + output = new FileOutputStream(databaseFile); + final byte[] buffer = new byte[2048]; + int length = input.read(buffer); + while (length >= 0) + { + output.write(buffer, 0, length); + length = input.read(buffer); + } + input.close(); + output.close(); + } + catch (MalformedURLException ex) + { + LOGGER.log(Level.SEVERE, _("geoIpUrlInvalid"), ex); + } + catch (IOException ex) + { + LOGGER.log(Level.SEVERE, _("connectionFailed"), ex); + } + finally + { + if (output != null) + { + try + { + output.close(); + } + catch (IOException ex) + { + LOGGER.log(Level.SEVERE, _("connectionFailed"), ex); + } + } + if (input != null) + { + try + { + input.close(); + } + catch (IOException ex) + { + LOGGER.log(Level.SEVERE, _("connectionFailed"), ex); + } + } + } + } +} diff --git a/EssentialsGeoIP/src/plugin.yml b/EssentialsGeoIP/src/plugin.yml index bcc2aa313..709e6d92b 100644 --- a/EssentialsGeoIP/src/plugin.yml +++ b/EssentialsGeoIP/src/plugin.yml @@ -1,6 +1,6 @@ # This determines the command prefix when there are conflicts (/name:home, /name:help, etc.) name: EssentialsGeoIP -main: com.earth2me.essentials.geoip.EssentialsGeoIP +main: net.ess3.geoip.EssentialsGeoIP # Note to developers: This next line cannot change, or the automatic versioning system will break. version: ${build.number} website: http://tiny.cc/EssentialsWiki -- cgit v1.2.3