Search in sources :

Example 6 with Kit

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

the class KitSetCooldownCommand method executeCommand.

@Override
public CommandResult executeCommand(final CommandSource player, CommandContext args) throws Exception {
    Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
    long seconds = args.<Long>getOne(duration).get();
    kitInfo.setCooldown(Duration.ofSeconds(seconds));
    KIT_HANDLER.saveKit(kitInfo);
    player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.setcooldown.success", kitInfo.getName(), Util.getTimeStringFromSeconds(seconds)));
    return CommandResult.success();
}
Also used : Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)

Example 7 with Kit

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

the class KitSetFirstJoinCommand 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).orElse(false);
    // This Kit is a reference back to the version in list, so we don't need
    // to update it explicitly
    kitInfo.setFirstJoinKit(b);
    KIT_HANDLER.saveKit(kitInfo);
    player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat(b ? "command.kit.setfirstjoin.on" : "command.kit.setfirstjoin.off", kitInfo.getName()));
    return CommandResult.success();
}
Also used : Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)

Example 8 with Kit

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

the class KitClearCommandCommand method executeCommand.

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

Example 9 with Kit

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

the class KitCommandCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // List all commands on a kit.
    Kit kit = args.<Kit>getOne(KIT_PARAMETER).get();
    List<String> commands = kit.getCommands();
    if (commands.isEmpty()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.command.nocommands", kit.getName()));
    } else {
        List<Text> cc = Lists.newArrayList();
        for (int i = 0; i < commands.size(); i++) {
            Text t = plugin.getMessageProvider().getTextMessageWithFormat("command.kit.command.commands.entry", String.valueOf(i + 1), commands.get(i));
            if (src.hasPermission(removePermission)) {
                t = Text.of(Text.builder().append(removeIcon).onClick(TextActions.runCommand("/nucleus:kit command remove " + kit.getName() + " " + commands.get(i))).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.command.removehover"))).build(), " ", t);
            }
            cc.add(t);
        }
        Util.getPaginationBuilder(src).title(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.command.commands.title", kit.getName())).contents(cc).sendTo(src);
    }
    return CommandResult.success();
}
Also used : Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit) Text(org.spongepowered.api.text.Text)

Example 10 with Kit

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

the class KitEditCommandCommand method executeCommand.

@Override
protected CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    final Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
    List<String> commands = kitInfo.getCommands();
    if (commands.size() > 9 * 6) {
        throw ReturnMessageException.fromKey("command.kit.command.edit.toomany", kitInfo.getName());
    }
    // Create an inventory with signed books.
    Random r = new Random();
    List<ItemStack> books = commands.stream().map(x -> {
        ItemStack stack = ItemStack.of(ItemTypes.WRITTEN_BOOK, 1);
        Text command = Text.of(x);
        stack.offer(Keys.DISPLAY_NAME, command);
        stack.offer(Keys.BOOK_PAGES, Lists.newArrayList(command));
        // So books don't stack.
        stack.offer(Keys.BOOK_AUTHOR, Text.of(kitInfo.getName(), "-", r.nextInt()));
        return stack;
    }).collect(Collectors.toList());
    // Create Inventory GUI.
    final InventoryTitle title = InventoryTitle.of(Text.of("Kit Commands: ", kitInfo.getName()));
    final Inventory inventory = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST).property(InventoryTitle.PROPERTY_NAME, title).build(plugin);
    books.forEach(inventory::offer);
    src.openInventory(inventory).ifPresent(x -> KIT_HANDLER.addKitCommandInventoryToListener(Tuple.of(kitInfo, inventory), x));
    return CommandResult.success();
}
Also used : Inventory(org.spongepowered.api.item.inventory.Inventory) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) Keys(org.spongepowered.api.data.key.Keys) ItemTypes(org.spongepowered.api.item.ItemTypes) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) Random(java.util.Random) KitFallbackBase(io.github.nucleuspowered.nucleus.modules.kit.commands.KitFallbackBase) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Lists(com.google.common.collect.Lists) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) InventoryArchetypes(org.spongepowered.api.item.inventory.InventoryArchetypes) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) CommandResult(org.spongepowered.api.command.CommandResult) 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) Collectors(java.util.stream.Collectors) List(java.util.List) Player(org.spongepowered.api.entity.living.player.Player) KitArgument(io.github.nucleuspowered.nucleus.argumentparsers.KitArgument) InventoryTitle(org.spongepowered.api.item.inventory.property.InventoryTitle) Random(java.util.Random) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit) Text(org.spongepowered.api.text.Text) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory)

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