CommandFramework3 #94
@ -36,8 +36,9 @@ public class TestCommand extends SWCommand {
|
||||
}
|
||||
|
||||
// One Help Command, the first Parameter should be some kind of CommandSender
|
||||
// The second argument can only be a varAgrs string of what arguments was tried to map
|
||||
@RegisterHelp
|
||||
public void testHelp(Player player) {
|
||||
public void testHelp(Player player, String... args) {
|
||||
player.sendMessage("This is your help message");
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,12 @@ public abstract class SWCommand {
|
||||
}
|
||||
});
|
||||
add(RegisterHelp.class, method, i -> i != 1, true, null, (anno, parameters) -> {
|
||||
if (!parameters[parameters.length - 1].isVarArgs()) {
|
||||
return;
|
||||
}
|
||||
if (parameters[parameters.length - 1].getType().getComponentType() != String.class) {
|
||||
return;
|
||||
}
|
||||
commandHelpSet.add(new SubCommand(this, method, anno.value()));
|
||||
});
|
||||
}
|
||||
|
@ -24,10 +24,7 @@ import org.bukkit.command.CommandSender;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
class SubCommand {
|
||||
@ -63,7 +60,7 @@ class SubCommand {
|
||||
for (Enum<?> enumConstant : enumClass.getEnumConstants()) {
|
||||
tabCompletes.add(enumConstant.name().toLowerCase());
|
||||
}
|
||||
arguments[i] = SWCommandUtils.createMapper(s -> SWCommandUtils.ENUM_MAPPER.apply(enumClass, s), s -> tabCompletes);
|
||||
arguments[i - 1] = SWCommandUtils.createMapper(s -> SWCommandUtils.ENUM_MAPPER.apply(enumClass, s), s -> tabCompletes);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -72,7 +69,7 @@ class SubCommand {
|
||||
name = mapper.value();
|
||||
}
|
||||
|
||||
arguments[i] = SWCommandUtils.MAPPER_FUNCTIONS.getOrDefault(name, SWCommandUtils.ERROR_FUNCTION);
|
||||
arguments[i - 1] = SWCommandUtils.MAPPER_FUNCTIONS.getOrDefault(name, SWCommandUtils.ERROR_FUNCTION);
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,6 +77,9 @@ class SubCommand {
|
||||
if (args.length < arguments.length - 1) {
|
||||
return false;
|
||||
}
|
||||
if (!varArgs && args.length > arguments.length) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Object[] objects = SWCommandUtils.generateArgumentArray(arguments, args, varArgs, subCommand);
|
||||
objects[0] = commandSenderFunction.apply(commandSender);
|
||||
@ -97,7 +97,7 @@ class SubCommand {
|
||||
if (!varArgs && args.length < arguments.length - 1) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<String> argsList = Arrays.asList(args);
|
||||
List<String> argsList = new LinkedList<>(Arrays.asList(args));
|
||||
|
||||
for (String value : subCommand) {
|
||||
String s = argsList.remove(0);
|
||||
if (argsList.isEmpty()) return Collections.singletonList(value);
|
||||
@ -107,7 +107,9 @@ class SubCommand {
|
||||
String s = argsList.remove(0);
|
||||
if (argsList.isEmpty()) return argument.tabCompletes(s);
|
||||
Lixfel
hat
Entweder du behandelst im SWCommand nicht den Fall null, oder du returnst immer eine leere Liste. Bitte nicht beides zeitgleich. Entweder du behandelst im SWCommand nicht den Fall null, oder du returnst immer eine leere Liste. Bitte nicht beides zeitgleich.
YoyoNow
hat
Denn fall null behandle ich eigentlich wegen unsauberen TabCompletern, die eigengeschrieben sind. Denn fall null behandle ich eigentlich wegen unsauberen TabCompletern, die eigengeschrieben sind.
Lixfel
hat
Dann nutze doch auch einfach immer null. Dann nutze doch auch einfach immer null.
|
||||
try {
|
||||
argument.map(s);
|
||||
if (argument.map(s) == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Ich denke mal, das throw new SecurityException aus der Zeile drüber wäre auch angebracht. Auf jeden Fall für "RuntimeException".