SteamWar/SpigotCore
Archiviert
13
0

CMD #141

Zusammengeführt
YoyoNow hat 29 Commits von CMD nach master 2021-12-12 15:58:20 +01:00 zusammengeführt
3 geänderte Dateien mit 21 neuen und 4 gelöschten Zeilen
Nur Änderungen aus Commit 86ce398224 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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) {
current.add(typeMapper.map(commandSender, EMPTY_ARRAY, optional));
if (!ignoreAsArgument) {
current.add(typeMapper.map(commandSender, EMPTY_ARRAY, optional));
}
if (next != null) {
next.generateArgumentArray(current, commandSender, args, startIndex);
}
return;
}
current.add(validArgument.value);
if (!ignoreAsArgument) {
current.add(validArgument.value);
}
if (next != null) {
next.generateArgumentArray(current, commandSender, args, startIndex + 1);
}

Datei anzeigen

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

Datei anzeigen

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