1 20 21 package freecs.commands; 22 import java.util.Enumeration ; 23 import java.util.Vector ; 24 25 import freecs.interfaces.ICommand; 26 import freecs.core.User; 27 import freecs.core.UserManager; 28 import freecs.content.MessageState; 29 30 35 public class CmdListOnlineFriends extends AbstractCommand { 36 public final String cmd= "/f"; 37 private static final ICommand selve=new CmdListOnlineFriends(); 38 39 private CmdListOnlineFriends () { } 40 41 public static ICommand getInstance () { 42 return selve; 43 } 44 45 public boolean execute (MessageState msgState, String param) { 46 if (msgState.sender.numberOfFriends () < 1) { 47 msgState.msgTemplate = "error.fl.nofriends"; 48 msgState.sender.sendMessage (msgState.mp); 49 return false; 50 } 51 Vector onlineFriends = new Vector (); 52 for (Enumeration e = msgState.sender.friends (); e.hasMoreElements (); ) { 53 String uname = (String ) e.nextElement (); 54 msgState.usercontext = UserManager.mgr.getUserByName (uname); 55 if (msgState.usercontext==null) 56 continue; 57 onlineFriends.add(msgState.usercontext); 58 } 59 if (onlineFriends.size() < 1) { 60 msgState.msgTemplate="error.f.noFriendOnline"; 61 msgState.sender.sendMessage (msgState.mp); 62 return false; 63 } 64 msgState.msgTemplate = "message.f.headline"; 65 msgState.param = String.valueOf(onlineFriends.size()); 66 msgState.sender.sendMessage (msgState.mp); 67 68 msgState.useRenderCache = false; 69 msgState.msgTemplate = "message.f"; 70 for (Enumeration e = onlineFriends.elements(); e.hasMoreElements(); ) { 71 msgState.usercontext = (User) e.nextElement(); 72 msgState.sender.sendMessage(msgState.mp); 73 } 74 msgState.msgTemplate = "message.f.count"; 75 msgState.sender.sendMessage(msgState.mp); 76 return true; 77 } 78 } 79 | Popular Tags |