Reformat project

This commit is contained in:
broccolai 2020-12-07 12:01:30 +00:00 committed by Alexander Söderberg
parent 01d36aecd8
commit 237eda75ef
30 changed files with 130 additions and 87 deletions

View file

@ -141,7 +141,8 @@ public final class AnnotationParser<C> {
final A inner = getAnnotationRecursively(
AnnotationAccessor.of(annotation.annotationType()),
clazz,
checkedAnnotations);
checkedAnnotations
);
if (inner != null) {
innerCandidate = inner;
}

View file

@ -33,6 +33,7 @@ import java.lang.annotation.Target;
* {@link cloud.commandframework.annotations.CommandMethod}
* <p>
* This should only be used on {@code String[]}
*
* @since 1.2.0
*/
@Target(ElementType.METHOD)

View file

@ -97,26 +97,31 @@ class AnnotationParserTest {
final Method annotatedMethod = annotatedClass.getDeclaredMethod("annotatedMethod");
System.out.println("Looking for @CommandDescription");
final CommandDescription commandDescription = AnnotationParser.getMethodOrClassAnnotation(annotatedMethod,
CommandDescription.class);
final CommandDescription commandDescription = AnnotationParser.getMethodOrClassAnnotation(
annotatedMethod,
CommandDescription.class
);
Assertions.assertNotNull(commandDescription);
Assertions.assertEquals("Hello World!", commandDescription.value());
System.out.println("Looking for @CommandPermission");
final CommandPermission commandPermission = AnnotationParser.getMethodOrClassAnnotation(annotatedMethod,
CommandPermission.class);
final CommandPermission commandPermission = AnnotationParser.getMethodOrClassAnnotation(
annotatedMethod,
CommandPermission.class
);
Assertions.assertNotNull(commandPermission);
Assertions.assertEquals("some.permission", commandPermission.value());
System.out.println("Looking for @CommandMethod");
final CommandMethod commandMethod = AnnotationParser.getMethodOrClassAnnotation(annotatedMethod,
CommandMethod.class);
final CommandMethod commandMethod = AnnotationParser.getMethodOrClassAnnotation(
annotatedMethod,
CommandMethod.class
);
Assertions.assertNotNull(commandMethod);
Assertions.assertEquals("method", commandMethod.value());
System.out.println("Looking for @Regex");
@SuppressWarnings("unused")
final Regex regex = AnnotationParser.getMethodOrClassAnnotation(annotatedMethod, Regex.class);
@SuppressWarnings("unused") final Regex regex = AnnotationParser.getMethodOrClassAnnotation(annotatedMethod, Regex.class);
}
@Test
@ -162,6 +167,7 @@ class AnnotationParserTest {
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
private @interface AnnotatedAnnotation {
}
@ -181,6 +187,7 @@ class AnnotationParserTest {
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
private @interface Bad1 {
}
@ -188,6 +195,7 @@ class AnnotationParserTest {
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
private @interface Bad2 {
}

View file

@ -346,7 +346,8 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
inner = inputQueue.remove();
if (inner.startsWith("\"") || inner.startsWith("'")) {
return ArgumentParseResult.failure(new StringParseException(sj.toString(),
StringMode.QUOTED, commandContext));
StringMode.QUOTED, commandContext
));
}
}

View file

@ -41,37 +41,52 @@ public class CommandRegistrationStateTest {
@Test
void testRegistrationChangesState() {
final TestCommandManager manager = new TestCommandManager();
manager.command(manager.commandBuilder("test").handler(ctx -> {}));
manager.command(manager.commandBuilder("test").handler(ctx -> {
}));
assertEquals(CommandManager.RegistrationState.REGISTERING, manager.getRegistrationState());
// And a second registration maintains it
manager.command(manager.commandBuilder("test2").handler(ctx -> {}));
manager.command(manager.commandBuilder("test2").handler(ctx -> {
}));
assertEquals(CommandManager.RegistrationState.REGISTERING, manager.getRegistrationState());
}
@Test
void testChangingRegistrationHandlerFails() {
final TestCommandManager manager = new TestCommandManager();
manager.command(manager.commandBuilder("test").handler(ctx -> {}));
assertThrows(IllegalStateException.class,
() -> manager.setCommandRegistrationHandler(CommandRegistrationHandler.nullCommandRegistrationHandler()));
manager.command(manager.commandBuilder("test").handler(ctx -> {
}));
assertThrows(
IllegalStateException.class,
() -> manager.setCommandRegistrationHandler(CommandRegistrationHandler.nullCommandRegistrationHandler())
);
}
@Test
void testRegistrationFailsInAfterRegistrationState() {
final TestCommandManager manager = new TestCommandManager();
manager.command(manager.commandBuilder("test").handler(ctx -> {}));
manager.command(manager.commandBuilder("test").handler(ctx -> {
}));
manager.transitionOrThrow(CommandManager.RegistrationState.REGISTERING, CommandManager.RegistrationState.AFTER_REGISTRATION);
assertThrows(IllegalStateException.class, () -> manager.command(manager.commandBuilder("test2").handler(ctx -> {})));
manager.transitionOrThrow(
CommandManager.RegistrationState.REGISTERING,
CommandManager.RegistrationState.AFTER_REGISTRATION
);
assertThrows(IllegalStateException.class, () -> manager.command(manager.commandBuilder("test2").handler(ctx -> {
})));
}
@Test
void testAllowUnsafeRegistration() {
final TestCommandManager manager = new TestCommandManager();
manager.setSetting(CommandManager.ManagerSettings.ALLOW_UNSAFE_REGISTRATION, true);
manager.command(manager.commandBuilder("test").handler(ctx -> {}));
manager.transitionOrThrow(CommandManager.RegistrationState.REGISTERING, CommandManager.RegistrationState.AFTER_REGISTRATION);
manager.command(manager.commandBuilder("unsafe").handler(ctx -> {}));
manager.command(manager.commandBuilder("test").handler(ctx -> {
}));
manager.transitionOrThrow(
CommandManager.RegistrationState.REGISTERING,
CommandManager.RegistrationState.AFTER_REGISTRATION
);
manager.command(manager.commandBuilder("unsafe").handler(ctx -> {
}));
}
}

