Merge branch 'master' into 1.17

This commit is contained in:
gnembon committed 2021-06-23 13:37:29 -03:00
commit 8314072f9d
3 files changed
+28 -8

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
@@ -9,6 +9,7 @@ import net.minecraft.server.command.ServerCommandSource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
@@ -46,10 +47,17 @@ public class CommandToken implements Comparable<CommandToken>
spec = spec.trim();
if (spec.isEmpty()) return Collections.emptyList();
List<CommandToken> elements = new ArrayList<>();
HashSet<String> seenArgs = new HashSet<>();
for (String el: spec.split("\\s+"))
{
CommandToken tok = CommandToken.getToken(el, host);
if (tok == null) throw CommandArgument.error("Unrecognized command token: "+ el);
if (tok.isArgument)
{
if (seenArgs.contains(tok.surface))
throw CommandArgument.error("Repeated command argument: "+tok.surface+", for '"+spec+"'. Argument names have to be unique");
seenArgs.add(tok.surface);
}
elements.add(tok);
}
return elements;