fix: 修复默认命令调用逻辑错误

Signed-off-by: 502647092 <admin@yumc.pw>
merge/1/MERGE
502647092 2016-11-10 16:34:00 +08:00
parent 9d45715190
commit 560724dd52
3 changed files with 50 additions and 64 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);
}
}