From 595c5c4da26f82919a2a309c35484cc4eed8a20f Mon Sep 17 00:00:00 2001 From: patjense Date: Sun, 13 Oct 2013 12:59:04 -0700 Subject: add delayed task for XMPP presence update --- .../xmpp/EssentialsXMPPPlayerListener.java | 123 +++++++++++++-------- 1 file changed, 74 insertions(+), 49 deletions(-) (limited to 'EssentialsXMPP/src') diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java index c0913e6a9..d7e30f7dc 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java @@ -3,6 +3,9 @@ package com.earth2me.essentials.xmpp; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.ess3.api.IUser; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -10,64 +13,86 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.Server; class EssentialsXMPPPlayerListener implements Listener { - private final transient IEssentials ess; + private final transient IEssentials ess; - EssentialsXMPPPlayerListener(final IEssentials ess) - { - super(); - this.ess = ess; - } + EssentialsXMPPPlayerListener(final IEssentials ess) + { + super(); + this.ess = ess; + } - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerJoin(final PlayerJoinEvent event) - { - final User user = ess.getUser(event.getPlayer()); - sendMessageToSpyUsers("Player " + user.getDisplayName() + " joined the game"); - } + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerJoin(final PlayerJoinEvent event) + { + final User user = ess.getUser(event.getPlayer()); - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerChat(final AsyncPlayerChatEvent event) - { - final User user = ess.getUser(event.getPlayer()); - sendMessageToSpyUsers(String.format(event.getFormat(), user.getDisplayName(), event.getMessage())); - } + Bukkit.getScheduler().scheduleSyncDelayedTask(ess, new Runnable() + { + @Override + public void run() + { + EssentialsXMPP.updatePresence(); + } + }); - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerQuit(final PlayerQuitEvent event) - { - final User user = ess.getUser(event.getPlayer()); - sendMessageToSpyUsers("Player " + user.getDisplayName() + " left the game"); - } + sendMessageToSpyUsers("Player " + user.getDisplayName() + " joined the game"); + } - private void sendMessageToSpyUsers(final String message) - { - try - { - List users = EssentialsXMPP.getInstance().getSpyUsers(); - synchronized (users) - { - for (final String address : users) - { - Bukkit.getScheduler().scheduleSyncDelayedTask(ess, new Runnable() - { - @Override - public void run() - { - EssentialsXMPP.getInstance().sendMessage(address, message); - } + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerChat(final AsyncPlayerChatEvent event) + { + final User user = ess.getUser(event.getPlayer()); + sendMessageToSpyUsers(String.format(event.getFormat(), user.getDisplayName(), event.getMessage())); + } - }); + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerQuit(final PlayerQuitEvent event) + { + final User user = ess.getUser(event.getPlayer()); - } - } - } - catch (Exception ex) - { - // Ignore exceptions - } - } + Bukkit.getScheduler().scheduleSyncDelayedTask(ess, new Runnable() + { + @Override + public void run() + { + EssentialsXMPP.updatePresence(); + } + }); + + + sendMessageToSpyUsers("Player " + user.getDisplayName() + " left the game"); + } + + private void sendMessageToSpyUsers(final String message) + { + try + { + List users = EssentialsXMPP.getInstance().getSpyUsers(); + synchronized (users) + { + for (final String address : users) + { + Bukkit.getScheduler().scheduleSyncDelayedTask(ess, new Runnable() + { + @Override + public void run() + { + EssentialsXMPP.getInstance().sendMessage(address, message); + } + + }); + + } + } + } + catch (Exception ex) + { + // Ignore exceptions + } + } } -- cgit v1.2.3