diff options
author | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-06-02 13:49:58 +0000 |
---|---|---|
committer | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-06-02 13:49:58 +0000 |
commit | 0ff89abeeef7d35f036144a0463f7ee87dcfe16e (patch) | |
tree | dfa0330b22e0b7d3b44fa73271cd5f9bff72ab83 /EssentialsXMPP/src/com/earth2me/essentials | |
parent | 8ba3e3c2f964d6300f355cd9567eed59d883e31d (diff) | |
download | Essentials-0ff89abeeef7d35f036144a0463f7ee87dcfe16e.tar Essentials-0ff89abeeef7d35f036144a0463f7ee87dcfe16e.tar.gz Essentials-0ff89abeeef7d35f036144a0463f7ee87dcfe16e.tar.lz Essentials-0ff89abeeef7d35f036144a0463f7ee87dcfe16e.tar.xz Essentials-0ff89abeeef7d35f036144a0463f7ee87dcfe16e.zip |
Code cleanup
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1569 e251c2fe-e539-e718-e476-b85c1f46cddb
Diffstat (limited to 'EssentialsXMPP/src/com/earth2me/essentials')
-rw-r--r-- | EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java | 2 | ||||
-rw-r--r-- | EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java | 43 |
2 files changed, 25 insertions, 20 deletions
diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java index 49aa2a6ea..d78782f12 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java @@ -23,7 +23,6 @@ public class Commandxmpp extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final String message = getFinalArg(args, 1); final String address = EssentialsXMPP.getInstance().getAddress(args[0]); if (address == null) { @@ -31,6 +30,7 @@ public class Commandxmpp extends EssentialsCommand } else { + final String message = getFinalArg(args, 1); final String senderName = sender instanceof Player ? ess.getUser(sender).getDisplayName() : Console.NAME; sender.sendMessage("[" + senderName + ">" + address + "] " + message); EssentialsXMPP.getInstance().sendMessage(address, "[" + senderName + "] " + message); diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java index e9da61440..c92365c44 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java @@ -51,28 +51,20 @@ public class XMPPManager extends Handler implements MessageListener, ChatManager public void sendMessage(final String address, final String message) { - Chat chat = null; - try + if (address != null && !address.isEmpty()) { - if (address == null || address.isEmpty()) - { - return; - } - startChat(address); - chat = chats.get(address); - if (chat == null) + try { - return; + startChat(address); + final Chat chat = chats.get(address); + if (chat != null) + { + chat.sendMessage(message.replaceAll("§[0-9a-f]", "")); + } } - chat.sendMessage(message.replaceAll("§[0-9a-f]", "")); - } - catch (XMPPException ex) - { - if (chat != null) + catch (XMPPException ex) { - chat.removeMessageListener(this); - chats.remove(address); - LOGGER.log(Level.WARNING, "Failed to send xmpp message.", ex); + disableChat(address, ex); } } } @@ -260,7 +252,9 @@ public class XMPPManager extends Handler implements MessageListener, ChatManager { LOGGER.log(Level.WARNING, "Failed to send xmpp message.", ex); } - } else { + } + else + { for (Player p : matches) { p.sendMessage("[" + chat.getParticipant() + ">" + p.getDisplayName() + "] " + message); @@ -280,4 +274,15 @@ public class XMPPManager extends Handler implements MessageListener, ChatManager } } } + + private void disableChat(final String address, final XMPPException exception) + { + final Chat chat = chats.get(address); + if (chat != null) + { + chat.removeMessageListener(this); + chats.remove(address); + LOGGER.log(Level.WARNING, "Failed to send xmpp message.", exception); + } + } } |