1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-22 01:48:50 +00:00

feat: 添加命令注册调试

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-12-12 17:51:16 +08:00
parent a631bc2699
commit 69d9faea9e

View File

@ -1,5 +1,8 @@
package pw.yumc.YumCore.commands; package pw.yumc.YumCore.commands;
import java.lang.reflect.Method;
import java.util.*;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
@ -7,6 +10,7 @@ import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import pw.yumc.YumCore.bukkit.Log; import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P; import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.bukkit.compatible.C; import pw.yumc.YumCore.bukkit.compatible.C;
@ -18,9 +22,6 @@ import pw.yumc.YumCore.commands.interfaces.Executor;
import pw.yumc.YumCore.commands.interfaces.HelpGenerator; import pw.yumc.YumCore.commands.interfaces.HelpGenerator;
import pw.yumc.YumCore.commands.interfaces.HelpParse; import pw.yumc.YumCore.commands.interfaces.HelpParse;
import java.lang.reflect.Method;
import java.util.*;
/** /**
* 子命令管理类 * 子命令管理类
* *
@ -79,6 +80,7 @@ public class CommandSub implements TabExecutor {
if (cmd == null) { if (cmd == null) {
if ((cmd = CommandKit.create(name)) == null) { throw new IllegalStateException("未找到命令 必须在plugin.yml先注册 " + name + " 命令!"); } if ((cmd = CommandKit.create(name)) == null) { throw new IllegalStateException("未找到命令 必须在plugin.yml先注册 " + name + " 命令!"); }
} }
Log.d("初始化命令: %s", name);
cmd.setExecutor(this); cmd.setExecutor(this);
cmd.setTabCompleter(this); cmd.setTabCompleter(this);
} }
@ -216,6 +218,7 @@ public class CommandSub implements TabExecutor {
*/ */
public CommandSub register(Executor... clazzs) { public CommandSub register(Executor... clazzs) {
for (Executor clazz : clazzs) { for (Executor clazz : clazzs) {
Log.d("解析执行类: %s", clazz.getClass().getName());
Method[] methods = clazz.getClass().getDeclaredMethods(); Method[] methods = clazz.getClass().getDeclaredMethods();
for (Method method : methods) { for (Method method : methods) {
if (registerCommand(method, clazz)) { if (registerCommand(method, clazz)) {
@ -242,7 +245,7 @@ public class CommandSub implements TabExecutor {
CommandInfo ci = CommandInfo.parse(method, clazz); CommandInfo ci = CommandInfo.parse(method, clazz);
if (ci != null) { if (ci != null) {
Class[] params = method.getParameterTypes(); Class[] params = method.getParameterTypes();
Log.d("注册命令 %s 参数类型: %s", ci.getName(), Arrays.toString(params)); Log.d("注册命令: %s 参数类型: %s", ci.getName(), Arrays.toString(params));
try { try {
Class<? extends CommandSender> sender = params[0]; Class<? extends CommandSender> sender = params[0];
// 用于消除unuse警告 // 用于消除unuse警告
@ -273,6 +276,7 @@ public class CommandSub implements TabExecutor {
CommandTabInfo ti = CommandTabInfo.parse(method, clazz); CommandTabInfo ti = CommandTabInfo.parse(method, clazz);
if (ti != null) { if (ti != null) {
if (method.getReturnType().equals(List.class)) { if (method.getReturnType().equals(List.class)) {
Log.d("注册命令补全: %s ", method.getName());
tabs.add(ti); tabs.add(ti);
return true; return true;
} }