Question Integer based arguments

  • After careful consideration and due to limited usage, we’ve made the decision to discontinue the PaperMC forums. Moving forward, we recommend using Hangar for plugin uploads, and for all other community discussions and support, please join us on Discord.

ringpolice

New member
Dec 9, 2024
2
0
1
Hello everyone, this is my first post on the papermc forums, and my second papermc plugin.

I am using LiteralArgumentBuilder to create a countdown command with an optional timer mode, how do I check if an argument is strictly an integer using the .then(Commands.literal("/argumenthere/") builder?

My code is as follows, I am utilizing a buddies framework shown below as popcorn.

Code:
@SuppressWarnings("UnstableApiUsage")
public class CountdownCommand implements dev.kokiriglade.popcorn.command.Command<LiteralArgumentBuilder<CommandSourceStack>, VindexCountdown> {
    VindexCountdown plugin = new VindexCountdown();
    Boolean utilized = false;
    @NotNull
    @Override
    public LiteralArgumentBuilder<CommandSourceStack> get(@NotNull final VindexCountdown plugin) {
        return Commands.literal("countdown")
                .requires(commandSourceStack -> (commandSourceStack.getSender().isOp() || commandSourceStack.getSender()
                        .hasPermission("vindex.countdown")) && commandSourceStack.getSender() instanceof Player)
                .executes(context -> {
                    final ConfigHandler config = plugin.getConfigManager();
                    final Player player = (Player) context.getSource().getSender();

                    MessageBuilder prefix = MessageBuilder.of(plugin, plugin.getConfigManager().getDocument().getString("lang.prefix"));
                    MessageBuilder usage = MessageBuilder.of(plugin, plugin.getConfigManager().getDocument().getString("lang.usage"));
                    MessageBuilder helper = MessageBuilder.of(plugin, plugin.getConfigManager().getDocument().getString("lang.helper"));

                    if(!utilized) {
                        plugin.formattedMessage(player, usage);
                        plugin.formattedMessage(player, helper);
                        utilized = true;
                    }else{
                        plugin.formattedMessage(player, "Countdown started!");
                        //10-second countdown
                        utilized = false;
                    }

                    return Command.SINGLE_SUCCESS;
                })
                .then(Commands.literal("reload")
                .executes(context -> {
                    final ConfigHandler config = plugin.getConfigManager();
                    MessageBuilder reload = MessageBuilder.of(plugin, config.getDocument().getString("lang.reload"));


                    plugin.formattedMessage((Player) context.getSource().getSender(), reload);
                    plugin.getConfigManager().reload();

                    return Command.SINGLE_SUCCESS;
                }))
                .then(Commands.literal("integer argument here?")
                .executes(context -> {

                    //  custom countdown timer

                    return Command.SINGLE_SUCCESS;
                }));
    }

}

Thank you much! If you see anything there I can improve on or change, please let me know, I am very open to cleaning this code up!
 
Version Output
This server is running Paper version 1.21.1-132-ver/1.21.1@b48403b (2024-11-21T10:14:27Z) (Implementing API version 1.21.1-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.1-85-c5a1066 (MC: 1.21.1)