KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freecs > commands > CmdJoinUser


1 /**
2  * Copyright (C) 2003 Manfred Andres
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  * Created on 28.09.2003
19  */

20
21 package freecs.commands;
22 import freecs.interfaces.ICommand;
23 import freecs.core.Group;
24 import freecs.core.User;
25 import freecs.content.MessageState;
26
27 /**
28  * @author Manfred Andres
29  *
30  * freecs.commands
31  */

32 public class CmdJoinUser extends AbstractCommand {
33     public final String JavaDoc cmd= "/ju";
34     private static final ICommand selve=new CmdJoinUser();
35
36     private CmdJoinUser () { }
37     
38     public static ICommand getInstance () {
39         return selve;
40     }
41     
42     public boolean execute (MessageState msgState, String JavaDoc param) {
43         User u;
44         if (param.length () < 1) {
45            msgState.msgTemplate="error.ju.noArg";
46            msgState.sender.sendMessage (msgState.mp);
47            return false;
48         } else if (param.indexOf (" ") > -1) {
49            u = getUser (msgState, param.substring(0, param.indexOf (" ")));
50         } else {
51            u = getUser (msgState, param);
52         }
53         if (u == null)
54             return false;
55         Group g = u.getGroup ();
56         if (g == null) return false;
57         if (g.equals (msgState.sender.getGroup ())) {
58             msgState.targetGroup = g;
59             msgState.usercontext = u;
60             msgState.msgTemplate="error.ju.alreadyHere";
61             msgState.sender.sendMessage (msgState.mp);
62             return false;
63         }
64         ICommand ic = CommandSet.getCommandSet().getCommand("/j");
65         return ic.execute (msgState, g.getRawName());
66     }
67 }
Popular Tags