Search in sources :

Example 71 with CommandSource

use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.

the class ListWarpCommand method createSub.

private void createSub(final CommandSource src, @Nullable final WarpCategory category, final Map<WarpCategory, List<Warp>> warpDataList) {
    final boolean econExists = plugin.getEconHelper().economyServiceExists();
    Text name = category == null ? Text.of(this.defaultName) : category.getDisplayName();
    List<Text> lt = warpDataList.get(category).stream().sorted(Comparator.comparing(Warp::getName)).map(s -> createWarp(s, s.getName(), econExists, defaultCost)).collect(Collectors.toList());
    Util.getPaginationBuilder(src).title(plugin.getMessageProvider().getTextMessageWithTextFormat("command.warps.list.category", name)).padding(Text.of(TextColors.GREEN, "-")).contents(lt).footer(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.list.back").toBuilder().onClick(TextActions.executeCallback(s -> createMain(s, warpDataList))).build()).sendTo(src);
}
Also used : RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) GenericArguments(org.spongepowered.api.command.args.GenericArguments) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) WarpHandler(io.github.nucleuspowered.nucleus.modules.warp.handlers.WarpHandler) WarpCategory(io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory) WarpConfigAdapter(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfigAdapter) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Location(org.spongepowered.api.world.Location) CommandSource(org.spongepowered.api.command.CommandSource) TextStyles(org.spongepowered.api.text.format.TextStyles) WarpConfig(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfig) Set(java.util.Set) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) Objects(java.util.Objects) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Comparator(java.util.Comparator) Text(org.spongepowered.api.text.Text)

Example 72 with CommandSource

use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.

the class WarpCommand method preProcessChecks.

@Override
protected ContinueMode preProcessChecks(final CommandSource source, CommandContext args) {
    if (args.<Player>getOne(playerKey).map(x -> !(source instanceof Player) || x.getUniqueId().equals(((Player) source).getUniqueId())).orElse(false)) {
        // Bypass cooldowns
        args.putArg(NoModifiersArgument.NO_COOLDOWN_ARGUMENT, true);
        return ContinueMode.CONTINUE;
    }
    if (!plugin.getEconHelper().economyServiceExists() || permissions.testCostExempt(source) || args.hasAny("y")) {
        return ContinueMode.CONTINUE;
    }
    Warp wd = args.<Warp>getOne(warpNameArg).get();
    Optional<Double> i = wd.getCost();
    double cost = i.orElse(this.defaultCost);
    if (cost <= 0) {
        return ContinueMode.CONTINUE;
    }
    String costWithUnit = plugin.getEconHelper().getCurrencySymbol(cost);
    if (plugin.getEconHelper().hasBalance((Player) source, cost)) {
        String command = String.format("/warp -y %s", wd.getName());
        source.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.details", wd.getName(), costWithUnit));
        source.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.clickaccept").toBuilder().onClick(TextActions.runCommand(command)).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.clickhover", command))).append(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.alt")).build());
    } else {
        source.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.nomoney", wd.getName(), costWithUnit));
    }
    return ContinueMode.STOP;
}
Also used : RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) NoCost(io.github.nucleuspowered.nucleus.internal.annotations.command.NoCost) PermissionInformation(io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) HashMap(java.util.HashMap) GenericArguments(org.spongepowered.api.command.args.GenericArguments) Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) WarpArgument(io.github.nucleuspowered.nucleus.argumentparsers.WarpArgument) Lists(com.google.common.collect.Lists) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) AdditionalCompletionsArgument(io.github.nucleuspowered.nucleus.argumentparsers.AdditionalCompletionsArgument) RequiredArgumentsArgument(io.github.nucleuspowered.nucleus.argumentparsers.RequiredArgumentsArgument) SelectorWrapperArgument(io.github.nucleuspowered.nucleus.argumentparsers.SelectorWrapperArgument) WarpConfigAdapter(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfigAdapter) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) ContinueMode(io.github.nucleuspowered.nucleus.internal.command.ContinueMode) NucleusTeleportHandler(io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) CommandSource(org.spongepowered.api.command.CommandSource) WarpConfig(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfig) NicknameArgument(io.github.nucleuspowered.nucleus.argumentparsers.NicknameArgument) CauseStackHelper(io.github.nucleuspowered.nucleus.util.CauseStackHelper) Sponge(org.spongepowered.api.Sponge) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) NoModifiersArgument(io.github.nucleuspowered.nucleus.argumentparsers.NoModifiersArgument) UseWarpEvent(io.github.nucleuspowered.nucleus.modules.warp.event.UseWarpEvent) Optional(java.util.Optional) EssentialsEquivalent(io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent) Player(org.spongepowered.api.entity.living.player.Player) Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) Player(org.spongepowered.api.entity.living.player.Player)

