3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +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);
private static final List<String> EXAMPLES = Arrays.asList("word", "some words");
private StringArrayArgumentType() {}
private StringArrayArgumentType() {
}
@Override
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 ArgumentType<T> type;
private SuggestionProvider<S> suggestionsProvider = null;
private @Nullable SuggestionProvider<S> suggestionsProvider = null;
private VelocityArgumentBuilder(final String name, final ArgumentType<T> type) {
this.name = name;

Datei anzeigen

@ -38,6 +38,7 @@ import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* 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 BiPredicate<CommandContextBuilder<S>, ImmutableStringReader> contextRequirement,
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,
redirect, modifier, forks, customSuggestions);
this.type = Preconditions.checkNotNull(type, "type");

Datei anzeigen

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

Datei anzeigen

@ -57,7 +57,7 @@ abstract class InvocableCommandRegistrar<T extends InvocableCommand<I>,
@Override
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 LiteralCommandNode<CommandSource> literal =

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -166,7 +166,9 @@ public class CommandManagerTests extends CommandTestSuite {
static final DummyCommand INSTANCE = new DummyCommand();
private DummyCommand() {}
private DummyCommand() {
}
@Override
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.VelocityEventManager;
import java.util.Arrays;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
abstract class CommandTestSuite {
private static VelocityEventManager eventManager;
private static @Nullable VelocityEventManager eventManager;
protected VelocityCommandManager manager;
protected final CommandSource source = MockCommandSource.INSTANCE;
@ -44,6 +45,9 @@ abstract class CommandTestSuite {
@AfterAll
static void afterAll() {
try {
if (eventManager == null) {
throw new AssertionError("Event manager must exist");
}
eventManager.shutdown();
eventManager = null;
} catch (final InterruptedException e) {
@ -53,6 +57,9 @@ abstract class CommandTestSuite {
@BeforeEach
void setUp() {
if (eventManager == null) {
throw new AssertionError("Event manager must exist");
}
this.manager = new VelocityCommandManager(eventManager);
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -244,7 +244,9 @@ public class SuggestionsProviderTests extends CommandTestSuite {
static final NoSuggestionsCommand INSTANCE = new NoSuggestionsCommand();
private NoSuggestionsCommand() {}
private NoSuggestionsCommand() {
}
@Override
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.assertEquals;
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.assertTrue;
@ -67,6 +68,7 @@ public class VelocityArgumentCommandNodeTests {
assertTrue(this.contextBuilder.getArguments().containsKey("foo"));
final ParsedArgument<Object, String[]> parsed =
(ParsedArgument<Object, String[]>) this.contextBuilder.getArguments().get("foo");
assertNotNull(parsed, "Argument foo is null!");
assertArrayEquals(new String[] { "hello", "world" }, parsed.getResult());
assertEquals(expectedRange, parsed.getRange());
}