    001package net.minecraft.command;
    002
    003import java.util.Arrays;
    004import java.util.List;
    005import net.minecraft.entity.player.EntityPlayer;
    006import net.minecraft.entity.player.EntityPlayerMP;
    007import net.minecraft.server.MinecraftServer;
    008import net.minecraft.util.EnumChatFormatting;
    009
    010public class CommandServerMessage extends CommandBase
    011{
    012    public List getCommandAliases()
    013    {
    014        return Arrays.asList(new String[] {"w", "msg"});
    015    }
    016
    017    public String getCommandName()
    018    {
    019        return "tell";
    020    }
    021
    022    /**
    023     * Return the required permission level for this command.
    024     */
    025    public int getRequiredPermissionLevel()
    026    {
    027        return 0;
    028    }
    029
    030    public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    031    {
    032        if (par2ArrayOfStr.length < 2)
    033        {
    034            throw new WrongUsageException("commands.message.usage", new Object[0]);
    035        }
    036        else
    037        {
    038            EntityPlayerMP entityplayermp = func_82359_c(par1ICommandSender, par2ArrayOfStr[0]);
    039
    040            if (entityplayermp == null)
    041            {
    042                throw new PlayerNotFoundException();
    043            }
    044            else if (entityplayermp == par1ICommandSender)
    045            {
    046                throw new PlayerNotFoundException("commands.message.sameTarget", new Object[0]);
    047            }
    048            else
    049            {
    050                String s = func_82361_a(par1ICommandSender, par2ArrayOfStr, 1, !(par1ICommandSender instanceof EntityPlayer));
    051                entityplayermp.sendChatToPlayer(EnumChatFormatting.GRAY + "" + EnumChatFormatting.ITALIC + entityplayermp.translateString("commands.message.display.incoming", new Object[] {par1ICommandSender.getCommandSenderName(), s}));
    052                par1ICommandSender.sendChatToPlayer(EnumChatFormatting.GRAY + "" + EnumChatFormatting.ITALIC + par1ICommandSender.translateString("commands.message.display.outgoing", new Object[] {entityplayermp.getCommandSenderName(), s}));
    053            }
    054        }
    055    }
    056
    057    /**
    058     * Adds the strings available in this command to the given list of tab completion options.
    059     */
    060    public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    061    {
    062        return getListOfStringsMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getAllUsernames());
    063    }
    064
    065    /**
    066     * Return whether the specified command parameter index is a username parameter.
    067     */
    068    public boolean isUsernameIndex(String[] par1ArrayOfStr, int par2)
    069    {
    070        return par2 == 0;
    071    }
    072}