use of com.mojang.brigadier.builder.RequiredArgumentBuilder in project BungeeCord by SpigotMC.
the class Commands method read.
@Override
public void read(ByteBuf buf) {
int nodeCount = readVarInt(buf);
NetworkNode[] nodes = new NetworkNode[nodeCount];
Deque<NetworkNode> nodeQueue = new ArrayDeque<>(nodes.length);
for (int i = 0; i < nodeCount; i++) {
byte flags = buf.readByte();
int[] children = readVarIntArray(buf);
int redirectNode = ((flags & FLAG_REDIRECT) != 0) ? readVarInt(buf) : 0;
ArgumentBuilder argumentBuilder;
switch(flags & FLAG_TYPE) {
case NODE_ROOT:
argumentBuilder = null;
break;
case NODE_LITERAL:
argumentBuilder = LiteralArgumentBuilder.literal(readString(buf));
break;
case NODE_ARGUMENT:
String name = readString(buf);
String parser = readString(buf);
argumentBuilder = RequiredArgumentBuilder.argument(name, ArgumentRegistry.read(parser, buf));
if ((flags & FLAG_SUGGESTIONS) != 0) {
String suggster = readString(buf);
((RequiredArgumentBuilder) argumentBuilder).suggests(SuggestionRegistry.getProvider(suggster));
}
break;
default:
throw new IllegalArgumentException("Unhandled node type " + flags);
}
NetworkNode node = new NetworkNode(argumentBuilder, flags, redirectNode, children);
nodes[i] = node;
nodeQueue.add(node);
}
boolean mustCycle;
do {
if (nodeQueue.isEmpty()) {
int rootIndex = readVarInt(buf);
root = (RootCommandNode<?>) nodes[rootIndex].command;
return;
}
mustCycle = false;
for (Iterator<NetworkNode> iter = nodeQueue.iterator(); iter.hasNext(); ) {
NetworkNode node = iter.next();
if (node.buildSelf(nodes)) {
iter.remove();
mustCycle = true;
}
}
} while (mustCycle);
throw new IllegalStateException("Did not finish building root node");
}
Aggregations