KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freecs > commands > CmdInvite


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 java.util.Iterator JavaDoc;
23 import java.util.Vector JavaDoc;
24
25 import freecs.interfaces.ICommand;
26 import freecs.interfaces.IGroupState;
27 import freecs.interfaces.IUserStates;
28 import freecs.core.User;
29 import freecs.content.MessageState;
30
31
32 /**
33  * @author Manfred Andres
34  *
35  * freecs.commands
36  */

37 public class CmdInvite extends AbstractCommand {
38     public final String JavaDoc cmd= "/i";
39     private static final ICommand selve=new CmdInvite();
40
41     private CmdInvite () { }
42     
43     public static ICommand getInstance () {
44         return selve;
45     }
46     
47     public boolean execute (MessageState msgState, String JavaDoc param) {
48         if (isPunished (msgState)) return false;
49         msgState.targetGroup = msgState.sender.getGroup ();
50         if ((msgState.targetGroup.hasState(IGroupState.MODERATED)
51                 && !msgState.sender.hasRight (IUserStates.MAY_OPEN_MODERATED_GROUP))
52             || (!msgState.sender.hasRight (IUserStates.ROLE_VIP)
53                 && !msgState.sender.getGroup ().usrIsSu (msgState.sender))) {
54             if (!msgState.sender.getGroup ().usrIsSu (msgState.sender) && !msgState.sender.hasRight (IUserStates.ROLE_VIP)) {
55                 msgState.msgTemplate = "error.noRight.noSuVipAdmin";
56                 msgState.sender.sendMessage (msgState.mp);
57             } else {
58             msgState.msgTemplate = "error.i.noRight";
59             msgState.sender.sendMessage (msgState.mp);
60             }
61             return false;
62         }
63         if (param.length () < 1) {
64             msgState.msgTemplate = "error.i.noArg";
65             msgState.sender.sendMessage(msgState.mp);
66             return false;
67         }
68         if (param.indexOf (" ") > -1
69             && !msgState.sender.hasRight(IUserStates.ROLE_VIP)) {
70             msgState.msgTemplate="error.mass.noRight.noVipAdmin";
71             msgState.sender.sendMessage(msgState.mp);
72             return false;
73         }
74         Vector JavaDoc found = getMultibleUsers(msgState, param);
75         msgState.useRenderCache = false;
76         for (Iterator JavaDoc e = found.iterator(); e.hasNext(); ) {
77             User cu = (User) e.next();
78             msgState.msgTemplate = "message.i.personal";
79             if (!setInvited (msgState, cu)) {
80                 e.remove();
81                 continue;
82             }
83             msgState.usercontext = cu;
84         }
85         if (found.size()==0)
86             return false;
87         if (found.size()==1) {
88             msgState.msgTemplate="message.i.singular";
89         } else {
90             msgState.msgTemplate="message.i.plural";
91             msgState.usrList = found.toArray();
92         }
93         msgState.sender.sendMessage(msgState.mp);
94         return true;
95     }
96 }
97
Popular Tags