Fix
This commit is contained in:
@@ -8,10 +8,13 @@ import java.util.Objects;
|
||||
* @author Bkm016
|
||||
* @since 2018-04-17
|
||||
*/
|
||||
public class CommandArgument {
|
||||
public class Argument {
|
||||
|
||||
// 参数名称
|
||||
private String name;
|
||||
// 是否必须
|
||||
private boolean required;
|
||||
// 参数补全
|
||||
private CommandTab tab;
|
||||
|
||||
public String getName() {
|
||||
@@ -26,19 +29,19 @@ public class CommandArgument {
|
||||
return tab;
|
||||
}
|
||||
|
||||
public CommandArgument(String name) {
|
||||
public Argument(String name) {
|
||||
this(name, true);
|
||||
}
|
||||
|
||||
public CommandArgument(String name, CommandTab tab) {
|
||||
public Argument(String name, CommandTab tab) {
|
||||
this(name, true, tab);
|
||||
}
|
||||
|
||||
public CommandArgument(String name, boolean required) {
|
||||
public Argument(String name, boolean required) {
|
||||
this(name, required, null);
|
||||
}
|
||||
|
||||
public CommandArgument(String name, boolean required, CommandTab tab) {
|
||||
public Argument(String name, boolean required, CommandTab tab) {
|
||||
this.name = name;
|
||||
this.required = required;
|
||||
this.tab = tab;
|
||||
@@ -54,10 +57,10 @@ public class CommandArgument {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof CommandArgument)) {
|
||||
if (!(o instanceof Argument)) {
|
||||
return false;
|
||||
}
|
||||
CommandArgument that = (CommandArgument) o;
|
||||
Argument that = (Argument) o;
|
||||
return isRequired() == that.isRequired() &&
|
||||
Objects.equals(getName(), that.getName()) &&
|
||||
Objects.equals(tab, that.tab);
|
||||
@@ -23,5 +23,5 @@ public @interface BaseCommand {
|
||||
|
||||
String usage() default "";
|
||||
|
||||
String[] aliases() default "";
|
||||
String[] aliases() default {};
|
||||
}
|
||||
@@ -49,9 +49,9 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
|
||||
public static void loadCommandRegister(BaseMainCommand baseMainCommand) {
|
||||
List<Method> methods = new ArrayList<>();
|
||||
List<CommandField> fields = new ArrayList<>();
|
||||
baseMainCommand.getLinkClasses().forEach(clazz -> java.util.Arrays.stream(clazz.getDeclaredMethods()).filter(method -> method.getAnnotation(CommandRegister.class) != null).forEach(methods::add));
|
||||
baseMainCommand.getLinkClasses().forEach(clazz -> java.util.Arrays.stream(clazz.getDeclaredMethods()).filter(method -> method.getAnnotation(SubCommand.class) != null).forEach(methods::add));
|
||||
if (methods.size() > 0) {
|
||||
methods.sort(Comparator.comparingDouble(a -> a.getAnnotation(CommandRegister.class).priority()));
|
||||
methods.sort(Comparator.comparingDouble(a -> a.getAnnotation(SubCommand.class).priority()));
|
||||
methods.forEach(x -> {
|
||||
try {
|
||||
x.setAccessible(true);
|
||||
@@ -60,9 +60,9 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
|
||||
}
|
||||
});
|
||||
}
|
||||
baseMainCommand.getLinkClasses().forEach(clazz -> java.util.Arrays.stream(clazz.getDeclaredFields()).filter(field -> field.getAnnotation(CommandRegister.class) != null && field.getType().equals(io.izzel.taboolib.module.command.base.BaseSubCommand.class)).forEach(field -> fields.add(new CommandField(field, clazz))));
|
||||
baseMainCommand.getLinkClasses().forEach(clazz -> java.util.Arrays.stream(clazz.getDeclaredFields()).filter(field -> field.getAnnotation(SubCommand.class) != null && field.getType().equals(io.izzel.taboolib.module.command.base.BaseSubCommand.class)).forEach(field -> fields.add(new CommandField(field, clazz))));
|
||||
if (fields.size() > 0) {
|
||||
fields.sort(Comparator.comparingDouble(commandField -> commandField.getField().getAnnotation(CommandRegister.class).priority()));
|
||||
fields.sort(Comparator.comparingDouble(commandField -> commandField.getField().getAnnotation(SubCommand.class).priority()));
|
||||
fields.forEach(commandField -> {
|
||||
try {
|
||||
commandField.getField().setAccessible(true);
|
||||
@@ -123,7 +123,7 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
|
||||
return label.stream().filter(l -> args[0].isEmpty() || l.toLowerCase().startsWith(args[0].toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
for (io.izzel.taboolib.module.command.base.BaseSubCommand subCommand : subCommands) {
|
||||
CommandArgument[] arguments = subCommand.getArguments();
|
||||
Argument[] arguments = subCommand.getArguments();
|
||||
if (args[0].equalsIgnoreCase(subCommand.getLabel()) && args.length - 1 <= arguments.length) {
|
||||
CommandTab commandTab = arguments[args.length - 2].getTab();
|
||||
if (commandTab != null) {
|
||||
@@ -208,7 +208,10 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
|
||||
}
|
||||
|
||||
private void disguisedPlugin() {
|
||||
linkClasses.forEach(clazz -> disguisedPlugin(clazz, registerCommand.getPlugin()));
|
||||
try {
|
||||
linkClasses.forEach(clazz -> disguisedPlugin(clazz, registerCommand.getPlugin()));
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private void disguisedPlugin(Class<?> targetClass, Plugin plugin) {
|
||||
|
||||
@@ -32,8 +32,8 @@ public abstract class BaseSubCommand {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
public CommandArgument[] getArguments() {
|
||||
return new CommandArgument[0];
|
||||
public Argument[] getArguments() {
|
||||
return new Argument[0];
|
||||
}
|
||||
|
||||
public CommandType getType() {
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.lang.annotation.Target;
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandRegister {
|
||||
public @interface SubCommand {
|
||||
|
||||
double priority() default 0;
|
||||
|
||||
Reference in New Issue
Block a user