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.content.MessageState; 28 import freecs.core.GroupManager; 29 import freecs.core.User; 30 import freecs.interfaces.IUserStates; 31 32 37 public class CmdBan extends AbstractCommand { 38 public final String cmd= "/ban"; 39 private static final ICommand selve= new CmdBan(); 40 41 private CmdBan () { } 42 43 public static ICommand getInstance () { 44 return selve; 45 } 46 47 public boolean execute (MessageState msgState, String param) { 48 if (isPunished (msgState)) 49 return false; 50 String parts[] = param.split (":"); 51 param = parts[0]; 52 msgState.targetGroup = null; 53 if (parts.length > 1) { 54 msgState.targetGroup = GroupManager.mgr.getGroup (parts[1]); 55 if (msgState.targetGroup==null) { 56 msgState.param = parts[1]; 57 msgState.msgTemplate="error.group.notExisting"; 58 msgState.sender.sendMessage(msgState.mp); 59 return false; 60 } 61 } else 62 msgState.targetGroup = msgState.sender.getGroup (); 63 if (!msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 64 if (msgState.targetGroup.hasState(IGroupState.ENTRANCE)) { 65 msgState.msgTemplate = "error.noRight.noVipAdmin"; 66 msgState.sender.sendMessage (msgState.mp); 67 return false; 68 } else if (!msgState.targetGroup.usrIsSu(msgState.sender)) { 69 msgState.msgTemplate="error.noRight.noSuVipAdmin"; 70 msgState.sender.sendMessage(msgState.mp); 71 return false; 72 } 73 } 74 if (param == null || param.length () < 1) { 75 msgState.msgTemplate = "error.ban.noArg"; 76 msgState.sender.sendMessage (msgState.mp); 77 return false; 78 } 79 msgState.useRenderCache=false; 80 ICommand ic = CommandSet.getCommandSet().getCommand("/k"); 81 Vector found = getMultibleUsers(msgState, param); 82 MessageState bkup = (MessageState) msgState.clone(); 83 for (Iterator e = found.iterator(); e.hasNext(); ) { 84 User cu = (User) e.next(); 85 if (cu.hasRight (IUserStates.PROTECTED_FROM_BAN) 86 && !msgState.sender.hasRight(IUserStates.ROLE_GOD)) { 87 User luc = msgState.usercontext; 88 msgState.usercontext = cu; 89 msgState.msgTemplate = "error.noRight.noAdmin"; 90 msgState.sender.sendMessage (msgState.mp); 91 msgState.usercontext=luc; 92 e.remove(); 93 continue; 94 } 95 if (msgState.targetGroup.equals(cu.getGroup())) { 96 if (!ic.execute(msgState, cu.getName())) { 97 e.remove(); 98 msgState.inhale(bkup); 99 continue; 100 } 101 msgState.inhale(bkup); 102 } 103 msgState.usercontext = cu; 104 msgState.targetGroup.setBanForUser (cu.getName(), true); 105 msgState.msgTemplate = "message.ban.personal"; 106 cu.sendMessage (msgState.mp); 107 } 108 if (found.size()==0) 109 return false; 110 if (found.size()==1) { 111 msgState.msgTemplate = "message.ban.singular"; 112 msgState.targetGroup.sendModeratedMessage (msgState.mp); 113 if (!msgState.sender.getGroup().equals(msgState.targetGroup)) { 114 msgState.msgTemplate= "message.ban.confirm.singular"; 115 msgState.sender.sendMessage (msgState.mp); 116 } 117 } else { 118 msgState.usrList = found.toArray(); 119 msgState.msgTemplate = "message.ban.plural"; 120 msgState.targetGroup.sendModeratedMessage (msgState.mp); 121 if (!msgState.sender.getGroup().equals(msgState.targetGroup)) { 122 msgState.msgTemplate= "message.ban.confirm.plural"; 123 msgState.sender.sendMessage (msgState.mp); 124 } 125 } 126 return true; 127 } 128 } 129 | Popular Tags |