summaryrefslogtreecommitdiffstats
path: root/EssentialsGeoIP/src/net
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2012-10-06 16:49:40 +0200
committersnowleo <schneeleo@gmail.com>2012-10-06 16:49:40 +0200
commitfabd88dc2585bf6798658f34a7ee122225316fe8 (patch)
treecdda3fad01567f042d5afbaa189ac12ef94f2b7e /EssentialsGeoIP/src/net
parent463c4ff62db553fc980545665a332ef7bbecdcc6 (diff)
downloadEssentials-fabd88dc2585bf6798658f34a7ee122225316fe8.tar
Essentials-fabd88dc2585bf6798658f34a7ee122225316fe8.tar.gz
Essentials-fabd88dc2585bf6798658f34a7ee122225316fe8.tar.lz
Essentials-fabd88dc2585bf6798658f34a7ee122225316fe8.tar.xz
Essentials-fabd88dc2585bf6798658f34a7ee122225316fe8.zip
Less locks please
Diffstat (limited to 'EssentialsGeoIP/src/net')
-rw-r--r--EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIPPlayerListener.java135
1 files changed, 57 insertions, 78 deletions
diff --git a/EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIPPlayerListener.java
index d2a30dbd8..5ccb5487a 100644
--- a/EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIPPlayerListener.java
+++ b/EssentialsGeoIP/src/net/ess3/geoip/EssentialsGeoIPPlayerListener.java
@@ -50,113 +50,91 @@ public class EssentialsGeoIPPlayerListener implements Listener, IReload
{
return;
}
- config.acquireReadLock();
- try
+ if (event.getPlayer().getAddress() == null || event.getPlayer().getAddress().getAddress() == null)
{
- if (event.getPlayer().getAddress() == null || event.getPlayer().getAddress().getAddress() == null) {
- return;
- }
- final InetAddress address = event.getPlayer().getAddress().getAddress();
-
- final StringBuilder builder = new StringBuilder();
- if (config.getData().getDatabase().isShowCities())
+ return;
+ }
+ 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)
{
- 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);
+ return;
}
- else
+ if (loc.city != null)
{
- builder.append(ls.getCountry(address).getName());
+ builder.append(loc.city).append(", ");
}
- if (config.getData().isShowOnWhois())
+ final String region = regionName.regionNameByCode(loc.countryCode, loc.region);
+ if (region != null)
{
- u.acquireWriteLock();
- try
- {
- u.getData().setGeolocation(builder.toString());
- }
- finally
- {
- u.unlock();
- }
+ builder.append(region).append(", ");
}
- if (config.getData().isShowOnLogin() && !u.isHidden())
+ builder.append(loc.countryName);
+ }
+ else
+ {
+ builder.append(ls.getCountry(address).getName());
+ }
+ if (config.getData().isShowOnWhois())
+ {
+ u.getData().setGeolocation(builder.toString());
+ u.queueSave();
+ }
+ if (config.getData().isShowOnLogin() && !u.isHidden())
+ {
+ for (Player player : event.getPlayer().getServer().getOnlinePlayers())
{
- for (Player player : event.getPlayer().getServer().getOnlinePlayers())
+ final IUser user = ess.getUserMap().getUser(player);
+ if (Permissions.GEOIP_SHOW.isAuthorized(user))
{
- final IUser user = ess.getUserMap().getUser(player);
- if (Permissions.GEOIP_SHOW.isAuthorized(user))
- {
- user.sendMessage(_("geoipJoinFormat", user.getPlayer().getDisplayName(), builder.toString()));
- }
+ user.sendMessage(_("geoipJoinFormat", user.getPlayer().getDisplayName(), builder.toString()));
}
}
}
- finally
- {
- config.unlock();
- }
}
@Override
public final void onReload()
{
config.onReload();
- config.acquireReadLock();
- try
+ if (config.getData().getDatabase().isShowCities())
{
- if (config.getData().getDatabase().isShowCities())
- {
- databaseFile = new File(geoip.getDataFolder(), "GeoIPCity.dat");
- }
- else
- {
- databaseFile = new File(geoip.getDataFolder(), "GeoIP.dat");
- }
- if (!databaseFile.exists())
+ 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().isDownloadIfMissing())
+ if (config.getData().getDatabase().isShowCities())
{
- if (config.getData().getDatabase().isShowCities())
- {
- downloadDatabase(config.getData().getDatabase().getDownloadUrlCity());
- }
- else
- {
- downloadDatabase(config.getData().getDatabase().getDownloadUrl());
- }
+ downloadDatabase(config.getData().getDatabase().getDownloadUrlCity());
}
else
{
- LOGGER.log(Level.SEVERE, _("cantFindGeoIpDB"));
- return;
+ downloadDatabase(config.getData().getDatabase().getDownloadUrl());
}
}
- try
- {
- ls = new LookupService(databaseFile);
- }
- catch (IOException ex)
+ else
{
- LOGGER.log(Level.SEVERE, _("cantReadGeoIpDB"), ex);
+ LOGGER.log(Level.SEVERE, _("cantFindGeoIpDB"));
+ return;
}
}
- finally
+ try
+ {
+ ls = new LookupService(databaseFile);
+ }
+ catch (IOException ex)
{
- config.unlock();
+ LOGGER.log(Level.SEVERE, _("cantReadGeoIpDB"), ex);
}
}
@@ -167,7 +145,8 @@ public class EssentialsGeoIPPlayerListener implements Listener, IReload
LOGGER.log(Level.SEVERE, _("geoIpUrlEmpty"));
return;
}
- if (!databaseFile.getAbsoluteFile().getParentFile().exists()) {
+ if (!databaseFile.getAbsoluteFile().getParentFile().exists())
+ {
databaseFile.getAbsoluteFile().getParentFile().mkdirs();
}
InputStream input = null;