Search in sources :

Example 1 with Kit

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

the class KitEditCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    final Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
    if (KIT_HANDLER.isOpen(kitInfo.getName())) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.edit.current", kitInfo.getName()));
    }
    Inventory inventory = Util.getKitInventoryBuilder().property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.edit.title", kitInfo.getName()))).build(plugin);
    kitInfo.getStacks().stream().filter(x -> !x.getType().equals(ItemTypes.NONE)).forEach(x -> inventory.offer(x.createStack()));
    Optional<Container> openedInventory = src.openInventory(inventory);
    if (openedInventory.isPresent()) {
        KIT_HANDLER.addKitInventoryToListener(Tuple.of(kitInfo, inventory), openedInventory.get());
        return CommandResult.success();
    }
    throw ReturnMessageException.fromKey("command.kit.edit.cantopen", kitInfo.getName());
}
Also used : Inventory(org.spongepowered.api.item.inventory.Inventory) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) ItemTypes(org.spongepowered.api.item.ItemTypes) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) Since(io.github.nucleuspowered.nucleus.internal.annotations.Since) KitFallbackBase(io.github.nucleuspowered.nucleus.modules.kit.commands.KitFallbackBase) GenericArguments(org.spongepowered.api.command.args.GenericArguments) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) CommandResult(org.spongepowered.api.command.CommandResult) KitHandler(io.github.nucleuspowered.nucleus.modules.kit.handlers.KitHandler) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Tuple(org.spongepowered.api.util.Tuple) InventoryTitle(org.spongepowered.api.item.inventory.property.InventoryTitle) CommandElement(org.spongepowered.api.command.args.CommandElement) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) Container(org.spongepowered.api.item.inventory.Container) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) KitArgument(io.github.nucleuspowered.nucleus.argumentparsers.KitArgument) Container(org.spongepowered.api.item.inventory.Container) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 2 with Kit

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

the class KitInfoCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Kit kit = args.<Kit>getOne(KIT_PARAMETER).get();
    MessageProvider mp = this.plugin.getMessageProvider();
    Util.getPaginationBuilder(src).title(mp.getTextMessageWithFormat("command.kit.info.title", kit.getName())).contents(addViewHover(mp, kit), addCommandHover(mp, kit), mp.getTextMessageWithFormat("command.kit.info.sep"), mp.getTextMessageWithFormat("command.kit.info.firstjoin", yesno(mp, kit.isFirstJoinKit())), mp.getTextMessageWithFormat("command.kit.info.cost", String.valueOf(kit.getCost())), mp.getTextMessageWithFormat("command.kit.info.cooldown", kit.getCooldown().map(x -> Util.getTimeStringFromSeconds(x.getSeconds())).orElse(mp.getMessageWithFormat("standard.none"))), mp.getTextMessageWithFormat("command.kit.info.onetime", yesno(mp, kit.isOneTime())), mp.getTextMessageWithFormat("command.kit.info.autoredeem", yesno(mp, kit.isAutoRedeem())), mp.getTextMessageWithFormat("command.kit.info.hidden", yesno(mp, kit.isHiddenFromList())), mp.getTextMessageWithFormat("command.kit.info.displayredeem", yesno(mp, kit.isAutoRedeem())), mp.getTextMessageWithFormat("command.kit.info.ignoresperm", yesno(mp, kit.ignoresPermission()))).sendTo(src);
    return CommandResult.success();
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)

Example 3 with Kit

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

the class KitRedeemMessageCommand 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.setDisplayMessageOnRedeem(b);
    KIT_HANDLER.saveKit(kitInfo);
    player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat(b ? "command.kit.displaymessage.on" : "command.kit.displaymessage.off", kitInfo.getName()));
    return CommandResult.success();
}
Also used : Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)

Example 4 with Kit

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

the class KitResetUsageCommand method executeCommand.

@Override
public CommandResult executeCommand(final CommandSource player, CommandContext args) throws Exception {
    Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
    User u = args.<User>getOne(user).get();
    KitUserDataModule inu = Nucleus.getNucleus().getUserDataManager().getUnchecked(u).get(KitUserDataModule.class);
    if (Util.getKeyIgnoreCase(inu.getKitLastUsedTime(), kitInfo.getName()).isPresent()) {
        // Remove the key.
        inu.removeKitLastUsedTime(kitInfo.getName().toLowerCase());
        player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.resetuser.success", u.getName(), kitInfo.getName()));
        return CommandResult.success();
    }
    throw ReturnMessageException.fromKey("command.kit.resetuser.empty", u.getName(), kitInfo.getName());
}
Also used : KitUserDataModule(io.github.nucleuspowered.nucleus.modules.kit.datamodules.KitUserDataModule) User(org.spongepowered.api.entity.living.player.User) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)

Example 5 with Kit

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

the class KitCostCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    Kit kit = args.<Kit>getOne(KIT_PARAMETER).get();
    double cost = args.<Double>getOne(costKey).get();
    if (cost < 0) {
        cost = 0;
    }
    kit.setCost(cost);
    KIT_HANDLER.saveKit(kit);
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.cost.success", kit.getName(), String.valueOf(cost)));
    return CommandResult.success();
}
Also used : Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)

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