diff --git a/docs/scarpet/api/Overview.md b/docs/scarpet/api/Overview.md index efdb6b6b..e4979462 100644 --- a/docs/scarpet/api/Overview.md +++ b/docs/scarpet/api/Overview.md @@ -188,7 +188,7 @@ baz(entities) -> // same thing ``` It works similarly to the auto command, but arguments get their inferred types based on the argument -names, looking at the full name, or the suffix after the last `_` that indicates the variable type. For instance, variable named `float` will +names, looking at the full name, or any suffix when splitting on `_` that indicates the variable type. For instance, variable named `float` will be parsed as a floating point number, but it can be named `'first_float'` or `'other_float'` as well. Any variable that is not supported, will be parsed as a `'string'` type. @@ -253,8 +253,14 @@ and less frequently used features, like forks and redirects, used pretty much on ### Command argument types -There are several default argument types that can be used directly without specifying custom types. Each argument can be -customized in the `'arguments'` section of the app config, specifying its base type, via `'type'` that needs +Argument types differ from actual argument names that the types are the suffixes of the used argument names, when separated with +`'_'` symbol. For example argument name `'from_pos'` will be interpreted as a built-in type `'int'` and provided to the command system +as a name `'from_pos'`, however if you define a custom type `'from_pos'`, your custom type will be used instead. +Longer suffixes take priority over shorter prefixes, then user defined suffixes mask build-in prefixes. + +There are several default argument types that can be used directly without specifying custom types. + +Each argument can be customized in the `'arguments'` section of the app config, specifying its base type, via `'type'` that needs to match any of the built-in types, with a series of optional modifiers. Shared modifiers include: * `suggest` - static list of suggestions to show above the command while typing * `suggester` - function taking one map argument, indicating current state of attributes in the parsed command diff --git a/src/main/java/carpet/script/command/CommandArgument.java b/src/main/java/carpet/script/command/CommandArgument.java index 1bb705b7..1a406c3c 100644 --- a/src/main/java/carpet/script/command/CommandArgument.java +++ b/src/main/java/carpet/script/command/CommandArgument.java @@ -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 argumentNode(String param, CarpetScriptHost host) throws CommandSyntaxException