KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freecs > commands > CmdListVips


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

37 public class CmdListVips extends AbstractCommand {
38     public final String JavaDoc cmd= "/vip";
39     private static final ICommand selve=new CmdListVips();
40
41     private CmdListVips () { }
42     
43     public static ICommand getInstance () {
44         return selve;
45     }
46     
47     public boolean execute (MessageState msgState, String JavaDoc param) {
48         if (param.length () > 0) {
49             if (!msgState.sender.hasRight(IUserStates.ROLE_VIP)) {
50                 msgState.msgTemplate = "error.noRight.noVipAdmin";
51                 msgState.sender.sendMessage (msgState.mp);
52                 return false;
53             }
54             msgState.msgTemplate = "message.m.vip";
55             msgState.message = param;
56             for (Enumeration JavaDoc e = UserManager.mgr.onlineVips(); e.hasMoreElements (); ) {
57                 User u = (User) e.nextElement ();
58                 if (u == null || u.equals(msgState.sender))
59                     continue;
60                 u.sendMessage (msgState.mp);
61             }
62             for (Enumeration JavaDoc e = UserManager.mgr.notListedAsOnlineVips(); e.hasMoreElements (); ) {
63                 User u = (User) e.nextElement ();
64                 if (u == null || u.equals(msgState.sender))
65                     continue;
66                 u.sendMessage (msgState.mp);
67             }
68             msgState.msgTemplate = "message.m.vip.confirm";
69             msgState.sender.sendMessage (msgState.mp);
70         } else {
71             StringBuffer JavaDoc sb = new StringBuffer JavaDoc ();
72             Vector JavaDoc v = UserManager.mgr.onlineVipList();
73             if (v.size() == 0) {
74                 msgState.msgTemplate = "error.vip.noVipOnline";
75                 msgState.sender.sendMessage (msgState.mp);
76                 return false;
77             }
78             if (v.size() == 1) {
79                 msgState.msgTemplate="message.vip.singular";
80                 msgState.usercontext = (User) v.get(0);
81             } else {
82                 msgState.msgTemplate="message.vip.plural";
83                 msgState.usrList = v.toArray();
84             }
85             msgState.sender.sendMessage(msgState.mp);
86         }
87         return true;
88     }
89 }
90
Popular Tags