mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-22 01:48:50 +00:00
fix: 修复默认命令调用逻辑错误
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
9d45715190
commit
560724dd52
@ -150,9 +150,6 @@ public class CommandManager implements TabExecutor {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (defCmd != null) {
|
||||
cmdCache.put(subcmd, defCmd);
|
||||
}
|
||||
if (!cmdCache.containsKey(subcmd)) {
|
||||
cmdCache.put(subcmd, CommandInfo.Unknow);
|
||||
}
|
||||
@ -209,7 +206,12 @@ public class CommandManager implements TabExecutor {
|
||||
}
|
||||
String subcmd = args[0].toLowerCase();
|
||||
if (subcmd.equalsIgnoreCase("help")) { return help.send(sender, command, label, args); }
|
||||
return getByCache(subcmd).execute(new CommandArgument(sender, command, label, moveStrings(args, 1)));
|
||||
CommandInfo cmd = getByCache(subcmd);
|
||||
if (cmd.equals(CommandInfo.Unknow) && defCmd != null) {
|
||||
return defCmd.execute(new CommandArgument(sender, command, label, args));
|
||||
} else {
|
||||
return cmd.execute(new CommandArgument(sender, command, label, moveStrings(args, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,14 +1,7 @@
|
||||
package pw.yumc.YumCore.commands.info;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
import pw.yumc.YumCore.bukkit.P;
|
||||
import pw.yumc.YumCore.commands.CommandArgument;
|
||||
@ -22,6 +15,13 @@ import pw.yumc.YumCore.commands.exception.CommandArgumentException;
|
||||
import pw.yumc.YumCore.commands.exception.CommandException;
|
||||
import pw.yumc.YumCore.commands.exception.CommandParseException;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 命令信息存储类
|
||||
*
|
||||
@ -95,8 +95,10 @@ public class CommandInfo {
|
||||
/**
|
||||
* 解析CommandInfo
|
||||
*
|
||||
* @param method 方法
|
||||
* @param origin 源对象
|
||||
* @param method
|
||||
* 方法
|
||||
* @param origin
|
||||
* 源对象
|
||||
* @return {@link CommandInfo}
|
||||
*/
|
||||
public static CommandInfo parse(Method method, Object origin) {
|
||||
@ -111,27 +113,15 @@ public class CommandInfo {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof CommandInfo) {
|
||||
return name.equalsIgnoreCase(((CommandInfo) obj).getName());
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* @param cmdArgs 命令参数
|
||||
* @param cmdArgs
|
||||
* 命令参数
|
||||
* @return 是否执行成功
|
||||
*/
|
||||
public boolean execute(final CommandArgument cmdArgs) {
|
||||
if (method == null) {
|
||||
return false;
|
||||
}
|
||||
if (method == null) { return false; }
|
||||
if (check(cmdArgs)) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
@ -182,11 +172,6 @@ public class CommandInfo {
|
||||
return sort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.toLowerCase().hashCode() + method.hashCode() + origin.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 是否为异步命令
|
||||
*/
|
||||
@ -197,19 +182,27 @@ public class CommandInfo {
|
||||
/**
|
||||
* 验证命令是否匹配
|
||||
*
|
||||
* @param cmd 需验证命令
|
||||
* @param cmd
|
||||
* 需验证命令
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public boolean isValid(String cmd) {
|
||||
return name.equalsIgnoreCase(cmd) || aliases.contains(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查命令
|
||||
*
|
||||
* @param cmdArgs 命令信息
|
||||
* @return 是否验证通过
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CommandInfo that = (CommandInfo) o;
|
||||
return Objects.equals(origin, that.origin) && Objects.equals(method, that.method) && Objects.equals(name, that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(origin, method, name);
|
||||
}
|
||||
|
||||
private boolean check(CommandArgument cmdArgs) {
|
||||
CommandSender sender = cmdArgs.getSender();
|
||||
return checkSender(sender) && checkArgs(sender, cmdArgs) && checkPerm(sender);
|
||||
|
@ -1,16 +1,16 @@
|
||||
package pw.yumc.YumCore.commands.info;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import pw.yumc.YumCore.bukkit.P;
|
||||
import pw.yumc.YumCore.commands.CommandArgument;
|
||||
import pw.yumc.YumCore.commands.annotation.Tab;
|
||||
import pw.yumc.YumCore.commands.exception.CommandException;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.P;
|
||||
import pw.yumc.YumCore.commands.CommandArgument;
|
||||
import pw.yumc.YumCore.commands.annotation.Tab;
|
||||
import pw.yumc.YumCore.commands.exception.CommandException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Tab补全
|
||||
@ -38,23 +38,10 @@ public class CommandTabInfo {
|
||||
*/
|
||||
public static CommandTabInfo parse(Method method, Object origin) {
|
||||
Tab tab = method.getAnnotation(Tab.class);
|
||||
if (tab != null) {
|
||||
return new CommandTabInfo(method, origin);
|
||||
}
|
||||
if (tab != null) { return new CommandTabInfo(method, origin); }
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof CommandTabInfo) {
|
||||
return method.equals(((CommandTabInfo) obj).getMethod());
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得补全List
|
||||
*
|
||||
@ -78,12 +65,16 @@ public class CommandTabInfo {
|
||||
}
|
||||
}
|
||||
|
||||
public Method getMethod() {
|
||||
return method;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CommandTabInfo that = (CommandTabInfo) o;
|
||||
return Objects.equals(origin, that.origin) && Objects.equals(method, that.method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return method.hashCode() + origin.hashCode();
|
||||
return Objects.hash(origin, method);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user