70 lines
1.4 KiB
Java
70 lines
1.4 KiB
Java
/**
|
|
*
|
|
*/
|
|
package cn.citycraft.CTZServer.commands;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.bukkit.command.CommandException;
|
|
|
|
import cn.citycraft.CTZServer.ServerThread;
|
|
|
|
/**
|
|
* 子命令处理类
|
|
*
|
|
* @author 蒋天蓓 2015年8月22日上午8:29:44
|
|
*/
|
|
public class HandlerMainCommand {
|
|
/**
|
|
* 命令监听类列表
|
|
*/
|
|
private final List<BaseCommand> commandlist = new ArrayList<BaseCommand>();;
|
|
/**
|
|
* 插件主类
|
|
*/
|
|
ServerThread main;
|
|
|
|
/**
|
|
* 注册子命令
|
|
*
|
|
* @param yum
|
|
* - 插件主类
|
|
*/
|
|
public HandlerMainCommand(final ServerThread serverThread) {
|
|
this.main = serverThread;
|
|
}
|
|
|
|
public boolean onCommand(final String label, final String[] args) {
|
|
for (final BaseCommand command : commandlist) {
|
|
if (command.isValidTrigger(label)) {
|
|
if (args.length >= command.getMinimumArguments()) {
|
|
try {
|
|
command.execute(label, args);
|
|
return true;
|
|
} catch (final CommandException e) {
|
|
printl(e.getMessage());
|
|
}
|
|
} else {
|
|
printl("§c错误的参数 §e使用方法 /" + command.getName() + command.getPossibleArguments());
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void printl(final String msg) {
|
|
System.out.println(msg);
|
|
}
|
|
|
|
/**
|
|
* 注册命令
|
|
*
|
|
* @param command
|
|
* - 被注册的命令类
|
|
*/
|
|
public void registerCommand(final BaseCommand command) {
|
|
commandlist.add(command);
|
|
}
|
|
}
|