From 2ffe95dc0f0fd85443787f6c8141376f2842d081 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Sat, 27 Dec 2025 00:08:49 +0200 Subject: [PATCH] Fixed parameters being resolved as args --- .../script/interpreter/ScriptDocument.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java index d0c0730b1..b278efe11 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java @@ -1574,7 +1574,8 @@ public class ScriptDocument { } // Try to resolve the argument type - TypeInfo argType = resolveExpressionType(argText, actualStart); + // First check if this looks like a parameter declaration (Type varName) + TypeInfo argType = resolveArgumentType(argText, actualStart); args.add(new MethodCallInfo.Argument( argText, actualStart, actualEnd, argType, true, null @@ -1607,6 +1608,35 @@ public class ScriptDocument { return args; } + /** + * Resolve the type of a method call argument. + * Handles both parameter declarations (Type varName) and expressions (variable.field()). + */ + private TypeInfo resolveArgumentType(String argText, int position) { + argText = argText.trim(); + + // Check if this looks like a parameter declaration: "Type varName" + // Pattern: identifier followed by whitespace and another identifier + if (argText.matches("^[A-Za-z_][a-zA-Z0-9_<>\\[\\],\\s]*\\s+[a-zA-Z_][a-zA-Z0-9_]*$")) { + // Split into tokens + String[] parts = argText.split("\\s+"); + if (parts.length >= 2) { + // Last part is the variable name, everything before is the type + // Join all but last as the type name + StringBuilder typeBuilder = new StringBuilder(); + for (int i = 0; i < parts.length - 1; i++) { + if (i > 0) typeBuilder.append(" "); + typeBuilder.append(parts[i]); + } + String typeName = typeBuilder.toString(); + return resolveType(typeName); + } + } + + // Otherwise, treat it as an expression + return resolveExpressionType(argText, position); + } + /** * Comprehensive expression type resolver that handles: * - Literals (strings, numbers, booleans, null)