SteamWar/SpigotCore
Archiviert
13
0

Fix SubCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2021-12-09 22:52:30 +01:00
Ursprung 2f331e169a
Commit 86ce398224
3 geänderte Dateien mit 21 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -20,12 +20,15 @@
package de.steamwar.command; package de.steamwar.command;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ToString
public class CommandPart { public class CommandPart {
private static final String[] EMPTY_ARRAY = new String[0]; private static final String[] EMPTY_ARRAY = new String[0];
@ -43,6 +46,9 @@ public class CommandPart {
private CommandPart next = null; private CommandPart next = null;
@Setter
private boolean ignoreAsArgument = false;
public CommandPart(TypeMapper<?> typeMapper, GuardChecker guard, Class<?> varArgType, String optional, GuardCheckType guardCheckType) { public CommandPart(TypeMapper<?> typeMapper, GuardChecker guard, Class<?> varArgType, String optional, GuardCheckType guardCheckType) {
this.typeMapper = typeMapper; this.typeMapper = typeMapper;
this.guard = guard; this.guard = guard;
@ -100,13 +106,17 @@ public class CommandPart {
throw new CommandParseException(); throw new CommandParseException();
} }
if (!validArgument.success) { if (!validArgument.success) {
current.add(typeMapper.map(commandSender, EMPTY_ARRAY, optional)); if (!ignoreAsArgument) {
current.add(typeMapper.map(commandSender, EMPTY_ARRAY, optional));
}
if (next != null) { if (next != null) {
next.generateArgumentArray(current, commandSender, args, startIndex); next.generateArgumentArray(current, commandSender, args, startIndex);
} }
return; return;
} }
current.add(validArgument.value); if (!ignoreAsArgument) {
current.add(validArgument.value);
}
if (next != null) { if (next != null) {
next.generateArgumentArray(current, commandSender, args, startIndex + 1); 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) { static CommandPart generateCommandPart(boolean help, String[] subCommand, Parameter[] parameters, Map<String, TypeMapper<?>> localTypeMapper, Map<String, GuardChecker> localGuardChecker) {
CommandPart first = null;
CommandPart current = null; CommandPart current = null;
for (String s : subCommand) { for (String s : subCommand) {
CommandPart commandPart = new CommandPart(createMapper(s), null, null, null, help ? GuardCheckType.HELP_COMMAND : GuardCheckType.COMMAND); CommandPart commandPart = new CommandPart(createMapper(s), null, null, null, help ? GuardCheckType.HELP_COMMAND : GuardCheckType.COMMAND);
commandPart.setIgnoreAsArgument(true);
if (current != null) { if (current != null) {
current.setNext(commandPart); current.setNext(commandPart);
} }
current = commandPart; current = commandPart;
if (first == null) {
first = current;
}
} }
for (int i = 1; i < parameters.length; i++) { for (int i = 1; i < parameters.length; i++) {
Parameter parameter = parameters[i]; Parameter parameter = parameters[i];
@ -133,8 +138,11 @@ public class SWCommandUtils {
current.setNext(commandPart); current.setNext(commandPart);
} }
current = commandPart; current = commandPart;
if (first == null) {
first = current;
}
} }
return current; return first;
} }
static TypeMapper<?> getTypeMapper(Parameter parameter, Map<String, TypeMapper<?>> localTypeMapper) { static TypeMapper<?> getTypeMapper(Parameter parameter, Map<String, TypeMapper<?>> localTypeMapper) {

Datei anzeigen

@ -89,7 +89,6 @@ class SubCommand {
} }
} }
commandPart.guardCheck(commandSender, args, 0); commandPart.guardCheck(commandSender, args, 0);
for (int i = 0; i < subCommand.length; i++) objects.remove(0);
objects.add(0, commandSenderFunction.apply(commandSender)); objects.add(0, commandSenderFunction.apply(commandSender));
method.setAccessible(true); method.setAccessible(true);
method.invoke(swCommand, objects.toArray()); method.invoke(swCommand, objects.toArray());