From 86ce3982246af98ee09199b1fc972b05ee21a0fc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 9 Dec 2021 22:52:30 +0100 Subject: [PATCH] Fix SubCommand --- .../src/de/steamwar/command/CommandPart.java | 14 ++++++++++++-- .../src/de/steamwar/command/SWCommandUtils.java | 10 +++++++++- .../src/de/steamwar/command/SubCommand.java | 1 - 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/CommandPart.java b/SpigotCore_Main/src/de/steamwar/command/CommandPart.java index e6dbf8c..666d516 100644 --- a/SpigotCore_Main/src/de/steamwar/command/CommandPart.java +++ b/SpigotCore_Main/src/de/steamwar/command/CommandPart.java @@ -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); } diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index 7de8407..8e43884 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -113,13 +113,18 @@ public class SWCommandUtils { } static CommandPart generateCommandPart(boolean help, String[] subCommand, Parameter[] parameters, Map> localTypeMapper, Map 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> localTypeMapper) { diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index 4b66771..7eade15 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -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());