001 /**
002 * Jetrix TetriNET Server
003 * Copyright (C) 2004 Emmanuel Bourg
004 *
005 * This program is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU General Public License
007 * as published by the Free Software Foundation; either version 2
008 * of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program; if not, write to the Free Software
017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018 */
019
020 package net.jetrix.commands;
021
022 import java.util.Locale;
023
024 import net.jetrix.messages.channel.CommandMessage;
025 import net.jetrix.messages.channel.PlineMessage;
026 import net.jetrix.Language;
027 import net.jetrix.User;
028 import net.jetrix.Client;
029
030 /**
031 * Set the away status of a player.
032 *
033 * @author Emmanuel Bourg
034 * @version $Revision: 798 $, $Date: 2009-02-18 16:24:28 +0100 (Wed, 18 Feb 2009) $
035 * @since 0.2
036 */
037 public class AwayCommand extends AbstractCommand
038 {
039 public String[] getAliases()
040 {
041 return new String[] { "away", "afk" };
042 }
043
044 public String getUsage(Locale locale)
045 {
046 return "/afk <" + Language.getText("command.params.message", locale) + ">";
047 }
048
049 public void execute(CommandMessage message)
050 {
051 Client client = (Client) message.getSource();
052 User user = client.getUser();
053
054 PlineMessage response = new PlineMessage();
055
056 if (user.getStatus() == User.STATUS_AFK)
057 {
058 user.setStatus(User.STATUS_OK);
059 response.setKey("command.away.off");
060 }
061 else
062 {
063 user.setStatus(User.STATUS_AFK);
064 response.setKey("command.away.on");
065
066 if (message.getParameterCount() > 0)
067 {
068 user.setProperty("command.away.message", message.getText());
069 }
070 else
071 {
072 user.setProperty("command.away.message", null);
073 }
074 }
075
076 client.send(response);
077 }
078 }