Fix varArgs, fix help
Dieser Commit ist enthalten in:
Ursprung
a7bf487336
Commit
ce2cd3d1bf
@ -135,7 +135,16 @@ public abstract class SWCommand {
|
|||||||
commandSet.add(new SubCommand(this, method, anno.value()));
|
commandSet.add(new SubCommand(this, method, anno.value()));
|
||||||
});
|
});
|
||||||
|
|
||||||
commandSet.sort(Comparator.comparingInt(o -> -o.subCommand.length));
|
this.commandSet.sort((o1, o2) -> {
|
||||||
|
int compare = Integer.compare(-o1.subCommand.length, -o2.subCommand.length);
|
||||||
|
if (compare != 0) {
|
||||||
|
return compare;
|
||||||
|
} else {
|
||||||
|
int i1 = o1.varArgType != null ? Integer.MAX_VALUE : o1.arguments.length;
|
||||||
|
int i2 = o2.varArgType != null ? Integer.MAX_VALUE : o2.arguments.length;
|
||||||
|
return Integer.compare(i1, i2);
|
||||||
|
}
|
||||||
|
});
|
||||||
commandHelpSet.sort(Comparator.comparingInt(o -> -o.subCommand.length));
|
commandHelpSet.sort(Comparator.comparingInt(o -> -o.subCommand.length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,8 +110,14 @@ public class SWCommandUtils {
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (varArgType != null && index > args.length - 1) {
|
||||||
|
Object varArgument = Array.newInstance(varArgType, 0);
|
||||||
|
arguments[arguments.length - 1] = varArgument;
|
||||||
|
} else {
|
||||||
for (int i = 0; i < parameters.length - (varArgType != null ? 1 : 0); i++) {
|
for (int i = 0; i < parameters.length - (varArgType != null ? 1 : 0); i++) {
|
||||||
|
System.out.println(index);
|
||||||
arguments[i + 1] = parameters[i].map(args[index]);
|
arguments[i + 1] = parameters[i].map(args[index]);
|
||||||
|
System.out.println(arguments[i + 1]);
|
||||||
index++;
|
index++;
|
||||||
if (arguments[i + 1] == null) {
|
if (arguments[i + 1] == null) {
|
||||||
throw new CommandParseException();
|
throw new CommandParseException();
|
||||||
@ -119,7 +125,7 @@ public class SWCommandUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (varArgType != null) {
|
if (varArgType != null) {
|
||||||
int length = args.length - parameters.length + 1;
|
int length = args.length - parameters.length - subCommand.length + 1;
|
||||||
Object varArgument = Array.newInstance(varArgType, length);
|
Object varArgument = Array.newInstance(varArgType, length);
|
||||||
arguments[arguments.length - 1] = varArgument;
|
arguments[arguments.length - 1] = varArgument;
|
||||||
|
|
||||||
@ -132,6 +138,7 @@ public class SWCommandUtils {
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,9 +32,9 @@ class SubCommand {
|
|||||||
private SWCommand swCommand;
|
private SWCommand swCommand;
|
||||||
private Method method;
|
private Method method;
|
||||||
String[] subCommand;
|
String[] subCommand;
|
||||||
private TypeMapper<?>[] arguments;
|
TypeMapper<?>[] arguments;
|
||||||
private Function<CommandSender, ?> commandSenderFunction;
|
private Function<CommandSender, ?> commandSenderFunction;
|
||||||
private Class<?> varArgType = null;
|
Class<?> varArgType = null;
|
||||||
|
|
||||||
public SubCommand(SWCommand swCommand, Method method, String[] subCommand) {
|
public SubCommand(SWCommand swCommand, Method method, String[] subCommand) {
|
||||||
this(swCommand, method, subCommand, new HashMap<>());
|
this(swCommand, method, subCommand, new HashMap<>());
|
||||||
@ -81,10 +81,10 @@ class SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean invoke(CommandSender commandSender, String[] args) {
|
boolean invoke(CommandSender commandSender, String[] args) {
|
||||||
if (args.length < arguments.length - 1) {
|
if (args.length < arguments.length + subCommand.length - (varArgType != null ? 1 : 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (varArgType == null && args.length > arguments.length) {
|
if (varArgType == null && args.length > arguments.length + subCommand.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -101,7 +101,7 @@ class SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> tabComplete(CommandSender commandSender, String[] args) {
|
List<String> tabComplete(CommandSender commandSender, String[] args) {
|
||||||
if (varArgType == null && args.length < arguments.length - 1) {
|
if (varArgType == null && args.length < arguments.length + subCommand.length - 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<String> argsList = new LinkedList<>(Arrays.asList(args));
|
List<String> argsList = new LinkedList<>(Arrays.asList(args));
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren