Search in sources :

Example 6 with Warp

use of io.github.nucleuspowered.nucleus.api.nucleusdata.Warp in project Nucleus by NucleusPowered.

the class SetCategoryCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    String warpName = args.<Warp>getOne(warpKey).get().getName();
    if (args.hasAny("r")) {
        // Remove the category.
        if (handler.setWarpCategory(warpName, null)) {
            src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.removed", warpName));
            return CommandResult.success();
        }
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.noremove", warpName));
    }
    Optional<Tuple<String, Boolean>> categoryOp = args.getOne(categoryKey);
    if (!categoryOp.isPresent()) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.required"));
    }
    Tuple<String, Boolean> category = categoryOp.get();
    if (!args.hasAny("n") && !category.getSecond()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.requirenew", category.getFirst()).toBuilder().onClick(TextActions.runCommand("/warp setcategory -n " + warpName + " " + category.getFirst())).build());
        return CommandResult.empty();
    }
    // Add the category.
    if (handler.setWarpCategory(warpName, category.getFirst())) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.added", category.getFirst(), warpName));
        return CommandResult.success();
    }
    WarpCategory c = handler.getWarpCategoryOrDefault(category.getFirst());
    throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithTextFormat("command.warp.category.couldnotadd", c.getDisplayName(), Text.of(warpName)));
}
Also used : Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Tuple(org.spongepowered.api.util.Tuple) WarpCategory(io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory)

Example 7 with Warp

use of io.github.nucleuspowered.nucleus.api.nucleusdata.Warp in project Nucleus by NucleusPowered.

the class SetCostCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Warp warpData = args.<Warp>getOne(warpKey).get();
    double cost = args.<Double>getOne(costKey).get();
    if (cost < -1) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.costset.arg"));
        return CommandResult.empty();
    }
    if (cost == -1 && warpHandler.setWarpCost(warpData.getName(), -1)) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.costset.reset", warpData.getName(), String.valueOf(this.defaultCost)));
        return CommandResult.success();
    } else if (warpHandler.setWarpCost(warpData.getName(), cost)) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.costset.success", warpData.getName(), String.valueOf(cost)));
        return CommandResult.success();
    }
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.costset.failed", warpData.getName()));
    return CommandResult.empty();
}
Also used : Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp)

Example 8 with Warp

use of io.github.nucleuspowered.nucleus.api.nucleusdata.Warp 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

Warp (io.github.nucleuspowered.nucleus.api.nucleusdata.Warp)8 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)5 Text (org.spongepowered.api.text.Text)4 WarpCategory (io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory)3 PermissionRegistry (io.github.nucleuspowered.nucleus.internal.PermissionRegistry)3 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)3 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)3 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)3 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)3 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)3 WarpConfig (io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfig)3 WarpConfigAdapter (io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfigAdapter)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 CommandResult (org.spongepowered.api.command.CommandResult)3 CommandSource (org.spongepowered.api.command.CommandSource)3 CommandContext (org.spongepowered.api.command.args.CommandContext)3 CommandElement (org.spongepowered.api.command.args.CommandElement)3 GenericArguments (org.spongepowered.api.command.args.GenericArguments)3