Example 73 with CommandSource

use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.

the class IfConditionElseArgumentTests method process.

private boolean process(BiPredicate<CommandSource, CommandContext> cond) throws Exception {
    // Get the element
    CommandSource source = Mockito.mock(CommandSource.class);
    CommandArgs args = new CommandArgs("", Lists.newArrayList());
    CommandContext context = new CommandContext();
    new IfConditionElseArgument(new TrueArgument(), new FalseArgument(), cond).parse(source, args, context);
    return context.<Boolean>getOne("key").orElseThrow(NullPointerException::new);
}
Also used : CommandArgs(org.spongepowered.api.command.args.CommandArgs) CommandContext(org.spongepowered.api.command.args.CommandContext) IfConditionElseArgument(io.github.nucleuspowered.nucleus.argumentparsers.IfConditionElseArgument) CommandSource(org.spongepowered.api.command.CommandSource)

Example 74 with CommandSource

use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.

the class NicknameArgumentTests method mockSource.

private CommandSource mockSource() {
    CommandSource mock = Mockito.mock(CommandSource.class);
    Mockito.when(mock.hasPermission(Mockito.any())).thenReturn(true);
    return mock;
}
Also used : CommandSource(org.spongepowered.api.command.CommandSource)

Example 75 with CommandSource

use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.

the class NoCostArgumentTests method getNoCostArgument.

private CommandContext getNoCostArgument(CommandElement toWrap, CommandContext cc) throws ArgumentParseException {
    CommandSource s = Mockito.mock(Player.class);
    CommandArgs ca = new CommandArgs("", new ArrayList<>());
    NoModifiersArgument<?> nca = new NoModifiersArgument<>(toWrap, (c, o) -> true);
    nca.parse(s, ca, cc);
    return cc;
}
Also used : CommandArgs(org.spongepowered.api.command.args.CommandArgs) CommandSource(org.spongepowered.api.command.CommandSource) NoModifiersArgument(io.github.nucleuspowered.nucleus.argumentparsers.NoModifiersArgument)

Aggregations

CommandSource (org.spongepowered.api.command.CommandSource)91 Text (org.spongepowered.api.text.Text)60 CommandResult (org.spongepowered.api.command.CommandResult)48 List (java.util.List)47 CommandContext (org.spongepowered.api.command.args.CommandContext)45 Collectors (java.util.stream.Collectors)37 Sponge (org.spongepowered.api.Sponge)37 Player (org.spongepowered.api.entity.living.player.Player)36 Optional (java.util.Optional)35 TextColors (org.spongepowered.api.text.format.TextColors)30 CommandElement (org.spongepowered.api.command.args.CommandElement)27 TextActions (org.spongepowered.api.text.action.TextActions)27 NonnullByDefault (org.spongepowered.api.util.annotation.NonnullByDefault)25 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)24 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)23 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)23 GenericArguments (org.spongepowered.api.command.args.GenericArguments)23 Util (io.github.nucleuspowered.nucleus.Util)20 Nullable (javax.annotation.Nullable)20 Map (java.util.Map)19