Revxrsal / Lamp

A modern annotations-driven commands framework for Java and Kotlin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing Argument = Unknown Command?

airdropped opened this issue · comments

I have a command class (blockregen region) with a subcommand (create) and a parameter (regenType). When a player runs the command with the parameter, tabcompleteion and suggestions work just fine. However when they run the command with nothing in the argument, it is supposed to say "You must specify a value for..." but it does not. Instead it just says "Unknown command. Type /help...".
Oddly enough, this works fine in console... there it tells me that I need to specify a value, and then proceeds to tell me that I need to be a player.

commented

Please share your code as well as your code that registers commands. Also, for the ease of communication, I suggest asking in the Discord server and sharing everything there. Other members of the community may also be able to provide help.

I already asked on discord here. Here's the code.

        commandHandler = BukkitCommandHandler.create(this);
        commandHandler.enableAdventure();

        commandHandler.registerValueResolver(RegenType.class, arguments -> {
            final String value = arguments.pop();
            final RegenType regenType = RegenType.fromName(value);
            if (regenType == null) {
                throw new CommandErrorException("Type '" + value + "' is not valid.");
            }

            return regenType;
        });
        commandHandler.getAutoCompleter().registerParameterSuggestions(RegenType.class, ((args, sender, command) -> RegenType.toList()));

        commandHandler.register(new HelpCommand());
        commandHandler.register(new RegionCommand(this));

        commandHandler.registerBrigadier();
@Command("blockregen region")
public class RegionCommand {
    private static final MiniMessage MM = MiniMessage.miniMessage();
    private static final TextComponent PLAYER_REQUIRED = Component.text().color(NamedTextColor.RED)
            .append(Component.text("You must be a player to execute this command.")).build();
    private static final TextComponent SELECTION_REQUIRED = Component.text().color(NamedTextColor.RED)
            .append(Component.text("You must make a selection first.")).build();
    private final BlockRegen plugin;

    public RegionCommand(final BlockRegen plugin) {
        this.plugin = plugin;
    }

    @DefaultFor("blockregen region")
    public void onRegion(final BukkitCommandActor actor) {
        // TODO: Region help
    }

    @Subcommand("create")
    public void onRegionCreate(final BukkitCommandActor actor, final RegenType regenType) {
        final Player player = actor.requirePlayer();

        final com.sk89q.worldedit.entity.Player wePlayer = BukkitAdapter.adapt(player);
        final SessionManager sessionManager = WorldEdit.getInstance().getSessionManager();
        final LocalSession localSession = sessionManager.get(wePlayer);

        final Region region;
        final World selectionWorld = localSession.getSelectionWorld();

        try {
            if (selectionWorld == null) throw new IncompleteRegionException();
            region = localSession.getSelection(selectionWorld);
        } catch (final IncompleteRegionException e) {
            actor.reply(SELECTION_REQUIRED);
            return;
        }

        plugin.getRegionManager().addRegion(region.getBoundingBox(), regenType);
        actor.reply(MM.deserialize("<green>Region created."));
    }

    @Subcommand("list")
    public void onRegionList(final BukkitCommandActor actor, @Optional final RegenType regenType) {
        final TextComponent.Builder response = Component.text().append(Component.text("BlockRegen Region List\n"));

        final Set<Map.Entry<CuboidRegion, RegenType>> entries = plugin.getRegionManager().getRegions().entrySet();

        int count = 0;
        for (final Map.Entry<CuboidRegion, RegenType> region : entries) {
            if (regenType != null && !region.getValue().equals(regenType)) continue;
            final CuboidRegion cuboid  = region.getKey();

            response.append(Component.text(cuboid.getMinimumPoint().toString()));
            response.append(Component.text(" to "));
            response.append(Component.text(cuboid.getMaximumPoint().toString()));
            response.appendNewline();
            count++;
        }

        if (count < 1) {
            response.append(Component.text().color(NamedTextColor.RED).append(Component.text("None")).build());
        }

        actor.reply(response.build());
    }
}
commented

Fixed in c54fcfb. Thanks for the report!