KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freecs > commands > CmdIgnore


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.IUserStates;
27 import freecs.content.MessageState;
28 import freecs.core.User;
29 import freecs.Server;
30
31 /**
32  * @author Manfred Andres
33  *
34  * freecs.commands
35  */

36 public class CmdIgnore extends AbstractCommand {
37     public final String JavaDoc cmd= "/ig";
38     private static final ICommand selve= new CmdIgnore();
39
40     private CmdIgnore () { }
41     
42     public static ICommand getInstance () {
43         return selve;
44     }
45     
46     public boolean execute (MessageState msgState, String JavaDoc param) {
47         if (param.length () < 1) {
48             msgState.msgTemplate = "error.ig.noArg";
49             msgState.sender.sendMessage (msgState.mp);
50             return false;
51         }
52         Vector JavaDoc found = getMultibleUsers(msgState, param);
53         for (Iterator JavaDoc e = found.iterator(); e.hasNext(); ) {
54             User cu = (User) e.next();
55             if (cu == null)
56                 continue;
57             if (cu.hasRight (IUserStates.ROLE_VIP)) {
58                 e.remove();
59                 continue;
60             }
61             if (cu.equals(msgState.sender)) {
62                 e.remove();
63                 continue;
64             }
65             msgState.usercontext = cu;
66             StringBuffer JavaDoc tsb = new StringBuffer JavaDoc ("User ").append (msgState.sender.getName ()).append (" is ignoring ").append (cu.getName ());
67             Server.log (this, tsb.toString (), Server.MSG_STATE, Server.LVL_VERBOSE);
68             msgState.sender.ignoreUser(msgState.usercontext);
69         }
70         if (found.size()==0)
71             return false;
72         if (found.size()==1) {
73             msgState.msgTemplate="message.ig.singular";
74         } else {
75             msgState.msgTemplate="message.ig.plural";
76             msgState.usrList = found.toArray();
77         }
78         msgState.sender.sendMessage(msgState.mp);
79         return true;
80     }
81     
82     public String JavaDoc toString() {
83         return ("[CmdIgnore]");
84     }
85 }
86
Popular Tags