View file

@ -217,8 +217,10 @@ public class CommandSuggestionsTest {
Assertions.assertEquals(Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"), suggestions3);
final String input4 = "numbers -1";
final List<String> suggestions4 = manager.suggest(new TestCommandSender(), input4);
Assertions.assertEquals(Arrays.asList("-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"),
suggestions4);
Assertions.assertEquals(
Arrays.asList("-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"),
suggestions4
);
final String input5 = "numberswithmin ";
final List<String> suggestions5 = manager.suggest(new TestCommandSender(), input5);
Assertions.assertEquals(Arrays.asList("5", "6", "7", "8", "9"), suggestions5);
@ -237,8 +239,10 @@ public class CommandSuggestionsTest {
Assertions.assertEquals(Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"), suggestions3);
final String input4 = "numberswithfollowingargument -1";
final List<String> suggestions4 = manager.suggest(new TestCommandSender(), input4);
Assertions.assertEquals(Arrays.asList("-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"),
suggestions4);
Assertions.assertEquals(
Arrays.asList("-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"),
suggestions4
);
}
@Test

View file

@ -92,8 +92,10 @@ class StringArgumentTest {
Assertions.assertEquals("quoted \" string", storage[0]);
Assertions.assertEquals("unquoted", storage[1]);
clear();
Assertions.assertThrows(CompletionException.class, () -> manager.executeCommand(new TestCommandSender(),
"'quoted quoted unquoted").join());
Assertions.assertThrows(CompletionException.class, () -> manager.executeCommand(
new TestCommandSender(),
"'quoted quoted unquoted"
).join());
}
@Test

View file

@ -32,6 +32,7 @@ import java.util.LinkedList;
/**
* Bungee specific {@link Caption caption keys}
*
* @since 1.1.0
*/
public final class BungeeCaptionKeys {

View file

@ -117,10 +117,12 @@ public class CloudburstCommandManager<C> extends CommandManager<C> {
}
static final class CloudListener implements Listener {
static final CloudListener INSTANCE = new CloudListener();
private CloudListener() {
}
}
}

View file

@ -71,18 +71,23 @@ public final class CloudInjectionModule<C> extends AbstractModule {
@SuppressWarnings({"unchecked", "rawtypes"})
protected void configure() {
final Type commandTreeType = Types.newParameterizedType(CommandTree.class, this.commandSenderType);
final Type commandExecutionCoordinatorType = Types.newParameterizedType(CommandExecutionCoordinator.class,
this.commandSenderType);
final Type commandExecutionCoordinatorType = Types.newParameterizedType(
CommandExecutionCoordinator.class,
this.commandSenderType
);
final Type executorFunction = Types.newParameterizedType(Function.class, commandTreeType,
commandExecutionCoordinatorType);
commandExecutionCoordinatorType
);
final Key executorFunctionKey = Key.get(executorFunction);
this.bind(executorFunctionKey).toInstance(this.commandExecutionCoordinator);
final Type commandSenderMapperFunction = Types.newParameterizedType(Function.class, CommandSource.class,
this.commandSenderType);
this.commandSenderType
);
final Key commandSenderMapperFunctionKey = Key.get(commandSenderMapperFunction);
this.bind(commandSenderMapperFunctionKey).toInstance(this.commandSenderMapper);
final Type backwardsCommandSenderMapperFunction = Types.newParameterizedType(Function.class, this.commandSenderType,
CommandSource.class);
CommandSource.class
);
final Key backwardsCommandSenderMapperFunctionKey = Key.get(backwardsCommandSenderMapperFunction);
this.bind(backwardsCommandSenderMapperFunctionKey).toInstance(this.backwardsCommandSenderMapper);
}

View file

@ -32,6 +32,7 @@ import java.util.LinkedList;
/**
* Velocity specific {@link Caption caption keys}
*
* @since 1.1.0
*/
public final class VelocityCaptionKeys {

View file

@ -72,6 +72,7 @@ public class VelocityCommandManager<C> extends CommandManager<C> implements Brig
private final ProxyServer proxyServer;
private final Function<CommandSource, C> commandSenderMapper;
private final Function<C, CommandSource> backwardsCommandSenderMapper;
/**
* Create a new command manager instance.
*

View file

@ -95,7 +95,8 @@ final class VelocityExecutor<C> implements Command<CommandSource> {
e.getCorrectSyntax(),
NamedTextColor.GRAY
)
).build())
).build()
)
);
} else if (throwable instanceof InvalidCommandSenderException) {
this.manager.handleException(