From 0155bcedb7f00726d0b2f14e612a5342322a8278 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 14 Dec 2011 16:31:08 +0100 Subject: Updated all modules to new api, some settings are still missing --- .../earth2me/essentials/geoip/EssentialsGeoIP.java | 2 +- .../geoip/EssentialsGeoIPPlayerListener.java | 26 ++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'EssentialsGeoIP/src/com/earth2me/essentials') diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java index e0ca6cd7c..f9436d7f0 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.geoip; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.api.IEssentials; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.event.Event.Priority; diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index ee187c2aa..5a33fecc9 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -2,9 +2,9 @@ package com.earth2me.essentials.geoip; import com.earth2me.essentials.EssentialsConf; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IConf; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IReload; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import com.maxmind.geoip.Location; import com.maxmind.geoip.LookupService; import com.maxmind.geoip.regionName; @@ -21,7 +21,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerListener; -public class EssentialsGeoIPPlayerListener extends PlayerListener implements IConf +public class EssentialsGeoIPPlayerListener extends PlayerListener implements IReload { LookupService ls = null; private static final Logger logger = Logger.getLogger("Minecraft"); @@ -36,13 +36,13 @@ public class EssentialsGeoIPPlayerListener extends PlayerListener implements ICo this.dataFolder = dataFolder; this.config = new EssentialsConf(new File(dataFolder, "config.yml")); config.setTemplateName("/config.yml", EssentialsGeoIP.class); - reloadConfig(); + onReload(); } @Override public void onPlayerJoin(PlayerJoinEvent event) { - User u = ess.getUser(event.getPlayer()); + IUser u = ess.getUser(event.getPlayer()); if (u.isAuthorized("essentials.geoip.hide")) { return; @@ -73,13 +73,21 @@ public class EssentialsGeoIPPlayerListener extends PlayerListener implements ICo } if (config.getBoolean("show-on-whois", true)) { - u.setGeoLocation(sb.toString()); + u.acquireWriteLock(); + try + { + u.getData().setGeolocation(sb.toString()); + } + finally + { + u.unlock(); + } } if (config.getBoolean("show-on-login", true) && !u.isHidden()) { for (Player player : event.getPlayer().getServer().getOnlinePlayers()) { - User user = ess.getUser(player); + IUser user = ess.getUser(player); if (user.isAuthorized("essentials.geoip.show")) { user.sendMessage(_("geoipJoinFormat", u.getDisplayName(), sb.toString())); @@ -89,7 +97,7 @@ public class EssentialsGeoIPPlayerListener extends PlayerListener implements ICo } @Override - public final void reloadConfig() + public final void onReload() { config.load(); -- cgit v1.2.3 From 6af054631fe04ef7a607f24e459e37836c568100 Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 24 Jan 2012 00:01:31 +0100 Subject: More work on 3.0 branch --- .../earth2me/essentials/geoip/ConfigHolder.java | 27 +++ .../earth2me/essentials/geoip/EssentialsGeoIP.java | 3 +- .../geoip/EssentialsGeoIPPlayerListener.java | 227 ++++++++++++--------- 3 files changed, 162 insertions(+), 95 deletions(-) create mode 100644 EssentialsGeoIP/src/com/earth2me/essentials/geoip/ConfigHolder.java (limited to 'EssentialsGeoIP/src/com/earth2me/essentials') diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/ConfigHolder.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/ConfigHolder.java new file mode 100644 index 000000000..e2d82d644 --- /dev/null +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/ConfigHolder.java @@ -0,0 +1,27 @@ +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"); + } + +} diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java index f9436d7f0..783684ef8 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java @@ -36,8 +36,9 @@ public class EssentialsGeoIP extends JavaPlugin this.setEnabled(false); return; } - final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(getDataFolder(), ess); + final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(this, ess); pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this); + ess.addReloadListener(playerListener); logger.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team")); diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index 5a33fecc9..aa54dbf25 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -1,9 +1,8 @@ package com.earth2me.essentials.geoip; -import com.earth2me.essentials.EssentialsConf; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.api.IReload; import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IReload; import com.earth2me.essentials.api.IUser; import com.maxmind.geoip.Location; import com.maxmind.geoip.LookupService; @@ -19,165 +18,205 @@ import java.util.zip.GZIPInputStream; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerListener; +import org.bukkit.plugin.Plugin; public class EssentialsGeoIPPlayerListener extends PlayerListener implements IReload { - LookupService ls = null; - private static final Logger logger = Logger.getLogger("Minecraft"); - File databaseFile; - File dataFolder; - EssentialsConf config; + 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(File dataFolder, IEssentials ess) + public EssentialsGeoIPPlayerListener(final Plugin geoip, final IEssentials ess) { + super(); this.ess = ess; - this.dataFolder = dataFolder; - this.config = new EssentialsConf(new File(dataFolder, "config.yml")); - config.setTemplateName("/config.yml", EssentialsGeoIP.class); + this.geoip = geoip; + this.config = new ConfigHolder(ess, geoip); onReload(); } @Override - public void onPlayerJoin(PlayerJoinEvent event) + public void onPlayerJoin(final PlayerJoinEvent event) { - IUser u = ess.getUser(event.getPlayer()); + final IUser u = ess.getUser(event.getPlayer()); if (u.isAuthorized("essentials.geoip.hide")) { return; } - InetAddress address = event.getPlayer().getAddress().getAddress(); - StringBuilder sb = new StringBuilder(); - if (config.getBoolean("database.show-cities", false)) + config.acquireReadLock(); + try { - Location loc = ls.getLocation(address); - if (loc == null) - { - return; - } - if (loc.city != null) + final InetAddress address = event.getPlayer().getAddress().getAddress(); + final StringBuilder builder = new StringBuilder(); + if (config.getData().getDatabase().isShowCities()) { - sb.append(loc.city).append(", "); - } - String region = regionName.regionNameByCode(loc.countryCode, loc.region); - if (region != null) - { - sb.append(region).append(", "); + 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); } - sb.append(loc.countryName); - } - else - { - sb.append(ls.getCountry(address).getName()); - } - if (config.getBoolean("show-on-whois", true)) - { - u.acquireWriteLock(); - try + else { - u.getData().setGeolocation(sb.toString()); + builder.append(ls.getCountry(address).getName()); } - finally + if (config.getData().isShowOnWhois()) { - u.unlock(); + u.acquireWriteLock(); + try + { + u.getData().setGeolocation(builder.toString()); + } + finally + { + u.unlock(); + } } - } - if (config.getBoolean("show-on-login", true) && !u.isHidden()) - { - for (Player player : event.getPlayer().getServer().getOnlinePlayers()) + if (config.getData().isShowOnLogin() && !u.isHidden()) { - IUser user = ess.getUser(player); - if (user.isAuthorized("essentials.geoip.show")) + for (Player player : event.getPlayer().getServer().getOnlinePlayers()) { - user.sendMessage(_("geoipJoinFormat", u.getDisplayName(), sb.toString())); + final IUser user = ess.getUser(player); + if (user.isAuthorized("essentials.geoip.show")) + { + user.sendMessage(_("geoipJoinFormat", user.getDisplayName(), builder.toString())); + } } } } + finally + { + config.unlock(); + } } @Override public final void onReload() { - 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()) + config.onReload(); + config.acquireReadLock(); + try { - if (config.getBoolean("database.download-if-missing", true)) + if (config.getData().getDatabase().isShowCities()) { - downloadDatabase(); + databaseFile = new File(geoip.getDataFolder(), "GeoIPCity.dat"); } else { - logger.log(Level.SEVERE, _("cantFindGeoIpDB")); - return; + 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); } } - try - { - ls = new LookupService(databaseFile); - } - catch (IOException ex) + finally { - logger.log(Level.SEVERE, _("cantReadGeoIpDB"), ex); + config.unlock(); } } - private void downloadDatabase() + private void downloadDatabase(final String url) { + if (url == null || url.isEmpty()) + { + LOGGER.log(Level.SEVERE, _("geoIpUrlEmpty")); + return; + } + InputStream input = null; + OutputStream output = null; 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, _("geoIpUrlEmpty")); - return; - } - logger.log(Level.INFO, _("downloadingGeoIp")); - URL downloadUrl = new URL(url); - URLConnection conn = downloadUrl.openConnection(); + LOGGER.log(Level.INFO, _("downloadingGeoIp")); + final URL downloadUrl = new URL(url); + final URLConnection conn = downloadUrl.openConnection(); conn.setConnectTimeout(10000); conn.connect(); - InputStream input = conn.getInputStream(); + input = conn.getInputStream(); if (url.endsWith(".gz")) { input = new GZIPInputStream(input); } - OutputStream output = new FileOutputStream(databaseFile); - byte[] buffer = new byte[2048]; + 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); } - output.close(); input.close(); + output.close(); } catch (MalformedURLException ex) { - logger.log(Level.SEVERE, _("geoIpUrlInvalid"), ex); - return; + LOGGER.log(Level.SEVERE, _("geoIpUrlInvalid"), ex); } catch (IOException ex) { - logger.log(Level.SEVERE, _("connectionFailed"), 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); + } + } } } } -- cgit v1.2.3 From c689b55c4ddff6483799e021334e403db745562e Mon Sep 17 00:00:00 2001 From: KHobbits Date: Wed, 25 Jan 2012 23:53:31 +0000 Subject: Fix depends --- EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'EssentialsGeoIP/src/com/earth2me/essentials') diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java index 2fa8b0adf..b6697a658 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java @@ -22,7 +22,7 @@ public class EssentialsGeoIP extends JavaPlugin public void onEnable() { final PluginManager pm = getServer().getPluginManager(); - final IEssentials ess = (IEssentials)pm.getPlugin("Essentials"); + final IEssentials ess = (IEssentials)pm.getPlugin("Essentials3"); if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { getLogger().log(Level.WARNING, _("versionMismatchAll")); -- cgit v1.2.3 From 8ab5bad988f7ad9c8a1fafd504cf108f3ec84cc3 Mon Sep 17 00:00:00 2001 From: snowleo Date: Sun, 5 Feb 2012 17:19:32 +0100 Subject: Modified BetterLocation, and new Permission-System --- .../com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'EssentialsGeoIP/src/com/earth2me/essentials') diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index 19cc06dc4..45d21d89c 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -4,6 +4,7 @@ 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.perm.Permissions; import com.maxmind.geoip.Location; import com.maxmind.geoip.LookupService; import com.maxmind.geoip.regionName; @@ -45,7 +46,7 @@ public class EssentialsGeoIPPlayerListener implements Listener, IReload public void onPlayerJoin(final PlayerJoinEvent event) { final IUser u = ess.getUser(event.getPlayer()); - if (u.isAuthorized("essentials.geoip.hide")) + if (Permissions.GEOIP_HIDE.isAuthorized(u)) { return; } @@ -93,7 +94,7 @@ public class EssentialsGeoIPPlayerListener implements Listener, IReload for (Player player : event.getPlayer().getServer().getOnlinePlayers()) { final IUser user = ess.getUser(player); - if (user.isAuthorized("essentials.geoip.show")) + if (Permissions.GEOIP_SHOW.isAuthorized(user)) { user.sendMessage(_("geoipJoinFormat", user.getDisplayName(), builder.toString())); } -- cgit v1.2.3 From 1bfe63da96ca91a736da95a6a82fc2ef747e3228 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 14 Mar 2012 03:01:23 +0100 Subject: Splitting permissions and ranks (renamed from groups) Deleted all old permissions handlers, since we fully use superperms now --- .../com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'EssentialsGeoIP/src/com/earth2me/essentials') diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index 45d21d89c..158457155 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -4,7 +4,7 @@ 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.perm.Permissions; +import com.earth2me.essentials.permissions.Permissions; import com.maxmind.geoip.Location; import com.maxmind.geoip.LookupService; import com.maxmind.geoip.regionName; -- cgit v1.2.3