Reformat project
This commit is contained in:
parent
01d36aecd8
commit
237eda75ef
30 changed files with 130 additions and 87 deletions
2
.github/workflows/gradle.yml
vendored
2
.github/workflows/gradle.yml
vendored
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
name: Java CI with Maven
|
name: Java CI with Maven
|
||||||
|
|
||||||
on: [push, pull_request]
|
on: [ push, pull_request ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,8 @@ public final class AnnotationParser<C> {
|
||||||
final A inner = getAnnotationRecursively(
|
final A inner = getAnnotationRecursively(
|
||||||
AnnotationAccessor.of(annotation.annotationType()),
|
AnnotationAccessor.of(annotation.annotationType()),
|
||||||
clazz,
|
clazz,
|
||||||
checkedAnnotations);
|
checkedAnnotations
|
||||||
|
);
|
||||||
if (inner != null) {
|
if (inner != null) {
|
||||||
innerCandidate = inner;
|
innerCandidate = inner;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import java.lang.annotation.Target;
|
||||||
* {@link cloud.commandframework.annotations.CommandMethod}
|
* {@link cloud.commandframework.annotations.CommandMethod}
|
||||||
* <p>
|
* <p>
|
||||||
* This should only be used on {@code String[]}
|
* This should only be used on {@code String[]}
|
||||||
|
*
|
||||||
* @since 1.2.0
|
* @since 1.2.0
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
|
|
|
||||||
|
|
@ -97,26 +97,31 @@ class AnnotationParserTest {
|
||||||
final Method annotatedMethod = annotatedClass.getDeclaredMethod("annotatedMethod");
|
final Method annotatedMethod = annotatedClass.getDeclaredMethod("annotatedMethod");
|
||||||
|
|
||||||
System.out.println("Looking for @CommandDescription");
|
System.out.println("Looking for @CommandDescription");
|
||||||
final CommandDescription commandDescription = AnnotationParser.getMethodOrClassAnnotation(annotatedMethod,
|
final CommandDescription commandDescription = AnnotationParser.getMethodOrClassAnnotation(
|
||||||
CommandDescription.class);
|
annotatedMethod,
|
||||||
|
CommandDescription.class
|
||||||
|
);
|
||||||
Assertions.assertNotNull(commandDescription);
|
Assertions.assertNotNull(commandDescription);
|
||||||
Assertions.assertEquals("Hello World!", commandDescription.value());
|
Assertions.assertEquals("Hello World!", commandDescription.value());
|
||||||
|
|
||||||
System.out.println("Looking for @CommandPermission");
|
System.out.println("Looking for @CommandPermission");
|
||||||
final CommandPermission commandPermission = AnnotationParser.getMethodOrClassAnnotation(annotatedMethod,
|
final CommandPermission commandPermission = AnnotationParser.getMethodOrClassAnnotation(
|
||||||
CommandPermission.class);
|
annotatedMethod,
|
||||||
|
CommandPermission.class
|
||||||
|
);
|
||||||
Assertions.assertNotNull(commandPermission);
|
Assertions.assertNotNull(commandPermission);
|
||||||
Assertions.assertEquals("some.permission", commandPermission.value());
|
Assertions.assertEquals("some.permission", commandPermission.value());
|
||||||
|
|
||||||
System.out.println("Looking for @CommandMethod");
|
System.out.println("Looking for @CommandMethod");
|
||||||
final CommandMethod commandMethod = AnnotationParser.getMethodOrClassAnnotation(annotatedMethod,
|
final CommandMethod commandMethod = AnnotationParser.getMethodOrClassAnnotation(
|
||||||
CommandMethod.class);
|
annotatedMethod,
|
||||||
|
CommandMethod.class
|
||||||
|
);
|
||||||
Assertions.assertNotNull(commandMethod);
|
Assertions.assertNotNull(commandMethod);
|
||||||
Assertions.assertEquals("method", commandMethod.value());
|
Assertions.assertEquals("method", commandMethod.value());
|
||||||
|
|
||||||
System.out.println("Looking for @Regex");
|
System.out.println("Looking for @Regex");
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused") final Regex regex = AnnotationParser.getMethodOrClassAnnotation(annotatedMethod, Regex.class);
|
||||||
final Regex regex = AnnotationParser.getMethodOrClassAnnotation(annotatedMethod, Regex.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -162,6 +167,7 @@ class AnnotationParserTest {
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
private @interface AnnotatedAnnotation {
|
private @interface AnnotatedAnnotation {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -181,6 +187,7 @@ class AnnotationParserTest {
|
||||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
private @interface Bad1 {
|
private @interface Bad1 {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -188,6 +195,7 @@ class AnnotationParserTest {
|
||||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
private @interface Bad2 {
|
private @interface Bad2 {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -346,7 +346,8 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
inner = inputQueue.remove();
|
inner = inputQueue.remove();
|
||||||
if (inner.startsWith("\"") || inner.startsWith("'")) {
|
if (inner.startsWith("\"") || inner.startsWith("'")) {
|
||||||
return ArgumentParseResult.failure(new StringParseException(sj.toString(),
|
return ArgumentParseResult.failure(new StringParseException(sj.toString(),
|
||||||
StringMode.QUOTED, commandContext));
|
StringMode.QUOTED, commandContext
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,37 +41,52 @@ public class CommandRegistrationStateTest {
|
||||||
@Test
|
@Test
|
||||||
void testRegistrationChangesState() {
|
void testRegistrationChangesState() {
|
||||||
final TestCommandManager manager = new TestCommandManager();
|
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());
|
assertEquals(CommandManager.RegistrationState.REGISTERING, manager.getRegistrationState());
|
||||||
// And a second registration maintains it
|
// 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());
|
assertEquals(CommandManager.RegistrationState.REGISTERING, manager.getRegistrationState());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testChangingRegistrationHandlerFails() {
|
void testChangingRegistrationHandlerFails() {
|
||||||
final TestCommandManager manager = new TestCommandManager();
|
final TestCommandManager manager = new TestCommandManager();
|
||||||
manager.command(manager.commandBuilder("test").handler(ctx -> {}));
|
manager.command(manager.commandBuilder("test").handler(ctx -> {
|
||||||
assertThrows(IllegalStateException.class,
|
}));
|
||||||
() -> manager.setCommandRegistrationHandler(CommandRegistrationHandler.nullCommandRegistrationHandler()));
|
assertThrows(
|
||||||
|
IllegalStateException.class,
|
||||||
|
() -> manager.setCommandRegistrationHandler(CommandRegistrationHandler.nullCommandRegistrationHandler())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRegistrationFailsInAfterRegistrationState() {
|
void testRegistrationFailsInAfterRegistrationState() {
|
||||||
final TestCommandManager manager = new TestCommandManager();
|
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);
|
manager.transitionOrThrow(
|
||||||
assertThrows(IllegalStateException.class, () -> manager.command(manager.commandBuilder("test2").handler(ctx -> {})));
|
CommandManager.RegistrationState.REGISTERING,
|
||||||
|
CommandManager.RegistrationState.AFTER_REGISTRATION
|
||||||
|
);
|
||||||
|
assertThrows(IllegalStateException.class, () -> manager.command(manager.commandBuilder("test2").handler(ctx -> {
|
||||||
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAllowUnsafeRegistration() {
|
void testAllowUnsafeRegistration() {
|
||||||
final TestCommandManager manager = new TestCommandManager();
|
final TestCommandManager manager = new TestCommandManager();
|
||||||
manager.setSetting(CommandManager.ManagerSettings.ALLOW_UNSAFE_REGISTRATION, true);
|
manager.setSetting(CommandManager.ManagerSettings.ALLOW_UNSAFE_REGISTRATION, true);
|
||||||
manager.command(manager.commandBuilder("test").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 -> {}));
|
manager.transitionOrThrow(
|
||||||
|
CommandManager.RegistrationState.REGISTERING,
|
||||||
|
CommandManager.RegistrationState.AFTER_REGISTRATION
|
||||||
|
);
|
||||||
|
manager.command(manager.commandBuilder("unsafe").handler(ctx -> {
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -217,8 +217,10 @@ public class CommandSuggestionsTest {
|
||||||
Assertions.assertEquals(Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"), suggestions3);
|
Assertions.assertEquals(Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"), suggestions3);
|
||||||
final String input4 = "numbers -1";
|
final String input4 = "numbers -1";
|
||||||
final List<String> suggestions4 = manager.suggest(new TestCommandSender(), input4);
|
final List<String> suggestions4 = manager.suggest(new TestCommandSender(), input4);
|
||||||
Assertions.assertEquals(Arrays.asList("-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"),
|
Assertions.assertEquals(
|
||||||
suggestions4);
|
Arrays.asList("-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"),
|
||||||
|
suggestions4
|
||||||
|
);
|
||||||
final String input5 = "numberswithmin ";
|
final String input5 = "numberswithmin ";
|
||||||
final List<String> suggestions5 = manager.suggest(new TestCommandSender(), input5);
|
final List<String> suggestions5 = manager.suggest(new TestCommandSender(), input5);
|
||||||
Assertions.assertEquals(Arrays.asList("5", "6", "7", "8", "9"), suggestions5);
|
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);
|
Assertions.assertEquals(Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9"), suggestions3);
|
||||||
final String input4 = "numberswithfollowingargument -1";
|
final String input4 = "numberswithfollowingargument -1";
|
||||||
final List<String> suggestions4 = manager.suggest(new TestCommandSender(), input4);
|
final List<String> suggestions4 = manager.suggest(new TestCommandSender(), input4);
|
||||||
Assertions.assertEquals(Arrays.asList("-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"),
|
Assertions.assertEquals(
|
||||||
suggestions4);
|
Arrays.asList("-1", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18", "-19"),
|
||||||
|
suggestions4
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,10 @@ class StringArgumentTest {
|
||||||
Assertions.assertEquals("quoted \" string", storage[0]);
|
Assertions.assertEquals("quoted \" string", storage[0]);
|
||||||
Assertions.assertEquals("unquoted", storage[1]);
|
Assertions.assertEquals("unquoted", storage[1]);
|
||||||
clear();
|
clear();
|
||||||
Assertions.assertThrows(CompletionException.class, () -> manager.executeCommand(new TestCommandSender(),
|
Assertions.assertThrows(CompletionException.class, () -> manager.executeCommand(
|
||||||
"'quoted quoted unquoted").join());
|
new TestCommandSender(),
|
||||||
|
"'quoted quoted unquoted"
|
||||||
|
).join());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import java.util.LinkedList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bungee specific {@link Caption caption keys}
|
* Bungee specific {@link Caption caption keys}
|
||||||
|
*
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
public final class BungeeCaptionKeys {
|
public final class BungeeCaptionKeys {
|
||||||
|
|
|
||||||
|
|
@ -117,10 +117,12 @@ public class CloudburstCommandManager<C> extends CommandManager<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class CloudListener implements Listener {
|
static final class CloudListener implements Listener {
|
||||||
|
|
||||||
static final CloudListener INSTANCE = new CloudListener();
|
static final CloudListener INSTANCE = new CloudListener();
|
||||||
|
|
||||||
private CloudListener() {
|
private CloudListener() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,18 +71,23 @@ public final class CloudInjectionModule<C> extends AbstractModule {
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
final Type commandTreeType = Types.newParameterizedType(CommandTree.class, this.commandSenderType);
|
final Type commandTreeType = Types.newParameterizedType(CommandTree.class, this.commandSenderType);
|
||||||
final Type commandExecutionCoordinatorType = Types.newParameterizedType(CommandExecutionCoordinator.class,
|
final Type commandExecutionCoordinatorType = Types.newParameterizedType(
|
||||||
this.commandSenderType);
|
CommandExecutionCoordinator.class,
|
||||||
|
this.commandSenderType
|
||||||
|
);
|
||||||
final Type executorFunction = Types.newParameterizedType(Function.class, commandTreeType,
|
final Type executorFunction = Types.newParameterizedType(Function.class, commandTreeType,
|
||||||
commandExecutionCoordinatorType);
|
commandExecutionCoordinatorType
|
||||||
|
);
|
||||||
final Key executorFunctionKey = Key.get(executorFunction);
|
final Key executorFunctionKey = Key.get(executorFunction);
|
||||||
this.bind(executorFunctionKey).toInstance(this.commandExecutionCoordinator);
|
this.bind(executorFunctionKey).toInstance(this.commandExecutionCoordinator);
|
||||||
final Type commandSenderMapperFunction = Types.newParameterizedType(Function.class, CommandSource.class,
|
final Type commandSenderMapperFunction = Types.newParameterizedType(Function.class, CommandSource.class,
|
||||||
this.commandSenderType);
|
this.commandSenderType
|
||||||
|
);
|
||||||
final Key commandSenderMapperFunctionKey = Key.get(commandSenderMapperFunction);
|
final Key commandSenderMapperFunctionKey = Key.get(commandSenderMapperFunction);
|
||||||
this.bind(commandSenderMapperFunctionKey).toInstance(this.commandSenderMapper);
|
this.bind(commandSenderMapperFunctionKey).toInstance(this.commandSenderMapper);
|
||||||
final Type backwardsCommandSenderMapperFunction = Types.newParameterizedType(Function.class, this.commandSenderType,
|
final Type backwardsCommandSenderMapperFunction = Types.newParameterizedType(Function.class, this.commandSenderType,
|
||||||
CommandSource.class);
|
CommandSource.class
|
||||||
|
);
|
||||||
final Key backwardsCommandSenderMapperFunctionKey = Key.get(backwardsCommandSenderMapperFunction);
|
final Key backwardsCommandSenderMapperFunctionKey = Key.get(backwardsCommandSenderMapperFunction);
|
||||||
this.bind(backwardsCommandSenderMapperFunctionKey).toInstance(this.backwardsCommandSenderMapper);
|
this.bind(backwardsCommandSenderMapperFunctionKey).toInstance(this.backwardsCommandSenderMapper);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import java.util.LinkedList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Velocity specific {@link Caption caption keys}
|
* Velocity specific {@link Caption caption keys}
|
||||||
|
*
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
public final class VelocityCaptionKeys {
|
public final class VelocityCaptionKeys {
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ public class VelocityCommandManager<C> extends CommandManager<C> implements Brig
|
||||||
private final ProxyServer proxyServer;
|
private final ProxyServer proxyServer;
|
||||||
private final Function<CommandSource, C> commandSenderMapper;
|
private final Function<CommandSource, C> commandSenderMapper;
|
||||||
private final Function<C, CommandSource> backwardsCommandSenderMapper;
|
private final Function<C, CommandSource> backwardsCommandSenderMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command manager instance.
|
* Create a new command manager instance.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,8 @@ final class VelocityExecutor<C> implements Command<CommandSource> {
|
||||||
e.getCorrectSyntax(),
|
e.getCorrectSyntax(),
|
||||||
NamedTextColor.GRAY
|
NamedTextColor.GRAY
|
||||||
)
|
)
|
||||||
).build())
|
).build()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
} else if (throwable instanceof InvalidCommandSenderException) {
|
} else if (throwable instanceof InvalidCommandSenderException) {
|
||||||
this.manager.handleException(
|
this.manager.handleException(
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@ name: ExamplePlugin
|
||||||
version: 1.2.0-SNAPSHOT
|
version: 1.2.0-SNAPSHOT
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
main: cloud.commandframework.examples.bukkit.ExamplePlugin
|
main: cloud.commandframework.examples.bukkit.ExamplePlugin
|
||||||
depends: [Essentials]
|
depends: [ Essentials ]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue