Add "literal" helper method to command builder
This commit is contained in:
parent
fb1f609c7f
commit
8190c96d1c
4 changed files with 21 additions and 12 deletions
|
|
@ -253,6 +253,18 @@ public class Command<C, M extends CommandMeta> {
|
||||||
this.commandExecutionHandler, this.commandPermission);
|
this.commandExecutionHandler, this.commandPermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a required {@link StaticArgument} into the command chain
|
||||||
|
*
|
||||||
|
* @param main Main argument name
|
||||||
|
* @param aliases Argument aliases
|
||||||
|
* @return New builder instance with the modified command chain
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public Builder<C, M> literal(@Nonnull final String main, @Nonnull final String... aliases) {
|
||||||
|
return this.argument(StaticArgument.required(main, aliases));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new command argument to the command
|
* Add a new command argument to the command
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.StaticArgument;
|
|
||||||
import com.intellectualsites.commands.arguments.standard.EnumArgument;
|
import com.intellectualsites.commands.arguments.standard.EnumArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||||
|
|
@ -42,10 +41,10 @@ public class CommandSuggestionsTest {
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void setupManager() {
|
static void setupManager() {
|
||||||
manager = new TestCommandManager();
|
manager = new TestCommandManager();
|
||||||
manager.command(manager.commandBuilder("test").argument(StaticArgument.required("one")).build());
|
manager.command(manager.commandBuilder("test").literal("one").build());
|
||||||
manager.command(manager.commandBuilder("test").argument(StaticArgument.required("two")).build());
|
manager.command(manager.commandBuilder("test").literal("two").build());
|
||||||
manager.command(manager.commandBuilder("test")
|
manager.command(manager.commandBuilder("test")
|
||||||
.argument(StaticArgument.required("var"))
|
.literal("var")
|
||||||
.argument(StringArgument.<TestCommandSender>newBuilder("str")
|
.argument(StringArgument.<TestCommandSender>newBuilder("str")
|
||||||
.withSuggestionsProvider((c, s) -> Arrays.asList("one", "two"))
|
.withSuggestionsProvider((c, s) -> Arrays.asList("one", "two"))
|
||||||
.build())
|
.build())
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.StaticArgument;
|
|
||||||
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.NoPermissionException;
|
import com.intellectualsites.commands.exceptions.NoPermissionException;
|
||||||
|
|
@ -47,12 +46,12 @@ class CommandTreeTest {
|
||||||
static void newTree() {
|
static void newTree() {
|
||||||
manager = new TestCommandManager();
|
manager = new TestCommandManager();
|
||||||
manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
|
manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
|
||||||
.argument(StaticArgument.required("one")).build())
|
.literal("one").build())
|
||||||
.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
|
.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
|
||||||
.argument(StaticArgument.required("two")).withPermission("no").build())
|
.literal("two").withPermission("no").build())
|
||||||
.command(manager.commandBuilder("test", Collections.singleton("other"),
|
.command(manager.commandBuilder("test", Collections.singleton("other"),
|
||||||
SimpleCommandMeta.empty())
|
SimpleCommandMeta.empty())
|
||||||
.argument(StaticArgument.required("opt", "öpt"))
|
.literal("opt", "öpt")
|
||||||
.argument(IntegerArgument
|
.argument(IntegerArgument
|
||||||
.optional("num", EXPECTED_INPUT_NUMBER))
|
.optional("num", EXPECTED_INPUT_NUMBER))
|
||||||
.build())
|
.build())
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.StaticArgument;
|
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.standard.BooleanArgument;
|
import com.intellectualsites.commands.arguments.standard.BooleanArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.DoubleArgument;
|
import com.intellectualsites.commands.arguments.standard.DoubleArgument;
|
||||||
|
|
@ -87,7 +86,7 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
.orElse(GameMode.SURVIVAL)))
|
.orElse(GameMode.SURVIVAL)))
|
||||||
.build())
|
.build())
|
||||||
.command(mgr.commandBuilder("kenny")
|
.command(mgr.commandBuilder("kenny")
|
||||||
.argument(StaticArgument.required("sux"))
|
.literal("sux")
|
||||||
.argument(IntegerArgument
|
.argument(IntegerArgument
|
||||||
.<BukkitCommandSender>newBuilder("perc")
|
.<BukkitCommandSender>newBuilder("perc")
|
||||||
.withMin(PERC_MIN).withMax(PERC_MAX).build())
|
.withMin(PERC_MIN).withMax(PERC_MAX).build())
|
||||||
|
|
@ -99,11 +98,11 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
})
|
})
|
||||||
.build())
|
.build())
|
||||||
.command(mgr.commandBuilder("test")
|
.command(mgr.commandBuilder("test")
|
||||||
.argument(StaticArgument.required("one"))
|
.literal("one")
|
||||||
.handler(c -> c.getSender().sendMessage("One!"))
|
.handler(c -> c.getSender().sendMessage("One!"))
|
||||||
.build())
|
.build())
|
||||||
.command(mgr.commandBuilder("test")
|
.command(mgr.commandBuilder("test")
|
||||||
.argument(StaticArgument.required("two"))
|
.literal("two")
|
||||||
.handler(c -> c.getSender().sendMessage("Two!"))
|
.handler(c -> c.getSender().sendMessage("Two!"))
|
||||||
.build())
|
.build())
|
||||||
.command(mgr.commandBuilder("uuidtest")
|
.command(mgr.commandBuilder("uuidtest")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue