From 25d72ab3764d7be7b65c9b8c9e763cc92f152ed0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 30 Mar 2021 17:26:43 +0200 Subject: [PATCH] Add more TypeMapper capabilities --- SpigotCore_Main/src/de/steamwar/acommand/TestCommand.java | 4 ++-- SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java | 6 +++--- SpigotCore_Main/src/de/steamwar/command/SubCommand.java | 4 ++-- SpigotCore_Main/src/de/steamwar/command/TypeMapper.java | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/acommand/TestCommand.java b/SpigotCore_Main/src/de/steamwar/acommand/TestCommand.java index 50901f1..8444aba 100644 --- a/SpigotCore_Main/src/de/steamwar/acommand/TestCommand.java +++ b/SpigotCore_Main/src/de/steamwar/acommand/TestCommand.java @@ -37,7 +37,7 @@ 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 were tried to map + // The second argument can only be a varArgs string of what arguments were tried to map @Register(help = true) public void testHelp(Player player, String... args) { player.sendMessage("This is your help message"); @@ -68,7 +68,7 @@ public class TestCommand extends SWCommand { .collect(Collectors.toList()); return new TypeMapper() { @Override - public Material map(String s) { + public Material map(String[] previous, String s) { return Material.valueOf(s.toUpperCase()); } diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index f44b891..a4c678d 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -115,7 +115,7 @@ public class SWCommandUtils { arguments[arguments.length - 1] = varArgument; } else { for (int i = 0; i < parameters.length - (varArgType != null ? 1 : 0); i++) { - arguments[i + 1] = parameters[i].map(args[index]); + arguments[i + 1] = parameters[i].map(Arrays.copyOf(args, Math.min(index - 1, 0)), args[index]); index++; if (arguments[i + 1] == null) { throw new CommandParseException(); @@ -128,7 +128,7 @@ public class SWCommandUtils { arguments[arguments.length - 1] = varArgument; for (int i = 0; i < length; i++) { - Object value = parameters[parameters.length - 1].map(args[index]); + Object value = parameters[parameters.length - 1].map(Arrays.copyOf(args, Math.min(index - 1, 0)), args[index]); if (value == null) { throw new CommandParseException(); } @@ -156,7 +156,7 @@ public class SWCommandUtils { public static TypeMapper createMapper(Function mapper, BiFunction> tabCompleter) { return new TypeMapper() { @Override - public T map(String s) { + public T map(String[] previous, String s) { return mapper.apply(s); } diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index 4742ff2..1ce4c11 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -114,7 +114,7 @@ class SubCommand { String s = argsList.remove(0); if (argsList.isEmpty()) return argument.tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s); try { - if (argument.map(s) == null) { + if (argument.map(Arrays.copyOf(args, argsList.size()), s) == null) { return null; } } catch (Exception e) { @@ -126,7 +126,7 @@ class SubCommand { String s = argsList.remove(0); if (argsList.isEmpty()) return arguments[arguments.length - 1].tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s); try { - if (arguments[arguments.length - 1].map(s) == null) { + if (arguments[arguments.length - 1].map(Arrays.copyOf(args, argsList.size()), s) == null) { return null; } } catch (Exception e) { diff --git a/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java b/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java index 90dbf1e..27b04f7 100644 --- a/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java +++ b/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java @@ -24,7 +24,7 @@ import org.bukkit.command.CommandSender; import java.util.List; public interface TypeMapper { - T map(String s); + T map(String[] previousArguments, String s); List tabCompletes(CommandSender commandSender, String[] previousArguments, String s); }