1 20 21 package freecs.commands; 22 23 import java.util.Enumeration ; 24 import java.util.Vector ; 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 37 public class CmdListVips extends AbstractCommand { 38 public final String 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 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 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 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 sb = new StringBuffer (); 72 Vector 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 |