1 20 21 package freecs.commands; 22 import java.util.Iterator ; 23 import java.util.Vector ; 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 37 public class CmdInvite extends AbstractCommand { 38 public final String 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 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 found = getMultibleUsers(msgState, param); 75 msgState.useRenderCache = false; 76 for (Iterator 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 |