📄 cmdkickhard.java
字号:
/**
* Copyright (C) 2003 Manfred Andres
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Created on 28.09.2003
*/
package freecs.commands;
import java.util.Enumeration;
import java.util.Vector;
import freecs.interfaces.ICommand;
import freecs.interfaces.IUserRights;
import freecs.core.Group;
import freecs.core.User;
import freecs.content.MessageState;
import freecs.Server;
/**
* @author Manfred Andres
*
* freecs.commands
*/
public class CmdKickHard implements ICommand {
public String cmd= "/kh";
private static CmdKickHard selve=null;
private CommandSet cs;
private CmdKickHard () { }
private CmdKickHard (CommandSet cs) {
this.cs=cs;
}
public static ICommand getInstance (CommandSet cs) {
if (selve == null) {
selve = new CmdKickHard (cs);
}
return selve;
}
public boolean execute (MessageState msgState, String param) {
if (cs.isPunished (msgState))
return false;
msgState.message="";
int pos1 = param.indexOf (":");
if (pos1 > 0) {
msgState.message = param.substring(pos1+1);
param = param.substring(0,pos1).trim();
}
pos1 = param.indexOf (" ");
long time = Server.srv.DEFAULT_BAN_DURATION;
if (pos1 == -1) {
User cu = cs.getUser (msgState, param);
if (cu == null) return false;
Group cug = cu.getGroup();
msgState.source = cu.getName();
if (!cs.kickHard (msgState, cu, time))
return false;
msgState.msgTemplate = "message.kh.singular";
cug.sendModeraedMessage (msgState.mp);
return true;
} else if (!msgState.sender.hasRight(IUserRights.ROLE_VIP)) {
msgState.msgTemplate = "error.kh.mass.noRight";
msgState.sender.sendMessage(msgState.mp);
return false;
}
String[] parts = param.split(" ");
long customTime=-1;
try {
customTime = Long.parseLong(parts[parts.length-1],10);
} catch (NumberFormatException nfe) {
/* last arg is not a number so it will be treated as a user */
}
time = customTime;
Vector grps = new Vector ();
StringBuffer t = new StringBuffer();
msgState.useRenderCache = false;
for (int i = 0; i < parts.length - (customTime==-1 ? 0 : 1); i++) {
User cu = cs.getUser (msgState, parts[i]);
if (cu == null)
continue;
Group cug = cu.getGroup();
String uname = cu.getName ();
if (!cs.kickHard (msgState, cu, time))
continue;
if (!grps.contains(cug))
grps.addElement(cug);
t.append (uname).append (", ");
}
if (t.length() < 3)
return false;
msgState.source = t.substring(0, t.length()-2);
msgState.msgTemplate="message.kh.plural";
for (Enumeration e = grps.elements(); e.hasMoreElements(); ) {
Group cg = (Group) e.nextElement();
cg.sendModeraedMessage (msgState.mp);
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -