Autocomplete on tab

I’m creating a shops plugin and I want to be able to have the items autocomplete-able when pressing tab. I know this is doable when using commands like "give ". Where you can complete online players as well as items. I could type in “dir” press tab, and it autocompletes to “minecraft:dirt”. This may have already been addressed at some point, but I haven’t been active in this forum since

This is what I have. The way that the SpongeAPI is very different to how I’ve been coding in my career. But I’m slowly getting used to it. This is what my command spec looks like

private static CommandSpec sell = CommandSpec.builder()
            .description(Text.of("Sell an item to a shop"))
            .arguments(
                    GenericArguments.catalogedElement(Text.of("item"), CatalogTypes.ITEM_TYPE),
                    GenericArguments.integer(Text.of("quantity"))
            )
            .executor(new SellCommand()).build();

I’m probably doing this all wrong anyway because it is pretty new to me. If I could get any feedback on this or answers to my question. That would be very appreciated.

If i remeber the default GenericArguments.catalogElement does not have tab completion. If you create your own CommandElement and enable the tab comletion in that CommandElement

I’m not trying to have anyone do this all for me. But do you know how I would go about doing that?

I’m sure I could figure it out on my own. But if anyone knows how to do that, I’d rather not spend hours on something that’s probably very simple.

I know you can create maps or lists for auto completion using “choices,” but I don’t want to have to enter in the 200+ possible items.

With Sponge.getRegistry() and something like getAllOf(ItemTypes.class) you can iterate over every item and associate it with it’s ID. Then you can use that for choices.

But yeah, it’s a pity tab completion isn’t supported.

1 Like

It should already work as long as you type minecraft: at the start.

1 Like

Oh, alright. It does work this way.

But I did notice that when using any built in commands you can just start with something like “dir” and it will auto fill to “minecraft:dirt”. Is there anyway I would be able to achieve this?

The way i suggested will do this.
The default GenericArgument only checks if the string typed starts with the id of the catalogue type.

What you need to do is create a commandExecutor that searchs for the id or name.

Here is a example of what you want (only for EntityType) that I made earlier.

2 Likes