From f6e6f02a84d1c084bdaa384349c9f620b5a80c6b Mon Sep 17 00:00:00 2001 From: Hugo Manrique Date: Thu, 10 Jun 2021 20:35:36 +0200 Subject: [PATCH] Fix checkstyle violations --- .../proxy/command/SuggestionsProvider.java | 3 --- .../proxy/command/VelocityCommandManager.java | 3 ++- .../command/brigadier/VelocityArgumentBuilder.java | 12 +++++++++++- .../brigadier/VelocityArgumentCommandNode.java | 2 +- .../proxy/command/CommandManagerTests.java | 2 +- .../brigadier/StringArrayArgumentTypeTests.java | 6 +++--- .../brigadier/VelocityArgumentCommandNodeTests.java | 6 +++++- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/SuggestionsProvider.java b/proxy/src/main/java/com/velocitypowered/proxy/command/SuggestionsProvider.java index a4faf9fd0..a2ca7588c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/SuggestionsProvider.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/SuggestionsProvider.java @@ -285,9 +285,6 @@ final class SuggestionsProvider { * Parses the hint nodes under the given node, which is either an alias node of * a {@link Command} or another hint node. * - * The caller must check the requirements - * are satisfied by a given source prior to calling this method. - * *

The reader and context are not mutated by this method. * * @param node the node to parse 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 d22115a48..3683c2cf2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -220,7 +220,8 @@ public class VelocityCommandManager implements CommandManager { final String normalizedInput = VelocityCommands.normalizeInput(cmdLine, false); try { return suggestionsProvider.provideSuggestions(normalizedInput, source) - .thenApply(suggestions -> Lists.transform(suggestions.getList(), Suggestion::getText)); + .thenApply(suggestions -> + Lists.transform(suggestions.getList(), Suggestion::getText)); } catch (final Throwable e) { // Again, plugins are naughty return CompletableFutures.exceptionallyCompletedFuture( diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentBuilder.java b/proxy/src/main/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentBuilder.java index d3f2506de..62e8c8b93 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentBuilder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentBuilder.java @@ -33,6 +33,16 @@ import org.checkerframework.checker.nullness.qual.Nullable; public final class VelocityArgumentBuilder extends ArgumentBuilder> { + /** + * Creates a builder for creating {@link VelocityArgumentCommandNode}s with + * the given name and type. + * + * @param name the name of the node + * @param type the type of the argument to parse + * @param the type of the command source + * @param the type of the argument to parse + * @return a builder + */ public static VelocityArgumentBuilder velocityArgument(final String name, final ArgumentType type) { Preconditions.checkNotNull(name, "name"); @@ -44,7 +54,7 @@ public final class VelocityArgumentBuilder private final ArgumentType type; private SuggestionProvider suggestionsProvider = null; - public VelocityArgumentBuilder(final String name, final ArgumentType type) { + private VelocityArgumentBuilder(final String name, final ArgumentType type) { this.name = name; this.type = type; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentCommandNode.java b/proxy/src/main/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentCommandNode.java index 262621931..d0bb4f6ec 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentCommandNode.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentCommandNode.java @@ -51,7 +51,7 @@ public class VelocityArgumentCommandNode extends ArgumentCommandNode type; - public VelocityArgumentCommandNode( + VelocityArgumentCommandNode( final String name, final ArgumentType type, final Command command, final Predicate requirement, final BiPredicate, ImmutableStringReader> contextRequirement, 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 c93392379..e977c12f0 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java @@ -85,7 +85,7 @@ public class CommandManagerTests extends CommandTestSuite { final var oldMeta = manager.metaBuilder("foo").build(); manager.register(oldMeta, DummyCommand.INSTANCE); // fails on execution final var newMeta = manager.metaBuilder("foo").build(); - manager.register("foo", (RawCommand) invocation -> called.set(true)); + manager.register(newMeta, (RawCommand) invocation -> called.set(true)); manager.executeAsync(MockCommandSource.INSTANCE, "foo").join(); assertTrue(called.get()); diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/brigadier/StringArrayArgumentTypeTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/brigadier/StringArrayArgumentTypeTests.java index d33d4a16b..80740ac2a 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/brigadier/StringArrayArgumentTypeTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/brigadier/StringArrayArgumentTypeTests.java @@ -93,10 +93,10 @@ public class StringArrayArgumentTypeTests { @Test void testMultipleWhitespaceCharsArePreserved() throws CommandSyntaxException { final StringReader reader = new StringReader( - " This is a message that shouldn't be normalized "); + " This is a message that shouldn't be normalized "); assertArrayEquals(new String[] { - "", "This", "", "is", "a", "", "", "message", "", "that", "shouldn't", "", "", "", "be", - "normalized", "", ""}, TYPE.parse(reader)); + "", "This", "", "is", "a", "", "", "message", "", "that", "shouldn't", "", "", "", "be", + "normalized", "", ""}, TYPE.parse(reader)); assertFalse(reader.canRead()); } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentCommandNodeTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentCommandNodeTests.java index b61d06531..1c1d6084b 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentCommandNodeTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/brigadier/VelocityArgumentCommandNodeTests.java @@ -18,7 +18,11 @@ package com.velocitypowered.proxy.command.brigadier; import static com.velocitypowered.proxy.command.brigadier.VelocityArgumentBuilder.velocityArgument; -import static org.junit.jupiter.api.Assertions.*; +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.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.StringReader;