Rename methods (#41)

This commit is contained in:
Josh Taylor 2020-10-09 12:30:08 +01:00 committed by GitHub
parent 8ebb248a47
commit fdb80b304c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 12 deletions

View file

@ -216,7 +216,7 @@ public final class AnnotationParser<C> {
} }
if (method.isAnnotationPresent(CommandPermission.class)) { if (method.isAnnotationPresent(CommandPermission.class)) {
builder = builder.withPermission(method.getAnnotation(CommandPermission.class).value()); builder = builder.permission(method.getAnnotation(CommandPermission.class).value());
} }
if (commandMethod.requiredSender() != Object.class) { if (commandMethod.requiredSender() != Object.class) {

View file

@ -29,7 +29,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* Equivalent to {@link cloud.commandframework.Command.Builder#withPermission(String)} * Equivalent to {@link cloud.commandframework.Command.Builder#permission(String)}
*/ */
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View file

@ -659,7 +659,7 @@ public class Command<C> {
* @param permission Command permission * @param permission Command permission
* @return New builder instance using the command permission * @return New builder instance using the command permission
*/ */
public @NonNull Builder<C> withPermission(final @NonNull CommandPermission permission) { public @NonNull Builder<C> permission(final @NonNull CommandPermission permission) {
return new Builder<>( return new Builder<>(
this.commandManager, this.commandManager,
this.commandMeta, this.commandMeta,
@ -677,7 +677,7 @@ public class Command<C> {
* @param permission Command permission * @param permission Command permission
* @return New builder instance using the command permission * @return New builder instance using the command permission
*/ */
public @NonNull Builder<C> withPermission(final @NonNull String permission) { public @NonNull Builder<C> permission(final @NonNull String permission) {
return new Builder<>( return new Builder<>(
this.commandManager, this.commandManager,
this.commandMeta, this.commandMeta,
@ -710,7 +710,7 @@ public class Command<C> {
builder = builder.argument(builtArgument, Description.of(command.getArgumentDescription(argument))); builder = builder.argument(builtArgument, Description.of(command.getArgumentDescription(argument)));
} }
if (this.commandPermission.toString().isEmpty()) { if (this.commandPermission.toString().isEmpty()) {
builder = builder.withPermission(command.getCommandPermission()); builder = builder.permission(command.getCommandPermission());
} }
return builder.handler(command.commandExecutionHandler); return builder.handler(command.commandExecutionHandler);
} }

View file

@ -132,6 +132,39 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
return StringArgument.<C>newBuilder(name).asOptionalWithDefault(defaultString).build(); return StringArgument.<C>newBuilder(name).asOptionalWithDefault(defaultString).build();
} }
/**
* Create a new required command argument with the 'single' parsing mode
*
* @param name Argument name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, String> single(final @NonNull String name) {
return of(name, StringMode.SINGLE);
}
/**
* Create a new required command argument with the 'greedy' parsing mode
*
* @param name Argument name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, String> greedy(final @NonNull String name) {
return of(name, StringMode.GREEDY);
}
/**
* Create a new required command argument with the 'quoted' parsing mode
*
* @param name Argument name
* @param <C> Command sender type
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, String> quoted(final @NonNull String name) {
return of(name, StringMode.QUOTED);
}
/** /**
* Get the string mode * Get the string mode
* *
@ -158,6 +191,12 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
super(String.class, name); super(String.class, name);
} }
/**
* Set the String mode
*
* @param stringMode String mode to parse with
* @return Builder instance
*/
private @NonNull Builder<C> withMode(final @NonNull StringMode stringMode) { private @NonNull Builder<C> withMode(final @NonNull StringMode stringMode) {
this.stringMode = stringMode; this.stringMode = stringMode;
return this; return this;

View file

@ -37,10 +37,10 @@ class CommandPermissionTest {
@BeforeAll @BeforeAll
static void setup() { static void setup() {
manager.command(manager.commandBuilder("test").literal("foo").withPermission("test.permission.one").build()); manager.command(manager.commandBuilder("test").literal("foo").permission("test.permission.one").build());
manager.command(manager.commandBuilder("test").literal("bar").withPermission("test.permission.two").build()); manager.command(manager.commandBuilder("test").literal("bar").permission("test.permission.two").build());
manager.command(manager.commandBuilder("test").literal("fizz").withPermission("test.permission.three").build()); manager.command(manager.commandBuilder("test").literal("fizz").permission("test.permission.three").build());
manager.command(manager.commandBuilder("test").literal("buzz").withPermission("test.permission.four").build()); manager.command(manager.commandBuilder("test").literal("buzz").permission("test.permission.four").build());
} }
@Test @Test

View file

@ -55,7 +55,7 @@ class CommandTreeTest {
manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty()) manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
.literal("one").build()) .literal("one").build())
.command(manager.commandBuilder("test", SimpleCommandMeta.empty()) .command(manager.commandBuilder("test", SimpleCommandMeta.empty())
.literal("two").withPermission("no").build()) .literal("two").permission("no").build())
.command(manager.commandBuilder("test", Collections.singleton("other"), .command(manager.commandBuilder("test", Collections.singleton("other"),
SimpleCommandMeta.empty() SimpleCommandMeta.empty()
) )
@ -79,11 +79,11 @@ class CommandTreeTest {
/* Build command for testing intermediary and final executors */ /* Build command for testing intermediary and final executors */
manager.command(manager.commandBuilder("command") manager.command(manager.commandBuilder("command")
.withPermission("command.inner") .permission("command.inner")
.literal("inner") .literal("inner")
.handler(c -> System.out.println("Using inner command"))); .handler(c -> System.out.println("Using inner command")));
manager.command(manager.commandBuilder("command") manager.command(manager.commandBuilder("command")
.withPermission("command.outer") .permission("command.outer")
.handler(c -> System.out.println("Using outer command"))); .handler(c -> System.out.println("Using outer command")));
/* Build command for testing compound types */ /* Build command for testing compound types */