1 /***
2 * Jetrix TetriNET Server
3 * Copyright (C) 2004 Emmanuel Bourg
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 package net.jetrix.commands;
21
22 import java.util.Locale;
23
24 import net.jetrix.messages.channel.CommandMessage;
25 import net.jetrix.messages.channel.PlineMessage;
26 import net.jetrix.Language;
27 import net.jetrix.User;
28 import net.jetrix.Client;
29
30 /***
31 * Set the away status of a player.
32 *
33 * @author Emmanuel Bourg
34 * @version $Revision: 798 $, $Date: 2009-02-18 16:24:28 +0100 (Wed, 18 Feb 2009) $
35 * @since 0.2
36 */
37 public class AwayCommand extends AbstractCommand
38 {
39 public String[] getAliases()
40 {
41 return new String[] { "away", "afk" };
42 }
43
44 public String getUsage(Locale locale)
45 {
46 return "/afk <" + Language.getText("command.params.message", locale) + ">";
47 }
48
49 public void execute(CommandMessage message)
50 {
51 Client client = (Client) message.getSource();
52 User user = client.getUser();
53
54 PlineMessage response = new PlineMessage();
55
56 if (user.getStatus() == User.STATUS_AFK)
57 {
58 user.setStatus(User.STATUS_OK);
59 response.setKey("command.away.off");
60 }
61 else
62 {
63 user.setStatus(User.STATUS_AFK);
64 response.setKey("command.away.on");
65
66 if (message.getParameterCount() > 0)
67 {
68 user.setProperty("command.away.message", message.getText());
69 }
70 else
71 {
72 user.setProperty("command.away.message", null);
73 }
74 }
75
76 client.send(response);
77 }
78 }