summaryrefslogtreecommitdiffstats
path: root/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java
blob: 529b4a1c2d72b90588a4967018605523afaf80df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.earth2me.essentials.xmpp;

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.commands.EssentialsCommand;
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import org.bukkit.Server;
import org.bukkit.entity.Player;


public class Commandxmpp extends EssentialsCommand
{
	public Commandxmpp()
	{
		super("xmpp");
	}

	@Override
	protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException
	{
		if (args.length < 2)
		{
			throw new NotEnoughArgumentsException();
		}

		final String address = EssentialsXMPP.getInstance().getAddress(args[0]);
		if (address == null)
		{
			sender.sendMessage("§cThere are no players matching that name.");
		}
		else
		{
			final String message = getFinalArg(args, 1);
			final String senderName = sender.isPlayer() ? ess.getUser(sender.getPlayer()).getDisplayName() : Console.NAME;
			sender.sendMessage("[" + senderName + ">" + address + "] " + message);
			if (!EssentialsXMPP.getInstance().sendMessage(address, "[" + senderName + "] " + message))
			{
				sender.sendMessage("§cError sending message.");
			}
		}
	}
}