scarpet app command system will warn on repeated arguments. Fixes #935
This commit is contained in:
1 parent
a77fc5c2f5
commit
6b2577d3b4
1 file changed
+8
@@ -9,6 +9,7 @@ import net.minecraft.server.command.ServerCommandSource;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -46,10 +47,17 @@ public class CommandToken implements Comparable<CommandToken>
|
|||||||
spec = spec.trim();
|
spec = spec.trim();
|
||||||
if (spec.isEmpty()) return Collections.emptyList();
|
if (spec.isEmpty()) return Collections.emptyList();
|
||||||
List<CommandToken> elements = new ArrayList<>();
|
List<CommandToken> elements = new ArrayList<>();
|
||||||
|
HashSet<String> seenArgs = new HashSet<>();
|
||||||
for (String el: spec.split("\\s+"))
|
for (String el: spec.split("\\s+"))
|
||||||
{
|
{
|
||||||
CommandToken tok = CommandToken.getToken(el, host);
|
CommandToken tok = CommandToken.getToken(el, host);
|
||||||
if (tok == null) throw CommandArgument.error("Unrecognized command token: "+ el);
|
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);
|
elements.add(tok);
|
||||||
}
|
}
|
||||||
return elements;
|
return elements;
|
||||||
|
|||||||
Reference in new issue
Block a user