Search in sources :

Example 1 with SpongeSubcommandParameterBuilder

use of org.spongepowered.common.command.parameter.subcommand.SpongeSubcommandParameterBuilder in project SpongeCommon by SpongePowered.

the class SpongeParameterizedCommandBuilder method build.

@Override
public Command.@NonNull Parameterized build() {
    if (this.subcommands.isEmpty()) {
        Preconditions.checkState(this.commandExecutor != null, "Either a subcommand or an executor must exist!");
    } else {
        Preconditions.checkState(!(!this.parameters.isEmpty() && this.commandExecutor == null), "An executor must exist if you set parameters!");
    }
    final Predicate<CommandCause> requirements = this.executionRequirements == null ? cause -> true : this.executionRequirements;
    final List<Parameter.Subcommand> subcommands = this.subcommands.entrySet().stream().map(x -> new SpongeSubcommandParameterBuilder().aliases(x.getValue()).subcommand(x.getKey()).build()).collect(Collectors.toList());
    // build the node.
    return new SpongeParameterizedCommand(subcommands, ImmutableList.copyOf(this.parameters), this.shortDescription, this.extendedDescription, requirements, this.commandExecutor, this.flags, this.isTerminal);
}
Also used : NonNull(org.checkerframework.checker.nullness.qual.NonNull) Command(org.spongepowered.api.command.Command) Predicate(java.util.function.Predicate) Flag(org.spongepowered.api.command.parameter.managed.Flag) Set(java.util.Set) HashMap(java.util.HashMap) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CommandCause(org.spongepowered.api.command.CommandCause) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Parameter(org.spongepowered.api.command.parameter.Parameter) Component(net.kyori.adventure.text.Component) Map(java.util.Map) CommandExecutor(org.spongepowered.api.command.CommandExecutor) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) SpongeSubcommandParameterBuilder(org.spongepowered.common.command.parameter.subcommand.SpongeSubcommandParameterBuilder) Nullable(org.checkerframework.checker.nullness.qual.Nullable) CommandCause(org.spongepowered.api.command.CommandCause) SpongeSubcommandParameterBuilder(org.spongepowered.common.command.parameter.subcommand.SpongeSubcommandParameterBuilder)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Component (net.kyori.adventure.text.Component)1 NonNull (org.checkerframework.checker.nullness.qual.NonNull)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 Command (org.spongepowered.api.command.Command)1 CommandCause (org.spongepowered.api.command.CommandCause)1 CommandExecutor (org.spongepowered.api.command.CommandExecutor)1 Parameter (org.spongepowered.api.command.parameter.Parameter)1 Flag (org.spongepowered.api.command.parameter.managed.Flag)1