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.IUserStates; 27 import freecs.util.GroupUserList; 28 import freecs.content.MessageState; 29 import freecs.core.User; 30 31 36 public class CmdChangeForeignColor extends AbstractCommand { 37 public final String cmd= "/fcol"; 38 private static final ICommand selve=new CmdChangeForeignColor(); 39 40 private CmdChangeForeignColor () { } 41 42 public static ICommand getInstance () { 43 return selve; 44 } 45 46 public boolean execute (MessageState msgState, String param) { 47 if (isPunished (msgState)) 48 return false; 49 if (!msgState.sender.hasRight(IUserStates.ROLE_VIP)) { 50 msgState.msgTemplate = "error.noRight.noVipAdmin"; 51 msgState.sender.sendMessage(msgState.mp); 52 return false; 53 } 54 if (param==null 55 || param.length() < 1) { 56 msgState.msgTemplate = "error.fcol.noArg"; 57 msgState.sender.sendMessage(msgState.mp); 58 return false; 59 } 60 int pos = param.indexOf(" "); 61 if (pos == -1) { 62 msgState.msgTemplate = "error.fcol.noUser"; 63 msgState.sender.sendMessage(msgState.mp); 64 return false; 65 } 66 msgState.param = param.substring(0,pos); 67 String colcode = msgState.param; 68 param = param.substring (pos+1); 69 if (!isColorCodeValid(msgState)) { 70 msgState.sender.sendMessage(msgState.mp); 71 return false; 72 } 73 Vector found = getMultibleUsers(msgState, param); 74 GroupUserList gul = new GroupUserList(); 75 for (Iterator i = found.iterator(); i.hasNext(); ) { 76 User u = (User) i.next(); 77 msgState.param = colcode; 78 if (u.equals(msgState.sender)) { 79 i.remove(); 80 continue; 81 } else if (isVip(u, u.getGroup(), msgState) 82 && !isVip(msgState.sender, u.getGroup(), msgState)) { 83 msgState.msgTemplate = "error.noRight.noVipAdmin"; 84 msgState.sender.sendMessage(msgState.mp); 85 i.remove(); 86 continue; 87 } else if (!isVip(msgState.sender, u.getGroup(), msgState) 88 && !msgState.sender.hasRight(IUserStates.ROLE_GOD)) { 89 msgState.targetGroup = u.getGroup(); 90 if (msgState.usrList.length > 1) 91 msgState.msgTemplate = "error.membership.notMember.many"; 92 else 93 msgState.msgTemplate = "error.membership.notMember"; 94 msgState.usercontext=u; 95 msgState.sender.sendMessage(msgState.mp); 96 i.remove(); 97 continue; 98 } 99 u.setColCode(msgState.param); 100 msgState.msgTemplate = "message.fcol.personal"; 101 msgState.usrList = found.toArray(); 102 msgState.usercontext=u; 103 if (found.size() > 1) 104 u.sendMessage(msgState.mp); 105 gul.addUser(u); 106 } 107 if (found.size() == 0) 108 return false; 109 if (found.size() == 1) { 110 msgState.usercontext = (User) found.get(0); 111 msgState.msgTemplate = "message.fcol.singular"; 112 msgState.targetGroup = msgState.usercontext.getGroup(); 113 if (msgState.targetGroup != null) { 114 msgState.targetGroup.sendMessage(msgState.mp); 115 if (!msgState.targetGroup.equals(msgState.sender.getGroup())) { 116 msgState.msgTemplate = "message.fcol.confirm.singular"; 117 msgState.sender.sendMessage(msgState.mp); 118 } 119 } 120 return true; 121 } 122 msgState.usrList = found.toArray(); 123 msgState.msgTemplate = "message.fcol.confirm.plural"; 124 msgState.sender.sendMessage(msgState.mp); 125 gul.sendMessage(msgState, "message.fcol", true); 126 return true; 127 } 128 } 129 | Popular Tags |