Search in sources :

Example 1 with CommandExecutor

use of org.spongepowered.api.command.CommandExecutor in project SpongeCommon by SpongePowered.

the class SpongePaginationService method createPaginationCommand.

public Command.Parameterized createPaginationCommand() {
    final Parameter.Value<ActivePagination> paginationIdParameter = Parameter.builder(ActivePagination.class).addParser(new ActivePaginationParameter()).key("pagination-id").build();
    final Command.Parameterized next = Command.builder().shortDescription(Component.text("Go to the next page")).executor((context) -> {
        context.requireOne(paginationIdParameter).nextPage();
        return CommandResult.success();
    }).build();
    final Command.Parameterized prev = Command.builder().shortDescription(Component.text("Go to the previous page")).executor((context) -> {
        context.requireOne(paginationIdParameter).previousPage();
        return CommandResult.success();
    }).build();
    final Parameter.Value<Integer> pageParameter = Parameter.integerNumber().key("page").build();
    final CommandExecutor pageExecutor = (context) -> {
        context.requireOne(paginationIdParameter).specificPage(context.requireOne(pageParameter));
        return CommandResult.success();
    };
    final Command.Parameterized page = Command.builder().shortDescription(Component.text("Go to a specific page")).addParameter(pageParameter).executor(pageExecutor).build();
    return Command.builder().addParameters(paginationIdParameter, Parameter.firstOf(pageParameter, Parameter.subcommand(next, "next", "n"), Parameter.subcommand(prev, "prev", "p", "previous"), Parameter.subcommand(page, "page"))).addChild(page, "page").shortDescription(Component.text("Helper command for paginations occurring")).executor(pageExecutor).build();
}
Also used : Command(org.spongepowered.api.command.Command) Cache(com.github.benmanes.caffeine.cache.Cache) ConcurrentMap(java.util.concurrent.ConcurrentMap) PaginationList(org.spongepowered.api.service.pagination.PaginationList) ValueCompleter(org.spongepowered.api.command.parameter.managed.ValueCompleter) Parameter(org.spongepowered.api.command.parameter.Parameter) Component(net.kyori.adventure.text.Component) Map(java.util.Map) CommandExecutor(org.spongepowered.api.command.CommandExecutor) Nameable(org.spongepowered.api.util.Nameable) Nullable(org.checkerframework.checker.nullness.qual.Nullable) CommandResult(org.spongepowered.api.command.CommandResult) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) SpongeCommandCompletion(org.spongepowered.common.command.SpongeCommandCompletion) CommandCompletion(org.spongepowered.api.command.CommandCompletion) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArgumentReader(org.spongepowered.api.command.parameter.ArgumentReader) Set(java.util.Set) UUID(java.util.UUID) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Audience(net.kyori.adventure.audience.Audience) ArgumentParseException(org.spongepowered.api.command.exception.ArgumentParseException) CommandContext(org.spongepowered.api.command.parameter.CommandContext) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) MapMaker(com.google.common.collect.MapMaker) Collections(java.util.Collections) Singleton(com.google.inject.Singleton) ValueParameter(org.spongepowered.api.command.parameter.managed.ValueParameter) Command(org.spongepowered.api.command.Command) CommandExecutor(org.spongepowered.api.command.CommandExecutor) Parameter(org.spongepowered.api.command.parameter.Parameter) ValueParameter(org.spongepowered.api.command.parameter.managed.ValueParameter)

Aggregations

Cache (com.github.benmanes.caffeine.cache.Cache)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 MapMaker (com.google.common.collect.MapMaker)1 Singleton (com.google.inject.Singleton)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Audience (net.kyori.adventure.audience.Audience)1 Component (net.kyori.adventure.text.Component)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 Command (org.spongepowered.api.command.Command)1 CommandCompletion (org.spongepowered.api.command.CommandCompletion)1 CommandExecutor (org.spongepowered.api.command.CommandExecutor)1