1 20 21 package freecs.commands; 22 23 import java.util.Iterator ; 24 import java.util.Vector ; 25 26 import freecs.content.MessageState; 27 import freecs.core.Group; 28 import freecs.core.User; 29 import freecs.interfaces.ICommand; 30 import freecs.interfaces.IUserStates; 31 import freecs.util.GroupUserList; 32 33 38 public class CmdUnPunish extends AbstractCommand { 39 public final String cmd= "/rgag"; 40 private static final ICommand selve=new CmdUnPunish(); 41 42 private CmdUnPunish () { } 43 44 public static ICommand getInstance () { 45 return selve; 46 } 47 48 public boolean execute (MessageState msgState, String param) { 49 if (isPunished (msgState)) 50 return false; 51 boolean mayPunish = msgState.sender.hasRight (IUserStates.MAY_PUNISH); 52 Group sg = msgState.sender.getGroup (); 53 boolean isSu = sg.usrIsSu (msgState.sender); 54 if (!mayPunish && !isSu) { 55 msgState.msgTemplate = "error.noRight.noSuVipAdmin"; 56 msgState.sender.sendMessage (msgState.mp); 57 return false; 58 } 59 if (param.length () < 1) { 60 msgState.msgTemplate = "error.rgag.noArg"; 61 msgState.sender.sendMessage (msgState.mp); 62 return false; 63 } 64 int pos = param.indexOf(":"); 65 if (pos != -1) { 66 msgState.reason = param.substring (pos+1); 67 param = param.substring (0, pos); 68 } else 69 msgState.reason = ""; 70 71 if (param.indexOf(" ") > -1 73 && !msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 74 msgState.msgTemplate = "error.mass.noRight.noVipAdmin"; 75 msgState.sender.sendMessage (msgState.mp); 76 return false; 77 } 78 GroupUserList gul = new GroupUserList(); 79 Vector found = getMultibleUsers(msgState, param); 80 msgState.useRenderCache = false; 81 for (Iterator i = found.iterator(); i.hasNext (); ) { 82 User cu = (User) i.next(); 83 if (cu.equals(msgState.sender)) { 84 i.remove(); 85 continue; 86 } 87 if (!mayPunish 89 && (cu.getGroup() == null 90 || !cu.getGroup().equals(msgState.sender.getGroup()))) { 91 msgState.msgTemplate = "error.noRight.noVipAdmin"; 92 User u = msgState.usercontext; 93 msgState.usercontext = cu; 94 msgState.sender.sendMessage (msgState.mp); 95 msgState.usercontext = u; 96 i.remove(); 97 continue; 98 } 99 boolean p = false; 100 if ((p && msgState.sender.isPunished()) 101 || cu == null || cu.isPunished () == p) 102 return false; 103 if (!cu.hasRight(IUserStates.FREELY_PUNISHABLE)) { 104 if (cu.hasRight(IUserStates.ROLE_GOD)) { 105 msgState.msgTemplate = "error.noRight.isAdmin"; 106 msgState.usercontext = cu; 107 msgState.sender.sendMessage (msgState.mp); 108 i.remove(); 109 continue; 110 } 111 if (cu.hasRight(IUserStates.ROLE_VIP) 112 && !msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 113 msgState.msgTemplate = "error.noRight.isVip"; 114 msgState.usercontext = cu; 115 msgState.sender.sendMessage (msgState.mp); 116 i.remove(); 117 continue; 118 } 119 if (cu.hasRight (IUserStates.PROTECTED_FROM_PUNISH) 120 && !msgState.sender.hasRight(IUserStates.ROLE_GOD)) { 121 msgState.msgTemplate = "error.gag.protected"; 122 msgState.usercontext = cu; 123 msgState.sender.sendMessage (msgState.mp); 124 i.remove(); 125 continue; 126 } 127 } 128 cu.setPunish (p); 129 if (found.size() > 1) { 130 msgState.msgTemplate= "message.rgag.personal"; 131 cu.sendMessage (msgState.mp); 132 } 133 gul.addUser(cu); 134 msgState.usercontext = cu; 135 } 136 if (found.size()==0) 137 return false; 138 if (found.size()==1) { 139 msgState.msgTemplate="message.rgag.singular"; 140 msgState.usercontext.getGroup().sendMessage(msgState.mp); 141 if (!msgState.sender.getGroup().equals(msgState.usercontext.getGroup())) { 142 msgState.msgTemplate="message.rgag.confirm.singular"; 143 msgState.sender.sendMessage(msgState.mp); 144 } 145 return true; 146 } 147 msgState.msgTemplate="message.rgag.confirm.plural"; 148 msgState.usrList = found.toArray(); 149 msgState.sender.sendMessage (msgState.mp); 150 gul.sendMessage(msgState, "message.rgag", false); 151 return true; 152 } 153 } 154 | Popular Tags |