Search in sources :

Example 21 with Kit

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

the class KitAddCommandCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
    String c = args.<String>getOne(command).get().replace(" {player} ", " {{player}} ");
    kitInfo.addCommand(c);
    KIT_HANDLER.saveKit(kitInfo);
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.command.add.command", c, kitInfo.getName()));
    return CommandResult.success();
}
Also used : Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)

Example 22 with Kit

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

the class KitRemoveCommandCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
    List<String> commands = kitInfo.getCommands();
    String cmd;
    if (args.hasAny(index)) {
        int idx = args.<Integer>getOne(index).get();
        if (idx == 0) {
            throw ReturnMessageException.fromKey("command.kit.command.remove.onebased");
        }
        if (idx > commands.size()) {
            throw ReturnMessageException.fromKey("command.kit.command.remove.overidx", String.valueOf(commands.size()), kitInfo.getName());
        }
        cmd = commands.remove(idx - 1);
    } else {
        cmd = args.<String>getOne(command).get().replace(" {player} ", " {{player}} ");
        if (!commands.remove(cmd)) {
            throw ReturnMessageException.fromKey("command.kit.command.remove.noexist", cmd, kitInfo.getName());
        }
    }
    kitInfo.setCommands(commands);
    KIT_HANDLER.saveKit(kitInfo);
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.command.remove.success", cmd, kitInfo.getName()));
    return CommandResult.success();
}
Also used : Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)

Example 23 with Kit

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

the class KitAutoRedeemCommand method executeCommand.

@Override
public CommandResult executeCommand(final CommandSource player, CommandContext args) throws Exception {
    Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
    boolean b = args.<Boolean>getOne(toggle).get();
    // This Kit is a reference back to the version in list, so we don't need
    // to update it explicitly
    kitInfo.setAutoRedeem(b);
    KIT_HANDLER.saveKit(kitInfo);
    player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat(b ? "command.kit.autoredeem.on" : "command.kit.autoredeem.off", kitInfo.getName()));
    return CommandResult.success();
}
Also used : Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)

Example 24 with Kit

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

the class KitCommand method executeCommand.

@Override
public CommandResult executeCommand(Player player, CommandContext args) throws ReturnMessageException {
    Kit kit = args.<Kit>getOne(KIT_PARAMETER).get();
    EconHelper econHelper = Nucleus.getNucleus().getEconHelper();
    double cost = econHelper.economyServiceExists() ? kit.getCost() : 0;
    if (permissions.testCostExempt(player)) {
        // If exempt - no cost.
        cost = 0;
    }
    // If we have a cost for the kit, check we have funds.
    if (cost > 0 && !econHelper.hasBalance(player, cost)) {
        throw ReturnMessageException.fromKey("command.kit.notenough", kit.getName(), econHelper.getCurrencySymbol(cost));
    }
    try {
        NucleusKitService.RedeemResult redeemResult = KIT_HANDLER.redeemKit(kit, player, true, this.mustGetAll);
        if (!redeemResult.rejected().isEmpty()) {
            // If we drop them, tell the user
            if (this.isDrop) {
                player.sendMessage(this.plugin.getMessageProvider().getTextMessageWithFormat("command.kit.itemsdropped"));
                redeemResult.rejected().forEach(x -> Util.dropItemOnFloorAtLocation(x, player.getLocation()));
            } else {
                player.sendMessage(this.plugin.getMessageProvider().getTextMessageWithFormat("command.kit.fullinventory"));
            }
        }
        if (kit.isDisplayMessageOnRedeem()) {
            player.sendMessage(this.plugin.getMessageProvider().getTextMessageWithFormat("command.kit.spawned", kit.getName()));
        }
        // Charge, if necessary
        if (cost > 0 && econHelper.economyServiceExists()) {
            econHelper.withdrawFromPlayer(player, cost);
        }
        return CommandResult.success();
    } catch (KitRedeemException ex) {
        switch(ex.getReason()) {
            case ALREADY_REDEEMED:
                throw ReturnMessageException.fromKey("command.kit.onetime.alreadyredeemed", kit.getName());
            case COOLDOWN_NOT_EXPIRED:
                KitRedeemException.Cooldown kre = (KitRedeemException.Cooldown) ex;
                throw ReturnMessageException.fromKey("command.kit.cooldown", Util.getTimeStringFromSeconds(kre.getTimeLeft().getSeconds()), kit.getName());
            case PRE_EVENT_CANCELLED:
                KitRedeemException.PreCancelled krepe = (KitRedeemException.PreCancelled) ex;
                throw new ReturnMessageException(krepe.getCancelMessage().orElseGet(() -> (Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.kit.cancelledpre", kit.getName()))));
            case NO_SPACE:
                throw ReturnMessageException.fromKey("command.kit.fullinventorynosave", kit.getName());
            case UNKNOWN:
            default:
                throw ReturnMessageException.fromKey("command.kit.fail", kit.getName());
        }
    }
}
Also used : NucleusKitService(io.github.nucleuspowered.nucleus.api.service.NucleusKitService) NoCooldown(io.github.nucleuspowered.nucleus.internal.annotations.command.NoCooldown) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit) EconHelper(io.github.nucleuspowered.nucleus.internal.EconHelper) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) KitRedeemException(io.github.nucleuspowered.nucleus.api.exceptions.KitRedeemException)

Aggregations

Kit (io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)24 Text (org.spongepowered.api.text.Text)7 Player (org.spongepowered.api.entity.living.player.Player)6 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)5 NoModifiers (io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers)4 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)4 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)4 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)4 KitFallbackBase (io.github.nucleuspowered.nucleus.modules.kit.commands.KitFallbackBase)4 KitHandler (io.github.nucleuspowered.nucleus.modules.kit.handlers.KitHandler)4 CommandResult (org.spongepowered.api.command.CommandResult)4 CommandContext (org.spongepowered.api.command.args.CommandContext)4 ItemTypes (org.spongepowered.api.item.ItemTypes)4 NonnullByDefault (org.spongepowered.api.util.annotation.NonnullByDefault)4 Lists (com.google.common.collect.Lists)3 Util (io.github.nucleuspowered.nucleus.Util)3 KitRedeemException (io.github.nucleuspowered.nucleus.api.exceptions.KitRedeemException)3 KitArgument (io.github.nucleuspowered.nucleus.argumentparsers.KitArgument)3 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)3 KitConfigAdapter (io.github.nucleuspowered.nucleus.modules.kit.config.KitConfigAdapter)3