1 20 21 package freecs.commands; 22 import freecs.interfaces.ICommand; 23 import freecs.interfaces.IGroupState; 24 import freecs.interfaces.IUserStates; 25 import freecs.core.GroupManager; 26 import freecs.core.UserManager; 27 import freecs.core.User; 28 import freecs.content.MessageState; 29 30 35 public class CmdInviteAll extends AbstractCommand { 36 public final String cmd= "/ia"; 37 private static final ICommand selve=new CmdInviteAll(); 38 39 private CmdInviteAll () { } 40 41 public static ICommand getInstance () { 42 return selve; 43 } 44 45 public boolean execute (MessageState msgState, String param) { 46 if (isPunished (msgState)) return false; 47 msgState.targetGroup = msgState.sender.getGroup (); 48 49 if (param.length () < 1 50 && !msgState.sender.hasRight (IUserStates.ROLE_GOD)) { 51 msgState.msgTemplate = "error.noRight.noAdmin"; 52 msgState.sender.sendMessage (msgState.mp); 53 return false; 54 } 55 if (msgState.targetGroup.hasState(IGroupState.ENTRANCE)) { 57 msgState.msgTemplate = "error.ia.inviteStartGroup"; 58 msgState.sender.sendMessage (msgState.mp); 59 return false; 60 } 61 if (param.length () > 0 62 && !msgState.sender.hasRight(IUserStates.ROLE_GOD)) { 63 msgState.msgTemplate = "error.noRight.noAdmin"; 64 msgState.sender.sendMessage (msgState.mp); 65 return false; 66 } 67 if (param.length () < 1) { 68 msgState.targetGroup = msgState.sender.getGroup (); 69 int counter = 0; 70 User[] usrs = UserManager.mgr.ustr.toArray(); 71 for (int i = 0; i < usrs.length; i++) { 72 User cu = usrs[i]; 73 if (msgState.sender.equals (cu.invitedBy()) 74 && msgState.sender.getGroup().equals(cu.invitedTo())) 75 continue; 76 msgState.msgTemplate = null; 77 if (setInvited(msgState, cu)) { 78 counter++; 79 } 80 } 81 if (counter==0) 82 return false; 83 msgState.param = String.valueOf (counter); 84 msgState.msgTemplate = "message.ia.all"; 85 msgState.sender.getGroup ().sendMessage (msgState.mp); 86 return true; 87 } 88 msgState.sourceGroup = GroupManager.mgr.getGroup (param); 89 if (msgState.sourceGroup == null) { 90 msgState.msgTemplate = "error.group.notExisting"; 91 msgState.param = param; 92 msgState.sender.sendMessage (msgState.mp); 93 return false; 94 } 95 if (msgState.sourceGroup.hasState(IGroupState.ENTRANCE) 96 && !msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 97 msgState.msgTemplate = "error.noRight.noVipAdmin"; 98 msgState.sender.sendMessage (msgState.mp); 99 return false; 100 } 101 int counter = 0; 102 User[] usrs=msgState.sourceGroup.getUserArray(); 103 if (usrs==null) { 104 msgState.msgTemplate = "error.group.notExisting"; 106 msgState.param = param; 107 msgState.sender.sendMessage (msgState.mp); 108 return false; 109 } 110 for (int i = 0; i < usrs.length; i++) { 111 User cu = usrs[i]; 112 if (setInvited(msgState, cu)) 113 counter++; 114 } 115 if (counter==0) 116 return false; 117 msgState.param = String.valueOf (counter); 118 msgState.msgTemplate = "message.ia.group"; 119 msgState.sender.getGroup ().sendModeratedMessage (msgState.mp); 120 return true; 121 } 122 } 123 | Popular Tags |