From 9c93292461a8635b441af96dbf98064b2c9ea245 Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Mon, 19 Dec 2022 09:42:34 +0000 Subject: [PATCH] Hotfix #310 for 8.7.1 --- .../dev/jorel/commandapi/CommandAPIHandler.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java index 6a7c42e512..1100a54ed9 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java @@ -129,9 +129,18 @@ public class CommandAPIHandler { */ public static String getRawArgumentInput(CommandContext cmdCtx, String key) { - StringRange range = ((Map>) COMMANDCONTEXT_ARGUMENTS.get(cmdCtx)) - .get(key).getRange(); - return cmdCtx.getInput().substring(range.getStart(), range.getEnd()); + final Map> commandContextArgs = (Map>) COMMANDCONTEXT_ARGUMENTS.get(cmdCtx); + final ParsedArgument parsedArgument = commandContextArgs.get(key); + + // TODO: Issue #310: Parsing this argument via /execute run doesn't have the value in + // the arguments for this command context (most likely because it's a redirected command). + // We need to figure out how to handle this case. + if(parsedArgument != null) { + StringRange range = parsedArgument.getRange(); + return cmdCtx.getInput().substring(range.getStart(), range.getEnd()); + } else { + return ""; + } } private static CommandAPIHandler instance;