From e502a7e6fd12b9f6073ba592cc744f820c62c5db Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 8 Sep 2012 14:40:19 +0100 Subject: Give user chance to get display name set before displaying geoip. --- .../geoip/EssentialsGeoIPPlayerListener.java | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'EssentialsGeoIP/src') diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index ab72cfa9f..c8de953cf 100644 --- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -40,16 +40,28 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf config.setTemplateName("/config.yml", EssentialsGeoIP.class); reloadConfig(); } - + @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerJoin(PlayerJoinEvent event) + public void onPlayerJoin(final PlayerJoinEvent event) + { + ess.scheduleAsyncDelayedTask(new Runnable() + { + @Override + public void run() + { + delayedJoin(event.getPlayer()); + } + }); + } + + public void delayedJoin(Player player) { - User u = ess.getUser(event.getPlayer()); - if (u.isAuthorized("essentials.geoip.hide") || event.getPlayer().getAddress() == null) + User u = ess.getUser(player); + if (u.isAuthorized("essentials.geoip.hide") || player.getAddress() == null) { return; } - InetAddress address = event.getPlayer().getAddress().getAddress(); + InetAddress address = player.getAddress().getAddress(); StringBuilder sb = new StringBuilder(); if (config.getBoolean("database.show-cities", false)) { @@ -79,9 +91,9 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf } if (config.getBoolean("show-on-login", true) && !u.isHidden()) { - for (Player player : event.getPlayer().getServer().getOnlinePlayers()) + for (Player onlinePlayer : player.getServer().getOnlinePlayers()) { - User user = ess.getUser(player); + User user = ess.getUser(onlinePlayer); if (user.isAuthorized("essentials.geoip.show")) { user.sendMessage(_("geoipJoinFormat", u.getDisplayName(), sb.toString())); -- cgit v1.2.3