Question Integer based arguemnts

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!
 
Last edited: