diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java index 74c7a80..ff21301 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -171,7 +171,7 @@ public class CommandDispatcher { private ParseResults parseNodes(final CommandNode node, final StringReader originalReader, final CommandContextBuilder contextSoFar) { final S source = contextSoFar.getSource(); Map, CommandSyntaxException> errors = null; - final List> potentials = Lists.newArrayList(); + List> potentials = null; final int cursor = originalReader.getCursor(); for (final CommandNode child : node.getRelevantNodes(originalReader)) { @@ -211,18 +211,22 @@ public class CommandDispatcher { return new ParseResults<>(context, parse.getReader(), parse.getExceptions()); } else { final ParseResults parse = parseNodes(child, reader, context); + if (potentials == null) { + potentials = new ArrayList<>(1); + } potentials.add(new PartialParse<>(context, parse)); } } else { + if (potentials == null) { + potentials = new ArrayList<>(1); + } potentials.add(new PartialParse<>(context, new ParseResults<>(context, reader, Collections.emptyMap()))); } } - if (!potentials.isEmpty()) { - final PartialParse likely; + if (potentials != null) { if (potentials.size() > 1) { - final List> sorted = Lists.newArrayList(potentials); - sorted.sort((a, b) -> { + potentials.sort((a, b) -> { if (!a.parse.getReader().canRead() && b.parse.getReader().canRead()) { return -1; } @@ -237,11 +241,8 @@ public class CommandDispatcher { } return 0; }); - likely = sorted.get(0); - } else { - likely = potentials.get(0); } - return likely.parse; + return potentials.get(0).parse; } return new ParseResults<>(contextSoFar, originalReader, errors == null ? Collections.emptyMap() : errors);