3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Fix cherry-picking issues

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-07-12 09:13:12 -04:00
Ursprung 009abe4cd3
Commit aab8f86aa8
13 geänderte Dateien mit 72 neuen und 56 gelöschten Zeilen

Datei anzeigen

@ -39,7 +39,9 @@ public final class StringArrayArgumentType implements ArgumentType<String[]> {
Splitter.on(CommandDispatcher.ARGUMENT_SEPARATOR_CHAR); Splitter.on(CommandDispatcher.ARGUMENT_SEPARATOR_CHAR);
private static final List<String> EXAMPLES = Arrays.asList("word", "some words"); private static final List<String> EXAMPLES = Arrays.asList("word", "some words");
private StringArrayArgumentType() {} private StringArrayArgumentType() {
}
@Override @Override
public String[] parse(final StringReader reader) throws CommandSyntaxException { public String[] parse(final StringReader reader) throws CommandSyntaxException {

Datei anzeigen

@ -52,7 +52,7 @@ public final class VelocityArgumentBuilder<S, T>
private final String name; private final String name;
private final ArgumentType<T> type; private final ArgumentType<T> type;
private SuggestionProvider<S> suggestionsProvider = null; private @Nullable SuggestionProvider<S> suggestionsProvider = null;
private VelocityArgumentBuilder(final String name, final ArgumentType<T> type) { private VelocityArgumentBuilder(final String name, final ArgumentType<T> type) {
this.name = name; this.name = name;

Datei anzeigen

@ -38,6 +38,7 @@ import java.util.Collection;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.BiPredicate; import java.util.function.BiPredicate;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* An argument node that uses the given (possibly custom) {@link ArgumentType} * An argument node that uses the given (possibly custom) {@link ArgumentType}
@ -56,7 +57,7 @@ public class VelocityArgumentCommandNode<S, T> extends ArgumentCommandNode<S, St
final Predicate<S> requirement, final Predicate<S> requirement,
final BiPredicate<CommandContextBuilder<S>, ImmutableStringReader> contextRequirement, final BiPredicate<CommandContextBuilder<S>, ImmutableStringReader> contextRequirement,
final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks,
final SuggestionProvider<S> customSuggestions) { final @Nullable SuggestionProvider<S> customSuggestions) {
super(name, StringArgumentType.greedyString(), command, requirement, contextRequirement, super(name, StringArgumentType.greedyString(), command, requirement, contextRequirement,
redirect, modifier, forks, customSuggestions); redirect, modifier, forks, customSuggestions);
this.type = Preconditions.checkNotNull(type, "type"); this.type = Preconditions.checkNotNull(type, "type");

Datei anzeigen

@ -46,7 +46,7 @@ public final class BrigadierCommandRegistrar extends AbstractCommandRegistrar<Br
this.register(literal); this.register(literal);
} }
for (final String alias : meta.getAliases()) { for (final String alias : meta.aliases()) {
if (primaryAlias.equals(alias)) { if (primaryAlias.equals(alias)) {
continue; continue;
} }

Datei anzeigen

@ -57,7 +57,7 @@ abstract class InvocableCommandRegistrar<T extends InvocableCommand<I>,
@Override @Override
public void register(final CommandMeta meta, final T command) { public void register(final CommandMeta meta, final T command) {
final Iterator<String> aliases = meta.getAliases().iterator(); final Iterator<String> aliases = meta.aliases().iterator();
final String primaryAlias = aliases.next(); final String primaryAlias = aliases.next();
final LiteralCommandNode<CommandSource> literal = final LiteralCommandNode<CommandSource> literal =

Datei anzeigen

@ -205,7 +205,7 @@ public class BrigadierCommandTests extends CommandTestSuite {
manager.register(new BrigadierCommand(node)); manager.register(new BrigadierCommand(node));
final Exception wrapper = assertThrows(CompletionException.class, () -> final Exception wrapper = assertThrows(CompletionException.class, () ->
manager.executeAsync(source, "hello").join()); manager.execute(source, "hello").join());
assertSame(expected, wrapper.getCause().getCause()); assertSame(expected, wrapper.getCause().getCause());
} }
@ -223,7 +223,7 @@ public class BrigadierCommandTests extends CommandTestSuite {
manager.register(new BrigadierCommand(node)); manager.register(new BrigadierCommand(node));
final Exception wrapper = assertThrows(CompletionException.class, () -> final Exception wrapper = assertThrows(CompletionException.class, () ->
manager.executeAsync(source, "hello").join()); manager.execute(source, "hello").join());
assertSame(expected, wrapper.getCause().getCause()); assertSame(expected, wrapper.getCause().getCause());
} }

Datei anzeigen

@ -48,7 +48,7 @@ public class CommandGraphInjectorTests extends CommandTestSuite {
@Test @Test
void testInjectInvocableCommand() { void testInjectInvocableCommand() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, (SimpleCommand) invocation -> fail()); manager.register(meta, (SimpleCommand) invocation -> fail());
manager.getInjector().inject(dest, source); manager.getInjector().inject(dest, source);
@ -61,7 +61,7 @@ public class CommandGraphInjectorTests extends CommandTestSuite {
void testFiltersImpermissibleAlias() { void testFiltersImpermissibleAlias() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -88,7 +88,7 @@ public class CommandGraphInjectorTests extends CommandTestSuite {
final var hint = LiteralArgumentBuilder final var hint = LiteralArgumentBuilder
.<CommandSource>literal("hint") .<CommandSource>literal("hint")
.build(); .build();
final var meta = manager.metaBuilder("hello") final var meta = manager.createMetaBuilder("hello")
.hint(hint) .hint(hint)
.build(); .build();
manager.register(meta, (SimpleCommand) invocation -> fail()); manager.register(meta, (SimpleCommand) invocation -> fail());
@ -106,7 +106,7 @@ public class CommandGraphInjectorTests extends CommandTestSuite {
final var hint = LiteralArgumentBuilder final var hint = LiteralArgumentBuilder
.<CommandSource>literal("hint") .<CommandSource>literal("hint")
.build(); .build();
final var meta = manager.metaBuilder("hello") final var meta = manager.createMetaBuilder("hello")
.hint(hint) .hint(hint)
.build(); .build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {

Datei anzeigen

@ -166,7 +166,9 @@ public class CommandManagerTests extends CommandTestSuite {
static final DummyCommand INSTANCE = new DummyCommand(); static final DummyCommand INSTANCE = new DummyCommand();
private DummyCommand() {} private DummyCommand() {
}
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {

Datei anzeigen

@ -25,13 +25,14 @@ import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.proxy.event.MockEventManager; import com.velocitypowered.proxy.event.MockEventManager;
import com.velocitypowered.proxy.event.VelocityEventManager; import com.velocitypowered.proxy.event.VelocityEventManager;
import java.util.Arrays; import java.util.Arrays;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
abstract class CommandTestSuite { abstract class CommandTestSuite {
private static VelocityEventManager eventManager; private static @Nullable VelocityEventManager eventManager;
protected VelocityCommandManager manager; protected VelocityCommandManager manager;
protected final CommandSource source = MockCommandSource.INSTANCE; protected final CommandSource source = MockCommandSource.INSTANCE;
@ -44,6 +45,9 @@ abstract class CommandTestSuite {
@AfterAll @AfterAll
static void afterAll() { static void afterAll() {
try { try {
if (eventManager == null) {
throw new AssertionError("Event manager must exist");
}
eventManager.shutdown(); eventManager.shutdown();
eventManager = null; eventManager = null;
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
@ -53,6 +57,9 @@ abstract class CommandTestSuite {
@BeforeEach @BeforeEach
void setUp() { void setUp() {
if (eventManager == null) {
throw new AssertionError("Event manager must exist");
}
this.manager = new VelocityCommandManager(eventManager); this.manager = new VelocityCommandManager(eventManager);
} }

Datei anzeigen

@ -42,7 +42,7 @@ public class RawCommandTests extends CommandTestSuite {
void testExecuteAlias() { void testExecuteAlias() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, (RawCommand) invocation -> { manager.register(meta, (RawCommand) invocation -> {
assertEquals(source, invocation.source()); assertEquals(source, invocation.source());
assertEquals("hello", invocation.alias()); assertEquals("hello", invocation.alias());
@ -58,7 +58,7 @@ public class RawCommandTests extends CommandTestSuite {
void testExecuteIgnoresAliasCase() { void testExecuteIgnoresAliasCase() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, (RawCommand) invocation -> { manager.register(meta, (RawCommand) invocation -> {
assertEquals("hello", invocation.alias()); assertEquals("hello", invocation.alias());
callCount.incrementAndGet(); callCount.incrementAndGet();
@ -72,7 +72,7 @@ public class RawCommandTests extends CommandTestSuite {
void testExecuteInputIsTrimmed() { void testExecuteInputIsTrimmed() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, (RawCommand) invocation -> { manager.register(meta, (RawCommand) invocation -> {
assertEquals("hello", invocation.alias()); assertEquals("hello", invocation.alias());
assertEquals("", invocation.arguments()); assertEquals("", invocation.arguments());
@ -88,7 +88,7 @@ public class RawCommandTests extends CommandTestSuite {
@Test @Test
void testExecuteAfterUnregisterForwards() { void testExecuteAfterUnregisterForwards() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, (RawCommand) invocation -> fail()); manager.register(meta, (RawCommand) invocation -> fail());
manager.unregister("hello"); manager.unregister("hello");
@ -99,7 +99,7 @@ public class RawCommandTests extends CommandTestSuite {
void testForwardsAndDoesNotExecuteImpermissibleAlias() { void testForwardsAndDoesNotExecuteImpermissibleAlias() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -124,7 +124,7 @@ public class RawCommandTests extends CommandTestSuite {
void testExecutesWithArguments() { void testExecutesWithArguments() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, (RawCommand) invocation -> { manager.register(meta, (RawCommand) invocation -> {
assertEquals("hello", invocation.alias()); assertEquals("hello", invocation.alias());
assertEquals("dear world", invocation.arguments()); assertEquals("dear world", invocation.arguments());
@ -139,7 +139,7 @@ public class RawCommandTests extends CommandTestSuite {
void testHandlesAndDoesNotExecuteWithImpermissibleArgs() { void testHandlesAndDoesNotExecuteWithImpermissibleArgs() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("color").build(); final var meta = manager.createMetaBuilder("color").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -163,7 +163,7 @@ public class RawCommandTests extends CommandTestSuite {
@Test @Test
void testDoesNotSuggestAliasIfImpermissible() { void testDoesNotSuggestAliasIfImpermissible() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -186,7 +186,7 @@ public class RawCommandTests extends CommandTestSuite {
@Test @Test
void testDoesNotSuggestAliasAfterUnregister() { void testDoesNotSuggestAliasAfterUnregister() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -205,7 +205,7 @@ public class RawCommandTests extends CommandTestSuite {
@Test @Test
void testSuggestsArgumentsAfterAlias() { void testSuggestsArgumentsAfterAlias() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -225,7 +225,7 @@ public class RawCommandTests extends CommandTestSuite {
@Test @Test
void testSuggestsArgumentsAfterAliasIgnoresAliasCase() { void testSuggestsArgumentsAfterAliasIgnoresAliasCase() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -244,7 +244,7 @@ public class RawCommandTests extends CommandTestSuite {
@Test @Test
void testSuggestsArgumentsAfterPartialArguments() { void testSuggestsArgumentsAfterPartialArguments() {
final var meta = manager.metaBuilder("numbers").build(); final var meta = manager.createMetaBuilder("numbers").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -265,7 +265,7 @@ public class RawCommandTests extends CommandTestSuite {
void testDoesNotSuggestFirstArgumentIfImpermissibleAlias() { void testDoesNotSuggestFirstArgumentIfImpermissibleAlias() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -294,7 +294,7 @@ public class RawCommandTests extends CommandTestSuite {
void testDoesNotSuggestArgumentsAfterPartialImpermissibleArguments() { void testDoesNotSuggestArgumentsAfterPartialImpermissibleArguments() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("foo").build(); final var meta = manager.createMetaBuilder("foo").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -321,7 +321,7 @@ public class RawCommandTests extends CommandTestSuite {
@Test @Test
void testDoesNotSuggestIfFutureCompletesExceptionally() { void testDoesNotSuggestIfFutureCompletesExceptionally() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -339,7 +339,7 @@ public class RawCommandTests extends CommandTestSuite {
@Test @Test
void testDoesNotSuggestIfSuggestAsyncThrows() { void testDoesNotSuggestIfSuggestAsyncThrows() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -358,7 +358,7 @@ public class RawCommandTests extends CommandTestSuite {
@Test @Test
void testSuggestCompletesExceptionallyIfHasPermissionThrows() { void testSuggestCompletesExceptionallyIfHasPermissionThrows() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -389,7 +389,7 @@ public class RawCommandTests extends CommandTestSuite {
final var hint = LiteralArgumentBuilder final var hint = LiteralArgumentBuilder
.<CommandSource>literal("hint") .<CommandSource>literal("hint")
.build(); .build();
final var meta = manager.metaBuilder("hello") final var meta = manager.createMetaBuilder("hello")
.hint(hint) .hint(hint)
.build(); .build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@ -412,7 +412,7 @@ public class RawCommandTests extends CommandTestSuite {
final var hint = LiteralArgumentBuilder final var hint = LiteralArgumentBuilder
.<CommandSource>literal("hint") .<CommandSource>literal("hint")
.build(); .build();
final var meta = manager.metaBuilder("hello") final var meta = manager.createMetaBuilder("hello")
.hint(hint) .hint(hint)
.build(); .build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@ -436,7 +436,7 @@ public class RawCommandTests extends CommandTestSuite {
.<CommandSource, String>argument("hint", word()) .<CommandSource, String>argument("hint", word())
.suggests((context, builder) -> CompletableFuture.failedFuture(new RuntimeException())) .suggests((context, builder) -> CompletableFuture.failedFuture(new RuntimeException()))
.build(); .build();
final var meta = manager.metaBuilder("hello") final var meta = manager.createMetaBuilder("hello")
.hint(hint) .hint(hint)
.build(); .build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {
@ -462,7 +462,7 @@ public class RawCommandTests extends CommandTestSuite {
throw new RuntimeException(); throw new RuntimeException();
}) })
.build(); .build();
final var meta = manager.metaBuilder("hello") final var meta = manager.createMetaBuilder("hello")
.hint(hint) .hint(hint)
.build(); .build();
manager.register(meta, new RawCommand() { manager.register(meta, new RawCommand() {

Datei anzeigen

@ -43,7 +43,7 @@ public class SimpleCommandTests extends CommandTestSuite {
void testExecutesAlias() { void testExecutesAlias() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, (SimpleCommand) invocation -> { manager.register(meta, (SimpleCommand) invocation -> {
assertEquals(source, invocation.source()); assertEquals(source, invocation.source());
assertEquals("hello", invocation.alias()); assertEquals("hello", invocation.alias());
@ -59,7 +59,7 @@ public class SimpleCommandTests extends CommandTestSuite {
void testExecuteIgnoresAliasCase() { void testExecuteIgnoresAliasCase() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, (SimpleCommand) invocation -> { manager.register(meta, (SimpleCommand) invocation -> {
assertEquals("hello", invocation.alias()); assertEquals("hello", invocation.alias());
callCount.incrementAndGet(); callCount.incrementAndGet();
@ -73,7 +73,7 @@ public class SimpleCommandTests extends CommandTestSuite {
void testExecuteInputIsTrimmed() { void testExecuteInputIsTrimmed() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, (SimpleCommand) invocation -> { manager.register(meta, (SimpleCommand) invocation -> {
assertEquals("hello", invocation.alias()); assertEquals("hello", invocation.alias());
assertArrayEquals(new String[0], invocation.arguments()); assertArrayEquals(new String[0], invocation.arguments());
@ -89,7 +89,7 @@ public class SimpleCommandTests extends CommandTestSuite {
@Test @Test
void testExecuteAfterUnregisterForwards() { void testExecuteAfterUnregisterForwards() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, (SimpleCommand) invocation -> fail()); manager.register(meta, (SimpleCommand) invocation -> fail());
manager.unregister("hello"); manager.unregister("hello");
@ -100,7 +100,7 @@ public class SimpleCommandTests extends CommandTestSuite {
void testForwardsAndDoesNotExecuteImpermissibleAlias() { void testForwardsAndDoesNotExecuteImpermissibleAlias() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -125,7 +125,7 @@ public class SimpleCommandTests extends CommandTestSuite {
void testExecutesWithArguments() { void testExecutesWithArguments() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, (SimpleCommand) invocation -> { manager.register(meta, (SimpleCommand) invocation -> {
assertEquals("hello", invocation.alias()); assertEquals("hello", invocation.alias());
assertArrayEquals(new String[] { "dear", "world" }, invocation.arguments()); assertArrayEquals(new String[] { "dear", "world" }, invocation.arguments());
@ -140,7 +140,7 @@ public class SimpleCommandTests extends CommandTestSuite {
void testHandlesAndDoesNotExecuteWithImpermissibleArgs() { void testHandlesAndDoesNotExecuteWithImpermissibleArgs() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("color").build(); final var meta = manager.createMetaBuilder("color").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -164,7 +164,7 @@ public class SimpleCommandTests extends CommandTestSuite {
@Test @Test
void testDoesNotSuggestAliasIfImpermissible() { void testDoesNotSuggestAliasIfImpermissible() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -187,7 +187,7 @@ public class SimpleCommandTests extends CommandTestSuite {
@Test @Test
void testDoesNotSuggestAliasAfterUnregister() { void testDoesNotSuggestAliasAfterUnregister() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -206,7 +206,7 @@ public class SimpleCommandTests extends CommandTestSuite {
@Test @Test
void testSuggestsArgumentsAfterAlias() { void testSuggestsArgumentsAfterAlias() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -226,7 +226,7 @@ public class SimpleCommandTests extends CommandTestSuite {
@Test @Test
void testSuggestsArgumentsAfterAliasIgnoresAliasCase() { void testSuggestsArgumentsAfterAliasIgnoresAliasCase() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -245,7 +245,7 @@ public class SimpleCommandTests extends CommandTestSuite {
@Test @Test
void testSuggestsArgumentsAfterPartialArguments() { void testSuggestsArgumentsAfterPartialArguments() {
final var meta = manager.metaBuilder("numbers").build(); final var meta = manager.createMetaBuilder("numbers").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -266,7 +266,7 @@ public class SimpleCommandTests extends CommandTestSuite {
void testDoesNotSuggestFirstArgumentIfImpermissibleAlias() { void testDoesNotSuggestFirstArgumentIfImpermissibleAlias() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -295,7 +295,7 @@ public class SimpleCommandTests extends CommandTestSuite {
void testDoesNotSuggestArgumentsAfterPartialImpermissibleArguments() { void testDoesNotSuggestArgumentsAfterPartialImpermissibleArguments() {
final var callCount = new AtomicInteger(); final var callCount = new AtomicInteger();
final var meta = manager.metaBuilder("foo").build(); final var meta = manager.createMetaBuilder("foo").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -322,7 +322,7 @@ public class SimpleCommandTests extends CommandTestSuite {
@Test @Test
void testDoesNotSuggestIfFutureCompletesExceptionally() { void testDoesNotSuggestIfFutureCompletesExceptionally() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -340,7 +340,7 @@ public class SimpleCommandTests extends CommandTestSuite {
@Test @Test
void testDoesNotSuggestIfSuggestAsyncThrows() { void testDoesNotSuggestIfSuggestAsyncThrows() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -359,7 +359,7 @@ public class SimpleCommandTests extends CommandTestSuite {
@Test @Test
void testSuggestCompletesExceptionallyIfHasPermissionThrows() { void testSuggestCompletesExceptionallyIfHasPermissionThrows() {
final var meta = manager.metaBuilder("hello").build(); final var meta = manager.createMetaBuilder("hello").build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {
@ -390,7 +390,7 @@ public class SimpleCommandTests extends CommandTestSuite {
final var hint = LiteralArgumentBuilder final var hint = LiteralArgumentBuilder
.<CommandSource>literal("hint") .<CommandSource>literal("hint")
.build(); .build();
final var meta = manager.metaBuilder("hello") final var meta = manager.createMetaBuilder("hello")
.hint(hint) .hint(hint)
.build(); .build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@ -413,7 +413,7 @@ public class SimpleCommandTests extends CommandTestSuite {
final var hint = LiteralArgumentBuilder final var hint = LiteralArgumentBuilder
.<CommandSource>literal("hint") .<CommandSource>literal("hint")
.build(); .build();
final var meta = manager.metaBuilder("hello") final var meta = manager.createMetaBuilder("hello")
.hint(hint) .hint(hint)
.build(); .build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@ -437,7 +437,7 @@ public class SimpleCommandTests extends CommandTestSuite {
.<CommandSource, String>argument("hint", word()) .<CommandSource, String>argument("hint", word())
.suggests((context, builder) -> CompletableFuture.failedFuture(new RuntimeException())) .suggests((context, builder) -> CompletableFuture.failedFuture(new RuntimeException()))
.build(); .build();
final var meta = manager.metaBuilder("hello") final var meta = manager.createMetaBuilder("hello")
.hint(hint) .hint(hint)
.build(); .build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {
@ -463,7 +463,7 @@ public class SimpleCommandTests extends CommandTestSuite {
throw new RuntimeException(); throw new RuntimeException();
}) })
.build(); .build();
final var meta = manager.metaBuilder("hello") final var meta = manager.createMetaBuilder("hello")
.hint(hint) .hint(hint)
.build(); .build();
manager.register(meta, new SimpleCommand() { manager.register(meta, new SimpleCommand() {

Datei anzeigen

@ -244,7 +244,9 @@ public class SuggestionsProviderTests extends CommandTestSuite {
static final NoSuggestionsCommand INSTANCE = new NoSuggestionsCommand(); static final NoSuggestionsCommand INSTANCE = new NoSuggestionsCommand();
private NoSuggestionsCommand() {} private NoSuggestionsCommand() {
}
@Override @Override
public void execute(final Invocation invocation) { public void execute(final Invocation invocation) {

Datei anzeigen

@ -21,6 +21,7 @@ import static com.velocitypowered.proxy.command.brigadier.VelocityArgumentBuilde
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -67,6 +68,7 @@ public class VelocityArgumentCommandNodeTests {
assertTrue(this.contextBuilder.getArguments().containsKey("foo")); assertTrue(this.contextBuilder.getArguments().containsKey("foo"));
final ParsedArgument<Object, String[]> parsed = final ParsedArgument<Object, String[]> parsed =
(ParsedArgument<Object, String[]>) this.contextBuilder.getArguments().get("foo"); (ParsedArgument<Object, String[]>) this.contextBuilder.getArguments().get("foo");
assertNotNull(parsed, "Argument foo is null!");
assertArrayEquals(new String[] { "hello", "world" }, parsed.getResult()); assertArrayEquals(new String[] { "hello", "world" }, parsed.getResult());
assertEquals(expectedRange, parsed.getRange()); assertEquals(expectedRange, parsed.getRange());
} }