/** * Sends a private chat message over the network, to the specified user. * * @param privmsg The private message to send. * @param user The user to send the private message to. * @throws CommandException If there is no connection to the network, or the application user is * away, or the private message is empty, or the private message is too long, or the specified * user has no port to send the private message to, or the specified user is away or offline. */ public void sendPrivateMessage(final String privmsg, final User user) throws CommandException { if (!isConnected()) { throw new CommandException("You can not send a private chat message without being connected"); } else if (me.isAway()) { throw new CommandException("You can not send a private chat message while away"); } else if (privmsg.trim().length() == 0) { throw new CommandException("You can not send an empty private chat message"); } else if (Tools.getBytes(privmsg) > Constants.MESSAGE_MAX_BYTES) { throw new CommandException( "You can not send a private chat message with more than " + Constants.MESSAGE_MAX_BYTES + " bytes"); } else if (user.getPrivateChatPort() == 0) { throw new CommandException( "You can not send a private chat message to a user with no available port number"); } else if (user.isAway()) { throw new CommandException("You can not send a private chat message to a user that is away"); } else if (!user.isOnline()) { throw new CommandException( "You can not send a private chat message to a user that is offline"); } else if (settings.isNoPrivateChat()) { throw new CommandException( "You can not send a private chat message when private chat is disabled"); } else { messages.sendPrivateMessage(privmsg, user); } }