Dieser Commit ist enthalten in:
Ursprung
2f331e169a
Commit
86ce398224
@ -20,12 +20,15 @@
|
||||
package de.steamwar.command;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ToString
|
||||
public class CommandPart {
|
||||
private static final String[] EMPTY_ARRAY = new String[0];
|
||||
|
||||
@ -43,6 +46,9 @@ public class CommandPart {
|
||||
|
||||
private CommandPart next = null;
|
||||
|
||||
@Setter
|
||||
private boolean ignoreAsArgument = false;
|
||||
|
||||
public CommandPart(TypeMapper<?> typeMapper, GuardChecker guard, Class<?> varArgType, String optional, GuardCheckType guardCheckType) {
|
||||
this.typeMapper = typeMapper;
|
||||
this.guard = guard;
|
||||
@ -100,13 +106,17 @@ public class CommandPart {
|
||||
throw new CommandParseException();
|
||||
}
|
||||
if (!validArgument.success) {
|
||||
if (!ignoreAsArgument) {
|
||||
current.add(typeMapper.map(commandSender, EMPTY_ARRAY, optional));
|
||||
}
|
||||
if (next != null) {
|
||||
next.generateArgumentArray(current, commandSender, args, startIndex);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!ignoreAsArgument) {
|
||||
current.add(validArgument.value);
|
||||
}
|
||||
if (next != null) {
|
||||
next.generateArgumentArray(current, commandSender, args, startIndex + 1);
|
||||
}
|
||||
|
@ -113,13 +113,18 @@ public class SWCommandUtils {
|
||||
}
|
||||
|
||||
static CommandPart generateCommandPart(boolean help, String[] subCommand, Parameter[] parameters, Map<String, TypeMapper<?>> localTypeMapper, Map<String, GuardChecker> localGuardChecker) {
|
||||
CommandPart first = null;
|
||||
CommandPart current = null;
|
||||
for (String s : subCommand) {
|
||||
CommandPart commandPart = new CommandPart(createMapper(s), null, null, null, help ? GuardCheckType.HELP_COMMAND : GuardCheckType.COMMAND);
|
||||
commandPart.setIgnoreAsArgument(true);
|
||||
if (current != null) {
|
||||
current.setNext(commandPart);
|
||||
}
|
||||
current = commandPart;
|
||||
if (first == null) {
|
||||
first = current;
|
||||
}
|
||||
}
|
||||
for (int i = 1; i < parameters.length; i++) {
|
||||
Parameter parameter = parameters[i];
|
||||
@ -133,8 +138,11 @@ public class SWCommandUtils {
|
||||
current.setNext(commandPart);
|
||||
}
|
||||
current = commandPart;
|
||||
if (first == null) {
|
||||
first = current;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
static TypeMapper<?> getTypeMapper(Parameter parameter, Map<String, TypeMapper<?>> localTypeMapper) {
|
||||
|
@ -89,7 +89,6 @@ class SubCommand {
|
||||
}
|
||||
}
|
||||
commandPart.guardCheck(commandSender, args, 0);
|
||||
for (int i = 0; i < subCommand.length; i++) objects.remove(0);
|
||||
objects.add(0, commandSenderFunction.apply(commandSender));
|
||||
method.setAccessible(true);
|
||||
method.invoke(swCommand, objects.toArray());
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren