more flexible dealing with custom argument types, allowing _ in custom types. Fixes #936

This commit is contained in:
gnembon committed 2021-06-23 13:36:14 -03:00
1 parent 979032688d
commit 85d60b283f
2 files changed
+19 -7

No files matched your search

@@ -269,10 +269,16 @@ public abstract class CommandArgument
public static CommandArgument getTypeForArgument(String argument, CarpetScriptHost host)
{
String[] components = argument.split("_");
String suffix = components[components.length-1];
CommandArgument arg = host.appArgTypes.get(suffix);
if (arg != null) return arg;
return builtIns.getOrDefault(suffix, DEFAULT);
CommandArgument arg;
for (int i = 0; i < components.length; i++)
{
String candidate = String.join("_", Arrays.asList(components).subList(i, components.length));
arg = host.appArgTypes.get(candidate);
if (arg != null) return arg;
arg = builtIns.get(candidate);
if (arg != null) return arg;
}
return DEFAULT;
}
public static RequiredArgumentBuilder<ServerCommandSource, ?> argumentNode(String param, CarpetScriptHost host) throws CommandSyntaxException