Optimized execute method, version 0.1.16
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ import groovy.io.FileType
|
|||||||
apply plugin: 'java-library'
|
apply plugin: 'java-library'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|
||||||
version = '0.1.15'
|
version = '0.1.16'
|
||||||
group = 'com.mojang'
|
group = 'com.mojang'
|
||||||
|
|
||||||
task wrapper(type: Wrapper) {
|
task wrapper(type: Wrapper) {
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ import com.mojang.brigadier.tree.CommandNode;
|
|||||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
import com.mojang.brigadier.tree.RootCommandNode;
|
import com.mojang.brigadier.tree.RootCommandNode;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Deque;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -91,26 +90,37 @@ public class CommandDispatcher<S> {
|
|||||||
int successfulForks = 0;
|
int successfulForks = 0;
|
||||||
boolean forked = false;
|
boolean forked = false;
|
||||||
boolean foundCommand = false;
|
boolean foundCommand = false;
|
||||||
final Deque<CommandContext<S>> contexts = new ArrayDeque<>(8);
|
|
||||||
final String command = parse.getReader().getString();
|
final String command = parse.getReader().getString();
|
||||||
contexts.add(parse.getContext().build(command));
|
final CommandContext<S> original = parse.getContext().build(command);
|
||||||
|
List<CommandContext<S>> contexts = Collections.singletonList(original);
|
||||||
|
ArrayList<CommandContext<S>> next = null;
|
||||||
|
|
||||||
while (!contexts.isEmpty()) {
|
while (contexts != null) {
|
||||||
final CommandContext<S> context = contexts.removeFirst();
|
final int size = contexts.size();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
final CommandContext<S> context = contexts.get(i);
|
||||||
final CommandContext<S> child = context.getChild();
|
final CommandContext<S> child = context.getChild();
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
if (!child.getNodes().isEmpty()) {
|
if (!child.getNodes().isEmpty()) {
|
||||||
foundCommand = true;
|
foundCommand = true;
|
||||||
final RedirectModifier<S> modifier = context.getRedirectModifier();
|
final RedirectModifier<S> modifier = context.getRedirectModifier();
|
||||||
if (modifier == null) {
|
if (modifier == null) {
|
||||||
contexts.add(child);
|
if (next == null) {
|
||||||
|
next = new ArrayList<>(1);
|
||||||
|
}
|
||||||
|
next.add(child);
|
||||||
} else {
|
} else {
|
||||||
final Collection<S> results = modifier.apply(context);
|
final Collection<S> results = modifier.apply(context);
|
||||||
|
if (!results.isEmpty()) {
|
||||||
if (results.size() > 1) {
|
if (results.size() > 1) {
|
||||||
forked = true;
|
forked = true;
|
||||||
}
|
}
|
||||||
|
if (next == null) {
|
||||||
|
next = new ArrayList<>(results.size());
|
||||||
|
}
|
||||||
for (final S source : results) {
|
for (final S source : results) {
|
||||||
contexts.add(child.copyFor(source));
|
next.add(child.copyFor(source));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,8 +140,12 @@ public class CommandDispatcher<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contexts = next;
|
||||||
|
next = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!foundCommand) {
|
if (!foundCommand) {
|
||||||
consumer.onCommandComplete(parse.getContext().build(command), false, 0);
|
consumer.onCommandComplete(original, false, 0);
|
||||||
throw ERROR_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
throw ERROR_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user