diff --git a/api/build.gradle b/api/build.gradle index 74a20130c..a02f510b9 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -98,6 +98,10 @@ javadoc { options.source = '8' } +test { + useJUnitPlatform() +} + publishing { publications { mavenJava(MavenPublication) { diff --git a/native/build.gradle b/native/build.gradle index 0a348523f..b5b260486 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -21,6 +21,10 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" } +test { + useJUnitPlatform() +} + publishing { publications { mavenJava(MavenPublication) { diff --git a/proxy/build.gradle b/proxy/build.gradle index f703a5749..1ed87838e 100644 --- a/proxy/build.gradle +++ b/proxy/build.gradle @@ -81,6 +81,10 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" } +test { + useJUnitPlatform() +} + shadowJar { exclude 'it/unimi/dsi/fastutil/booleans/**' exclude 'it/unimi/dsi/fastutil/bytes/**' diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java index 4165c0afa..f8adfc2e9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -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 hint : meta.getHints()) { - node.addChild(hint); - } + for (CommandNode hint : meta.getHints()) { + node.addChild(BrigadierUtils.wrapForHinting(hint, node.getCommand())); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/BrigadierUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/BrigadierUtils.java index 1bad01978..73bf67f84 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/BrigadierUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/BrigadierUtils.java @@ -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 wrapForHinting( + final CommandNode node, final @Nullable Command command) { + Preconditions.checkNotNull(node, "node"); + ArgumentBuilder builder = node.createBuilder(); + builder.executes(command); + for (CommandNode child : node.getChildren()) { + builder.then(wrapForHinting(child, command)); + } + return builder.build(); + } + private BrigadierUtils() { throw new AssertionError(); } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java index ef2bf022f..d5dc457a9 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java @@ -122,20 +122,6 @@ public class CommandManagerTests { assertTrue(manager.hasCommand("foO")); } - @Test - void testAlreadyRegisteredThrows() { - VelocityCommandManager manager = createManager(); - manager.register("bar", new NoopDeprecatedCommand()); - assertThrows(IllegalArgumentException.class, () -> - manager.register("BAR", new NoopSimpleCommand())); - assertThrows(IllegalArgumentException.class, () -> { - CommandMeta meta = manager.metaBuilder("baz") - .aliases("BAr") - .build(); - manager.register(meta, new NoopRawCommand()); - }); - } - @Test void testBrigadierExecute() { VelocityCommandManager manager = createManager(); @@ -181,9 +167,9 @@ public class CommandManagerTests { assertTrue(manager.executeImmediatelyAsync(MockCommandSource.INSTANCE, "buy 14").join()); assertTrue(checkedRequires.compareAndSet(true, false)); assertTrue(executed.get()); - assertFalse(manager.execute(MockCommandSource.INSTANCE, "buy 9"), + assertTrue(manager.execute(MockCommandSource.INSTANCE, "buy 9"), "Invalid arg returns false"); - assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "buy 12 bananas")); + assertTrue(manager.executeImmediately(MockCommandSource.INSTANCE, "buy 12 bananas")); assertTrue(checkedRequires.get()); } @@ -392,7 +378,7 @@ public class CommandManagerTests { .join().isEmpty()); assertEquals( ImmutableList.of("123"), - manager.offerSuggestions(MockCommandSource.INSTANCE, "simPle foo ").join()); + manager.offerSuggestions(MockCommandSource.INSTANCE, "simPle foo").join()); assertEquals( ImmutableList.of("baz", "foo"), manager.offerSuggestions(MockCommandSource.INSTANCE, "raw ").join()); @@ -411,7 +397,7 @@ public class CommandManagerTests { .join().isEmpty()); assertEquals( ImmutableList.of("123", "456"), - manager.offerSuggestions(MockCommandSource.INSTANCE, "deprEcated foo ").join()); + manager.offerSuggestions(MockCommandSource.INSTANCE, "deprEcated foo").join()); assertTrue(manager.offerSuggestions(MockCommandSource.INSTANCE, "deprecated foo 789 ") .join().isEmpty()); }