Search in sources :

Example 1 with ContinueMode

use of io.github.nucleuspowered.nucleus.internal.command.ContinueMode 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)

Aggregations

Lists (com.google.common.collect.Lists)1 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)1 Warp (io.github.nucleuspowered.nucleus.api.nucleusdata.Warp)1 AdditionalCompletionsArgument (io.github.nucleuspowered.nucleus.argumentparsers.AdditionalCompletionsArgument)1 NicknameArgument (io.github.nucleuspowered.nucleus.argumentparsers.NicknameArgument)1 NoModifiersArgument (io.github.nucleuspowered.nucleus.argumentparsers.NoModifiersArgument)1 RequiredArgumentsArgument (io.github.nucleuspowered.nucleus.argumentparsers.RequiredArgumentsArgument)1 SelectorWrapperArgument (io.github.nucleuspowered.nucleus.argumentparsers.SelectorWrapperArgument)1 WarpArgument (io.github.nucleuspowered.nucleus.argumentparsers.WarpArgument)1 PermissionRegistry (io.github.nucleuspowered.nucleus.internal.PermissionRegistry)1 NoCost (io.github.nucleuspowered.nucleus.internal.annotations.command.NoCost)1 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)1 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)1 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)1 ContinueMode (io.github.nucleuspowered.nucleus.internal.command.ContinueMode)1 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)1 EssentialsEquivalent (io.github.nucleuspowered.nucleus.internal.docgen.annotations.EssentialsEquivalent)1 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)1 PermissionInformation (io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation)1 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)1