mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 11:49:12 +00:00
Code cleanup
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1569 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
8ba3e3c2f9
commit
0ff89abeee
3 changed files with 29 additions and 24 deletions
|
@ -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);
|
||||
|
|
|
@ -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())
|
||||
try
|
||||
{
|
||||
return;
|
||||
startChat(address);
|
||||
final Chat chat = chats.get(address);
|
||||
if (chat != null)
|
||||
{
|
||||
chat.sendMessage(message.replaceAll("§[0-9a-f]", ""));
|
||||
}
|
||||
}
|
||||
startChat(address);
|
||||
chat = chats.get(address);
|
||||
if (chat == null)
|
||||
catch (XMPPException ex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
chat.sendMessage(message.replaceAll("§[0-9a-f]", ""));
|
||||
}
|
||||
catch (XMPPException ex)
|
||||
{
|
||||
if (chat != null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ depend: [Essentials]
|
|||
commands:
|
||||
setxmpp:
|
||||
description: set your xmpp address
|
||||
usage: /<command> address
|
||||
usage: /<command> <address>
|
||||
xmpp:
|
||||
description: send a message to a player
|
||||
usage: /<command> player message
|
||||
usage: /<command> <player> <message>
|
||||
xmppspy:
|
||||
description: toggle xmpp spy for all message
|
||||
usage: /<command> player
|
||||
description: toggle xmpp spy for all messages
|
||||
usage: /<command> <player>
|
Loading…
Reference in a new issue