Make sure unit tests actually run(!) and fix command hints

This commit is contained in:
Andrew Steinborn
2020-12-14 14:39:39 -05:00
parent 4f5c315ef8
commit 523b61e0c7
6 changed files with 40 additions and 23 deletions

View File

@@ -102,11 +102,8 @@ public class VelocityCommandManager implements CommandManager {
}
if (!(command instanceof BrigadierCommand)) {
if (!meta.getHints().isEmpty()) {
// If the user specified a hint, then add the hints to the command node directly.
for (CommandNode<CommandSource> hint : meta.getHints()) {
node.addChild(hint);
}
for (CommandNode<CommandSource> hint : meta.getHints()) {
node.addChild(BrigadierUtils.wrapForHinting(hint, node.getCommand()));
}
}

View File

@@ -1,8 +1,10 @@
package com.velocitypowered.proxy.util;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
@@ -11,6 +13,7 @@ import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.CommandSource;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Provides utilities for working with Brigadier commands.
@@ -124,6 +127,25 @@ public final class BrigadierUtils {
return command.toLowerCase(Locale.ENGLISH);
}
/**
* Prepares the given command node prior for hinting metadata to
* a {@link com.velocitypowered.api.command.Command}.
*
* @param node the command node to be wrapped
* @param command the command to execute
* @return the wrapped command node
*/
public static CommandNode<CommandSource> wrapForHinting(
final CommandNode<CommandSource> node, final @Nullable Command<CommandSource> command) {
Preconditions.checkNotNull(node, "node");
ArgumentBuilder<CommandSource, ?> builder = node.createBuilder();
builder.executes(command);
for (CommandNode<CommandSource> child : node.getChildren()) {
builder.then(wrapForHinting(child, command));
}
return builder.build();
}
private BrigadierUtils() {
throw new AssertionError();
}