diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index da927ad..0d09c7f 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -100,7 +100,7 @@ public class SWCommandUtils { } } - static Object[] generateArgumentArray(TypeMapper[] parameters, String[] args, Class varArgType, String[] subCommand) throws CommandParseException { + static Object[] generateArgumentArray(CommandSender commandSender, TypeMapper[] parameters, String[] args, Class varArgType, String[] subCommand) throws CommandParseException { Object[] arguments = new Object[parameters.length + 1]; int index = 0; while (index < subCommand.length) { @@ -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(Arrays.copyOf(args, index), args[index]); + arguments[i + 1] = parameters[i].map(commandSender, Arrays.copyOf(args, index), 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(Arrays.copyOf(args, index), args[index]); + Object value = parameters[parameters.length - 1].map(commandSender, Arrays.copyOf(args, index), 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[] previous, String s) { + public T map(CommandSender commandSender, String[] previousArguments, 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 343cbd0..b7a414b 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -88,7 +88,7 @@ class SubCommand { return false; } try { - Object[] objects = SWCommandUtils.generateArgumentArray(arguments, args, varArgType, subCommand); + Object[] objects = SWCommandUtils.generateArgumentArray(commandSender, arguments, args, varArgType, subCommand); objects[0] = commandSenderFunction.apply(commandSender); method.setAccessible(true); method.invoke(swCommand, objects); @@ -116,7 +116,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(Arrays.copyOf(args, index), s) == null) { + if (argument.map(commandSender, Arrays.copyOf(args, index), s) == null) { return null; } } catch (Exception e) { @@ -129,7 +129,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(Arrays.copyOf(args, index), s) == null) { + if (arguments[arguments.length - 1].map(commandSender, Arrays.copyOf(args, index), 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 27b04f7..c0c160c 100644 --- a/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java +++ b/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java @@ -24,7 +24,15 @@ import org.bukkit.command.CommandSender; import java.util.List; public interface TypeMapper { - T map(String[] previousArguments, String s); + default T map(CommandSender commandSender, String[] previousArguments, String s) { + return map(previousArguments, s); + } + + // For backwards compatibility, can be removed later on + @Deprecated(since = "Use the other map Function without calling super!") + default T map(String[] previousArguments, String s) { + throw new SecurityException(); + } List tabCompletes(CommandSender commandSender, String[] previousArguments, String s); }